码迷,mamicode.com
首页 > 数据库 > 详细

基于apache和mysql,安装seafile - v1.0

时间:2014-06-14 08:31:55      阅读:485      评论:0      收藏:0      [点我收藏+]

标签:des   class   blog   code   http   tar   

seafile:下一代的开源云存储
更好的文件同步,隐私保护和团队协作功能!
本文基于官方文档,补充描述基于apache和mysql,安装seafile服务器。

原文网址:https://cloud.seafile.com/group/762/wiki/%E5%9C%A8apache%E7%8E%AF%E5%A2%83%E4%B8%8B%E9%83%A8%E7%BD%B2seafile/

修改:陈海青(http://hhrz.org)

1、准备

下载安装预装了apache和mysql的虚拟机(基于debain的 LAMP Stack -  Web Stack (MySQL) :
项目主页:http://www.turnkeylinux.org/lampstack
下载地址:http://downloads.sourceforge.net/project/turnkeylinux/ovf/turnkey-lamp-13.0-wheezy-amd64-ovf.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fturnkeylinux%2Ffiles%2Fovf%2F&ts=1400205666&use_mirror=skylink
 

2、下载和安装Seafile服务器

1)下载

     到seafile的下载页面(http://www.seafile.com/download)下载最新的服务器安装包.

2)部署和目录选择

 

假设安装目录 /usr/local/seafile,建议这样的目录结构:

mkdir -p /usr/local/seafile
#将 下载的服务器安装包seafile-server_* 移动到 haiwen 目录下后
mv seafile-server_* /usr/local/seafile
cd /usr/local/seafile
tar -xzf seafile-server_*
mkdir installed
mv seafile-server_* installed 

现在,你的目录看起来应该像这样:

#tree seafile -L 2
seafile
├── installed
│   └── seafile-server_1.8.2_x86-64.tar.gz
└── seafile-server-1.8.2
    ├── reset-admin.sh
    ├── runtime
    ├── seafile
    ├── seafile.sh
    ├── seahub
    ├── seahub.sh
    ├── setup-seafile.sh
    └── upgrade 

这样设计目录的好处在于

  • 和 seafile 相关的配置文件都可以放在 seafile 目录下,便于集中管理.
  • 后续升级时,你只需要解压最新的安装包到 seafile 目录下.

这样你可以重用 seafile 目录下已经存在的配置文件,而不用重新配置.

3)准备 MySQL 数据库

Seafile 服务器有三个组件需要拥有自己的数据库:

  • ccnet server
  • seafile server
  • seahub

Seafile 服务器组件更多信息请看Seafile服务器组件概览.

有两种方法可以初始化数据库:

  1. 通过setup-seafile-mysql.sh脚本创建数据库.
  2. 自己或其他人(比如数据库管理员)创建

我们建议采用第一种方法. 脚本会要求你提供 MySQL 数据库的的根密码,之后创建:

  • ccnet/seafile/seahub 数据库
  • 一个可以连接到这些数据库的用户

然而,有时你不得不使用第二种方法. 如果你没有根密码,你需要通过拥有这种权限的人(比如数据库管理员)来帮助你创建三个数据库,和一个能连接这三个数据库的用户. 例如,为 ccnet/seafile/seahub 分别创建如下三个数据库:ccnet-db / seafile-db / seahub-db, 和一个可以连接这三个数据库的 MySQL 用户seafile:

create database `ccnet-db` character set = ‘utf8‘;
create database `seafile-db` character set = ‘utf8‘;
create database `seahub-db` character set = ‘utf8‘;

create user ‘seafile‘@‘localhost‘ identified by ‘seafile‘;

GRANT ALL PRIVILEGES ON `ccnet-db`.* to `seafile`;
GRANT ALL PRIVILEGES ON `seafile-db`.* to `seafile`;
GRANT ALL PRIVILEGES ON `seahub-db`.* to `seafile`; 

4)安装 Seafile 服务器

(1)安装前的准备工作

安装 Seafile 服务器之前,请确认已安装以下软件

  • python 2.6 or 2.7
  • python-setuptools
  • python-simplejson
  • python-imaging
  • python-mysqldb
#在Debian/Ubuntu系统下
apt-get update
apt-get install python2.7 python-setuptools python-simplejson python-imaging python-mysqldb 

(2)开始设置数据库

cd seafile-server-*
./setup-seafile-mysql.sh  #运行安装脚本并回答预设问题 

如果你的系统中没有安装上面的某个软件,那么 Seafile初始化脚本会提醒你安装相应的软件包.

该脚本会依次询问你一些问题,从而一步步引导你配置 Seafile 的各项参数:

参数作用说明

seafile server name

seafile 服务器的名字,将来在客户端会显示为这个名字

3 ~ 15 个字符,可以用英文字母,数字,下划线

seafile server ip or domain

seafile 服务器的 IP 地址或者域名

客户端将通过这个 IP 或者地址来访问你的 Seafile 服务

ccnet server port

ccnet 使用的 TCP 端口

一般使用默认的10001 端口,如果已经被占用,可以设置为其他的端口

seafile data dir

seafile 数据存放的目录,用上面的例子,默认将是 /data/haiwen/seafile-data

seafile 数据将随着使用而逐渐增加,请把它放在一个有足够大空闲空间的分区上

seafile server port

seafile 服务器 使用的 TCP 端口

一般使用默认的 12001 端口,如果已经被占用,可以设置为其他的端口

seafile httpserver port

seafile httpserver 使用的 TCP 端口

一般使用默认的 8082 端口,如果已经被占用,可以设置为其他的端口

seahub admin email

sehaub管理员的登录帐户名

使用一个 email 地址

seahub admin password

seahub 管理员的密码

 

在这里, 你会被要求选择一种创建 Seafile 数据库的方式:

-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------

[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases 

具体选择哪项, 取决于你是否拥有根密码.

  • 如果选择1, 你需要提供根密码. 脚本程序会创建数据库和用户。
  • 如果选择2, ccnet/seafile/seahub 数据库应该已经被你(或者其他人)提前创建。

如果选择 [1] Create new ccnet/seafile/seahub databases,你会被问三个问题::

 

QuestionDescriptionNote

mysql server host

the host address of the mysql server

the default is localhost

mysql server port

the port of the mysql server

the default is 3306. Almost every mysql server uses this port.

root password

the password of mysql root account

the root password is required to create new databases and a new user

mysql user for seafile

the username for seafile programs to use to access MySQL server

if the user does not exist, it would be created

password for seafile mysql user

the password for the user above

 

ccnet dabase name

the name of the database used by ccnet, default is "ccnet-db"

the database would be created if not existing

seafile dabase name

the name of the database used by seafile, default is "seafile-db"

the database would be created if not existing

seahub dabase name

the name of the database used by seahub, default is "seahub-db"

the database would be created if not existing

如果你选择[2] Use existing ccnet/seafile/seahub databases, 你会被问到如下三个问题::

 

QuestionDescriptionNote

mysql server host

the host address of the mysql server

the default is localhost

mysql server port

the port of the mysql server

the default is 3306. Almost every mysql server uses this port

mysql user for seafile

the user for seafile programs to use to access MySQL server

the user must already exists

password for seafile mysql user

the password for the user above

 

ccnet dabase name

the name of the database used by ccnet

this database must already exist

seafile dabase name

the name of the database used by seafile, default is "seafile-db"

this database must already exist

seahub dabase name

the name of the database used by seahub, default is "seahub-db"

this database must already exist

如果安装正确完成,你会看到下面这样的输出

 

现在你的目录结构看起来应该是这样:

#tree seafile -L 2
seafile
├── ccnet               # configuration files
│   ├── ccnet.conf
│   ├── mykey.peer
│   ├── PeerMgr
│   └── seafile.ini
├── installed
│   └── seafile-server_1.8.2_x86-64.tar.gz
├── seafile-data
│   └── seafile.conf
├── seafile-server-1.8.2  # active version
│   ├── reset-admin.sh
│   ├── runtime
│   ├── seafile
│   ├── seafile.sh
│   ├── seahub
│   ├── seahub.sh
│   ├── setup-seafile.sh
│   └── upgrade
├── seafile-server-latest  # symbolic link to seafile-server-1.8.2
├── seahub-data
│   └── avatars
├── seahub_settings.py   # optional config file
└── seahub_settings.pyc 

seafile-server-latest文件夹为指向当前 Seafile 服务器文件夹的符号链接. 将来你升级到新版本后, 升级脚本会自动更新使其始终指向最新的 Seafile 服务器文件夹,建立方法:

#cd /usr/local/seafile

# ln  -s seafile-server-latest  symbolic link to seafile-server-1.8.2

5)启动 Seafile 服务器

(1)启动之前

因为 Seafile 在客户端和服务器之间使用持续连接,如果你的客户端数量巨大, 你应该在启动 Seafile 之前修改你的 Linux 文件最大打开数,如下:

ulimit -n 30000 

(2)启动 Seafile 服务器和 Seahub 网站

在 seafile-server-1.8.2 目录下,运行如下命令

  • 启动 Seafile:
./seafile.sh start # 启动 Seafile 服务 
  • 启动 Seahub
./seahub.sh start <port>  # 启动 Seahub 网站 (默认运行在8000端口上) 

小贴士: 你第一次启动 seahub 时,seahub.sh 脚本会提示你创建一个 seafile 管理员帐号。

服务启动后, 打开浏览器并输入以下地址

http://192.168.1.111:8000/ 

你会被重定向到登陆页面. 输入你在安装 Seafile 时提供的用户名和密码后,你会进入 Myhome 页面,新建资料库.

恭喜! 现在你已经成功的安装了 Seafile 服务器.

 

(3)在另一端口上运行 Seahub

如果你不想在默认的 8000 端口上运行 Seahub, 而是想自定义端口(比如8001)中运行,请按以下步骤操作:

  • 关闭 Seafile 服务器
./seahub.sh stop # 停止 Seafile 进程
./seafile.sh stop # 停止 Seahub 
  • 更改haiwen/ccnet/ccnet.conf文件中SERVICE_URL 的值(假设你的 ip 或者域名时192.168.1.100), 如下:
SERVICE_URL = http://192.168.1.100:8001 
  • 重启 Seafile 服务器
./seafile.sh start # 启动 Seafile 服务
./seahub.sh start 8001 # 启动 Seahub 网站 (运行在8001端口上) 

ccnet.conf更多细节请看[Seafile server configuration options](Seafile server configuration options "wikilink").

(4)关闭/重启 Seafile 和 Seahub

关闭

./seahub.sh stop # 停止 Seahub
./seafile.sh stop # 停止 Seafile 进程 

重启

./seafile.sh restart # 停止当前的 Seafile 进程,然后重启 Seafile
./seahub.sh restart  # 停止当前的 Seahub 进程,并在 8000 端口重新启动 Seahub 

如果停止/重启的脚本运行失败

大多数情况下 seafile.sh seahub.sh 脚本可以正常工作。如果遇到问题:

  • 使用pgrep命令检查 seafile/seahub 进程是否还在运行中
pgrep -f seafile-controller # 查看 Seafile 进程
pgrep -f "manage.py run_gunicorn" # 查看 Seahub 进程 
  • 使用pkill命令杀掉相关进程
pkill -f seafile-controller # 结束 Seafile 进程
pkill -f "manage.py run_gunicorn" # 结束 Seafile 进程 

 

 

3、在Apache环境下部署Seafile

1)准备工作

  1. Ubuntu 下安装python-flup库:

    sudo apt-get install python-flup
    
  2. Ubuntu 下安装和启用 mod_fastcgi 和 mod_rewrite :
    debain下需要调整才能下载(参考:https://packages.debian.org/zh-cn/wheezy/libapache2-mod-fastcgi):
    您可以使用以下列表中的任何一个源镜像只要往您的 /etc/apt/sources.list 文件中像下面这样添加一行:
    deb http://ftp.cn.debian.org/debian wheezy main non-free
    请使用最终确定的源镜像替换 ftp.cn.debian.org/debian。

    sudo apt-get install libApache2-mod-fastcgi
    sudo a2enmod rewrite
    sudo a2enmod fastcgi
  3. 启用 Apache proxy

    sudo a2enmod proxy_http
    

Windows 下, 首先下载mod_fastcgi-*.dll并将它放置在你的组件目录下. 在 debian/raspbian 环境下安装 fcgi 请参考这里

2)Apache 环境下部署 Seahub/HttpServer

Seahub 是 Seafile 服务器的网站界面. HttpServer 用来处理浏览器端文件的上传与下载. 默认情况下, 它在 8082 端口上监听 HTTP 请求.

这里我们通过 fastcgi 部署 Seahub, 通过反向代理(Reverse Proxy)部署 HttpServer. 我们假设你已经将 Seahub 绑定了域名"www.myseafile.com".

如果使用ip地址:则使用ip地址代替域名。

首先编辑你的 Apache 配置文件.根据你的 Linux 版本, 你需要在文件末尾增加以下语句:

Apache2.conf, for ubuntu/debian:

FastCGIExternalServer /var/www/seahub.fcgi -host 127.0.0.1:8000

httpd.conf, for centos/fedora:

FastCGIExternalServer /var/www/html/seahub.fcgi -host 127.0.0.1:8000

httpd.conf, for Windows:

LoadModule fastcgi_module modules/mod_fastcgi-2.4.6-AP22.dll
LoadModule rewrite_module modules/mod_rewrite.so
FastCGIExternalServer e:/seafile-server-1.7.1/seahub/seahub.fcgi -host 127.0.0.1:8000 

注意, seahub.fcgi只是一个位置标识符, 你并不需要在你的系统中新建这个文件夹.

二, 修改 Apache 配置文件: (sites-enabled/000-default) for ubuntu/debian (vhost.conf) for centos/fedora

<VirtualHost *:80>
  ServerName www.myseafile.com
  DocumentRoot /var/www
  Alias /media  /home/user/haiwen/seafile-server-latest/seahub/media         

  RewriteEngine On

  #
  # seafile httpserver
  #
  ProxyPass /seafhttp http://127.0.0.1:8082
  ProxyPassReverse /seafhttp http://127.0.0.1:8082
  RewriteRule ^/seafhttp - [QSA,L]

  #
  # seahub
  #
  RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ /seahub.fcgi$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</VirtualHost>

3)修改 ccnet.conf 和 seahub_setting.py

修改 ccnet.conf

你需要在/data/haiwen/ccnet/ccnet.confSERVICE_URL字段中自定义域名。

SERVICE_URL = http://www.myseafile.com

注意:如果你改变了 Seahub 的域名,也需要同步更改SERVICE_URL.

修改 seahub_settings.py

请在seahub_settings.py新增一行,设定HTTP_SERVER_ROOT的值

HTTP_SERVER_ROOT = ‘http://www.myseafile.com/seafhttp‘

启动 Seafile 和 Seahub

sudo service apache2 restart
./seafile.sh start
./seahub.sh start-fastcgi

4)升级 Seafile 服务器注意事项

升级Seafile时, 除了常规操作外,还需增加一步操作: ‘‘‘在 nginx/apache 配置中更新静态文件路径‘‘‘. 例如, 假设你正在将服务器从 1.3.0 升级到 1.4.0, 那么你需要:

 Alias /media  /home/user/haiwen/seafile-server-1.4.0/seahub/media

小贴士:

你可以创建一个符号链接seafile-server-latest, 并将它指向当前 Seafile 服务器文件夹(在2.1.0及其后续服务器版本中,e setup-seafile.sh脚本程序会自动创建). 之后, 每次你运行一个升级脚本, 脚本都会自动为seafile-server-latest创建符号链接并将其指向最新版本服务器的文件夹.

通过如下语句实现:

 location /media {
        root /home/user/haiwen/seafile-server-latest/seahub;
    }

这样,以后在你升级 Seafile 服务器的时候,不必每次都去更新 Nginx 配置.

5)其他说明

阅读Seafile服务器组件概览会帮你更好的理解 Seafile

查看seafile更多信息请移至..

在 Seafile 服务器端有两个组件:Seahub 和 HttpServer. HttpServer 通过监听 8082 端口处理文件的上传与下载. Seahub 通过监听 8000 端口负责其他的WEB页面. 但是在 https 下, Seahub 应该通过 fastcgi 模式监听8000端口 (运行./seahub.sh start-fastcgi). 而且在 fastcgi 模式下, 如果直接访问http://domain:8000时,会返回错误页面.

当一个用户访问https://domain.com/home/my/时, Apache 接受到访问请求后,通过 fastcgi 将其转发至 Seahub. 可通过以下配置来实现:

#
# seahub
#
RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(seahub.*)$ /seahub.fcgi/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

and

FastCGIExternalServer /var/www/seahub.fcgi -host 127.0.0.1:8000 

当一个用户在 Seahub 中点击文件下载链接时, Seahub 读取HTTP_SERVER_ROOT的值,并将其用户重定向到 https://domain.com/seafhttp/xxxxx/https://domain.com/seafhttpHTTP_SERVER_ROOT的值. 这里, HTTP_SERVER 表示是 Seafile 中只负责文件上传与下载的的 HttpServer 组件.

当 Apache 在 https://domain.com/seafhttp/xxxxx/接收到访问请求后, 它把请求发送到正在监听 127.0.0.1:8082 的 HttpServer 组件, 可通过以下配置来实现:

ProxyPass /seafhttp http://127.0.0.1:8082
ProxyPassReverse /seafhttp http://127.0.0.1:8082
RewriteRule ^/seafhttp - [QSA,L]

基于apache和mysql,安装seafile - v1.0,布布扣,bubuko.com

基于apache和mysql,安装seafile - v1.0

标签:des   class   blog   code   http   tar   

原文地址:http://www.cnblogs.com/hhrz/p/3787869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!