CentOS 6下安装Apache +MySQL + Seafile

近年来类似 Dropbox 形式的同步型网盘 (云存储服务) 已经成为越来越多人生活和工作中都离不开的工具了。可惜 Dropbox 在国内多次遭屏蔽,而国产的百度云、金山快盘等产品也有人不太喜欢使用。如果你有动手能力,并且希望数据能掌握在自己手中,那么给自己或团队搭建私有的文件同步云存储平台是个不错的选择。Seafile 是一个免费开源且专业可靠的云存储平台软件,能让你自建一个类似 Dropbox 功能的私有云存储服务!可以实现文件同步、共享、跨平台访问、团队协作等功能……

Seafile 是由国内团队开发的一个国际化的开源云存储软件项目,目前据说已有10万左右的用户,典型的机构用户包括比利时的皇家自然科学博物馆、德国的 Wuppertal 气候、能源研究所等等。Seafile 同时提供了客户端和服务器端软件免费下载,任何个人或公司都能搭建属于自己的私有文件同步服务。

Seafile 的服务器端支持 Linux 、Windows 以及树莓派平台,客户端除了网页版之外,还支持 Mac、Linux、Windows 三个桌面平台以及 Android 和 iOS 两个移动平台。你可以利用局域网里的一台电脑作为服务器,搭建一个仅局域网内部能访问的专有云存储服务,也能将 Seafile 部署到互联网上的诸如阿里云、Linode 或任何 VPS、独立服务器上,实现一个私人的在线云存储服务。

官方详细的记录了在ubuntu的安装过程,但未详述CentOS的安装,CentOS上Apache需要自行编译mod_proxy和Mod_fastcgi模块。网络上的一些文章总是不很全面,有的没有记载编译安装mod_proxy,或者过程不全,有的没有记载安装Mod_fastcgi模块。我参考了一下网上一些相关文章,下面手记了一下CentOS+Apache+MySQL+Seafile的安装全过程。
安装MySQL数据库

yum install mysql-server

service mysqld start

mysqladmin -u root password 'XXXXXXXXXXXXXXXXXXX' //修改XXX为你想设定的Root密码

安装seafile-server

安装环境依赖包

yum install python2.7 python-setuptools python-simplejson python-imaging MySQL-python -y

假设安装目录为/home/seafile/

我们安装官方推荐的目录树格式安装Seafile,方便今后的版本更新,无需再次调整apache

[root@hxs ~]# cd /home/
[root@hxs home]# mkdir seafile
[root@hxs hxs]# mkdir installed
[root@hxs hxs]# cd /home/seafile/
[root@hxs seafile]# mv /root/seafile-server_4.1.2_x86-64.tar.gz /home/seafile
[root@hxs seafile]# tar -xzf seafile-server_4.1.2_x86-64.tar.gz
[root@hxs seafile]# mv seafile-server_4.1.2_x86-64.tar.gz installe
执行安装程序
[root@hxs seafile]# cd /home/seafile/seafile-server-4.1.2
[root@hxs seafile]# ./setup-seafile-mysql.sh #运行安装脚本并回答预设问题,#按照提示一步步完成即可。
具体可以参考:http://manual-cn.seafile.com/deploy/using_mysql.html

注意:
官方提示,mysql连接请不要使用localhost,应使用127.0.0.1,在测试的过程中,也的确有这个问题。

安装完成后会显示:

—————————————————————–
Your seafile server configuration has been finished successfully.
—————————————————————–

run seafile server: ./seafile.sh { start | stop | restart }
run seahub server: ./seahub.sh { start <port> | stop | restart <port> }

—————————————————————–
If you are behind a firewall, remember to allow input/output of these tcp ports:
—————————————————————–

port of ccnet server: 10001
port of seafile server: 12001
port of seafile fileserver: 8082
port of seahub: 8000

When problems occur, Refer to

https://github.com/haiwen/seafile/wiki

for information.

启动之前

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

[root@hxs seafile-server-4.1.2]# ulimit -n 30000

Seafile服务器的相关命令

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

关闭/重启 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 进程

启动Seafile服务器
[root@hxs seafile]# ./seafile.sh start
[root@hxs seafile]# ./seahub.sh start 8000

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

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

http://192.168.1.111:8000/

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

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

在另一端口上运行 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更多细节请看(server_configuration.md) .
其他设置
部分配置的变量可能在配置文件中不存在,此时会取默认配置,一旦填写后,在加载时会覆盖默认配置!

MySQL配置
如果需要调整MySQL配置需要修改2个config文件,分别是ccnet/ccnet.conf,seahub_settings.py,根据实际情况调整:
注意:
官方提示,mysql连接请不要使用localhost,应使用127.0.0.1,在测试的过程中,也的确有这个问题。
ccnet/ccnet.conf:
1
[Database]
ENGINE = mysql
PASSWD = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DB = ccnet-db
HOST = 127.0.0.1
USER = seafile
PORT = 3306
seahub_settings.py

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'seahub-db',
'USER': 'seafile',
'PASSWORD': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
}
}
}

邮件服务设置

修改seahub_settings.py,如果没有,则在末尾添加即可:

EMAIL_USE_TLS = False
EMAIL_HOST = 'smtp.liudongkai.com' # smpt server
EMAIL_HOST_USER = '[email protected]' # username
EMAIL_HOST_PASSWORD = 'hello!liudongkai' # password
EMAIL_PORT = '25'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER

个性化设置
如需要调整站点名称,logo URL等信息,修改seahub_settings.py:
Seafile的web部分是采用Django这个开源框架搭的,部分设置变量可以参考Django,这家伙的资料比较好找。

# 站点名称,url等配置
# 特别是在搭配Apache/nginx做代理后,一定不要忘记修改这里
SITE_TITLE = 'HiCloud'
SITE_BASE = 'http://cloud.liudongkai.com/'
LOGO_URL = 'http://cloud.liudongkai.com/'
SITE_NAME = 'HiCloud'

# 搭配Apache/nginx代理是必须启用,直接IP访问的话,就注释掉吧
HTTP_SERVER_ROOT = 'http://cloud.liudongkai.com/seafhttp'

# 注册功能开关,false=关闭
ENABLE_SIGNUP = False

# 两个管理员邮件通知开关
# 添加用户
SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER = True
# 改密码
SEND_EMAIL_ON_RESETTING_USER_PASSWD = True

# 机构显示开关,一旦改为ture,web页面里的“机构”按钮会被隐藏
CLOUD_MODE = False

# 3个Cookie相关的开关
# Cookie的生命周期,单位:s
SESSION_COOKIE_AGE = 60 * 60

# 是否在每次请求时都保存 Session 数据
# ture开启后,结合SESSION_COOKIE_AGE设置,那么按用户在web上最后一次操作开始计时,1小时后cookie过期,期间一旦有操作,计时器
会重新计时。
SESSION_SAVE_EVERY_REQUEST = True

# session持久化开关
# false,那么在cookie有效期内,用户重新开启浏览器将不必重新登录。
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
防火墙配置vi /etc/sysconfig/iptables

/etc/sysconfig/iptables增加几条内容开放80、8000、8082、10001、12001端口

参考iptable文件如下

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 8000 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 8082 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10001 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 12001 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
[root@hxs seafile-server-4.1.2]# iptables -V
iptables v1.4.7
[root@hxs seafile-server-4.1.2]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all — 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp — 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all — 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp — 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all — 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all — 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

[root@hxs seafile-server-4.1.2]# vi /etc/sysconfig/iptables
[root@hxs seafile-server-4.1.2]# /etc/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
安装Apache服务器
yum -y install httpd

安装FastCGI模块(mod_fastcgi)

安装编译相关的依赖包
yum install python-flup
yum -y install apr apr-devel httpd-devel libtool

下载mod_fastcgi源代码
cd temp
curl -O http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz

解压并进行编译安装
tar -xzvf mod_fastcgi-current.tar.gz
cd mod_fastcgi-2.4.6/
cp Makefile.AP2 Makefile

修改top_dir目录到你真实的apache安装目录后,进行编译安装
我们采用的默认安装,如下更改Makefile内文件top_dir
#top_dir = /usr/local/apache2
top_dir = /usr/lib64/httpd ##如32位机器应是/usr/lib/httpd
编译安装fastcgi,安装到/usr/lib64/httpd/modules/(32位机器/usr/lib/httpd/modules/)
make
make install
安装proxy模块(mod_proxy)

检查现有apache的版本

# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Jul 27 2014 0:0:0

下载对应的源码包并编译安装

# cd /tmp/
# wget http://archive.apache.org/dist/httpd/httpd-2.2.15.tar.gz
# tar zxvf httpd-2.2.15.tar.gz
# cd httpd-2.2.25
# ./configure –enable-mods-shared="proxy proxy_http proxy_connect"
# cd modules/proxy/
# /usr/sbin/apxs -i -a -o mod_proxy.so -c mod_proxy.c proxy_util.c
# /usr/sbin/apxs -i -a -o mod_proxy_http.so -c mod_proxy_http.c proxy_util.c
# /usr/sbin/apxs -i -a -o mod_proxy_connect.so -c mod_proxy_connect.c proxy_util.c
# /usr/sbin/apxs -i -a -o mod_proxy_balancer.so -c mod_proxy_balancer.c proxy_util.c
# /usr/sbin/apxs -i -a -o mod_proxy_ftp.so -c mod_proxy_ftp.c proxy_util.c
注:如果编译安装Apache,请修改/usr/sbin/apxs 为你的apache目录如:/usr/local/apache/bin/apxs

重启apache
# /usr/sbin/apachectl restart 或 # /etc/init.d/httpd restart
配置etc/httpd/conf/httd.conf

文件末尾添加FastCGIExternalServer
LoadModule fastcgi_module modules/mod_fastcgi.so

新增文件/etc/httpd/conf.d/vhost.conf,代码如下
<VirtualHost *:80>
ServerName pc.fd.fj.cn
DocumentRoot /var/www/html
Alias /media /home/seafile/seafile-server-latest/seahub/media

RewriteEngine On

#
# seafile fileserver
#
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>

##
FastCGIExternalServer /var/www/html/seahub.fcgi -host 127.0.0.1:8000
修改 ccnet.conf 和 seahub_setting.py

修改 ccnet.conf

你需要在 /home/seafile/ccnet/ccnet.conf 的 SERVICE_URL 字段中自定义域名。
SERVICE_URL = http://www.myseafile.com
注意:如果你改变了 Seahub 的域名,也需要同步更改 SERVICE_URL .

修改 seahub_settings.py

请在 seahub_settings.py 新增一行,设定 FILE_SERVER_ROOT 的值
FILE_SERVER_ROOT = 'http://www.myseafile.com/seafhttp'         //注意不可省略seafhttp,只能修改前面的域名部分
配置selinux

selinux在centos6下面默认是开启的。

setsebool -P httpd_can_network_connect 1 ##httpd可网络连接

chcon -R -h -u system_u -t httpd_sys_content_t /home/seafile/seafile-server-latest/seahub/media/ ##httpd可访问

chcon -R -h -u system_u -t httpd_sys_content_t /home/seafile/seahub-data/avatars/ ##httpd可访问

启动服务

seafile和seahub启动,httpd重启。

service httpd restart
/home/seafile/seafile-server-latest/seafile.sh restart
/home/seafile/seafile-server-latest/seahub.sh restart-fastcgi
遇到问题

httpd出错apr_sockaddr_info_get() failed

Starting httpd: httpd: apr_sockaddr_info_get() failed for seafile.linuxidc.com

在/etc/hosts添加seafile.linuxidc.com,机器名称。

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 seafile.linuxidc.com

FastCGI: apr_dir_open()失败

出错信息如下

[Wed Nov 20 10:51:13 2013] [error] (13)Permission denied: FastCGI: apr_dir_open() failed

[Wed Nov 20 10:51:13 2013] [notice] Digest: generating secret for digest authentication …

[Wed Nov 20 10:51:13 2013] [notice] Digest: done

[Wed Nov 20 10:51:13 2013] [error] (13)Permission denied: FastCGI: apr_dir_open() failed

[Wed Nov 20 10:51:13 2013] [notice] FastCGI: process manager initialized (pid 1823)

[Wed Nov 20 10:51:13 2013] [notice] Apache/2.2.15 (Unix) DAV/2 mod_fastcgi/2.4.6 configured — resuming normal operations

是selinux问题,执行如下命令chcon -R -t var_log_t /var/log/httpd/fastcgi/

CentOS 6下安装Apache +MySQL + Seafile》有3个想法

  1. Pingback引用通告: centos 6.6搭建seafile私有云盘 – 赵浮云的blog

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注