0%

CentOS+Apache+seafile+WindowsAD 安装记录

20140113 更新:
[1]. 忽略域中被禁止的用户。

安装环境

CentOS 5.10 x64
Apache 2.2.4 自编译
seafile 2.0.4 with MySQL
Windows AD

seafile安装目录 /home/seafile/

相关账号

mysql两套账号密码:

账号 密码 作用
root root super权限,用于数据库安装。
seafile seafile 仅对seafile的3个库有DML权限。

Windows AD账号:

账号 密码 备注
cloud cloud 具体设定见 # 域设置

域设置

确保域可用,为了安全性,在域控上增加一个账号,用户域账户登录查询用。

假定域账户设定:

属性
LIUDONGKAI.COM
账号 cloud
用户组 Users

并将cloud账号加入Domain Admins用户组里,仅此用户组即可。

seafile 2.0.4 + MySQL

参考资料:https://github.com/haiwen/seafile/wiki/Deploy-Seafile-with-MySQL

准备

  1. 确保mysql已安装并可用。
  2. 下载程序seafile server 2.0.4 x64至安装目录/home/seafile/下,并解压。http://seafile.googlecode.com/files/seafile-server_2.0.4_x86-64.tar.gz

步骤

安装seafile-server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ cd /home/seafile/
$ tar zxvf seafile-server_2.0.4_x86-64.tar.gz
$ ln -s seafile-server seafile-server-2.0.4
#创建软连方便今后的版本更新,无需再次调整apache


$ tree -L 2
.
|-- seafile-server -> seafile-server-2.0.4
|-- seafile-server-2.0.4
| |-- reset-admin.sh
| |-- runtime
| |-- seafile
| |-- seafile.sh
| |-- seahub
| |-- seahub.sh
| |-- setup-seafile-mysql.py
| |-- setup-seafile-mysql.sh
| |-- setup-seafile.sh
| `-- upgrade
`-- seafile-server_2.0.4_x86-64.tar.gz

./seafile-server/setup-seafile-mysql.sh
#按照提示一步步完成即可。安装之前会检查依赖库和工具是否存在及版本,缺啥补啥,能跑起来就好

./seafile-server/seafile.sh start
./seafile-server/seahub.sh start

完成以上步骤,依赖MySQL自建账号模式的seafile就可以通过访问设定的IP+端口的形式正常使用了。

添加域的部分查看 LDAP设置(整合Windows AD账号)
需要使用域名访问,请查看 Apache部分

其他设置

部分配置的变量可能在配置文件中不存在,此时会取默认配置,一旦填写后,在加载时会覆盖默认配置!

MySQL配置

如果需要调整MySQL配置需要修改2个config文件,分别是ccnet/ccnet.confseahub_settings.py,根据实际情况调整:

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

ccnet/ccnet.conf:

1
2
3
4
5
6
7
[Database]
ENGINE = mysql
PASSWD = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DB = ccnet-db
HOST = 127.0.0.1
USER = seafile
PORT = 3306

seahub_settings.py

1
2
3
4
5
6
7
8
9
10
11
12
13
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,如果没有,则在末尾添加即可:

1
2
3
4
5
6
7
EMAIL_USE_TLS = False
EMAIL_HOST = 'smtp.liudongkai.com' # smpt server
EMAIL_HOST_USER = 'seafile@liudongkai.com' # 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,这家伙的资料比较好找。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 站点名称,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

LDAP设置(整合Windows AD账号)

参考资料:https://github.com/haiwen/seafile/wiki/Configure-Seafile-to-use-LDAP

LDAP部分的设定非常的简单,只要对ccnet/ccnet.conf做相应修改即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[LDAP]
# LDAP URL for the host, ldap://, ldaps:// and ldapi:// are supported
# To use TLS, you should configure the LDAP server to listen on LDAPS
# port and specify ldaps:// here.
HOST = ldap://127.0.0.1
# 也可以写alias

# base DN from where all the users can be reached.
BASE = ou=组A,dc=liudongkai,dc=com;ou=组B,dc=liudongkai,dc=com
# 如果你在AD上设有多个组,那么都加上去吧,不然没写的组就无法登录了
# 如果还想禁用掉其中的一部分人,还可以使用过滤器FILTER


# user DN to bind to. If not set, will use anonymous login.
USER_DN = cn=cloud,cn=users,dc=liudongkai,dc=com
# 因为在 安装环境 -- 域设置 这段介绍里已经说明,cloud在用户组users里,
# 所以填写cn=users,如果是在自建的“组A”里,那么填写ou=组A

# Password for the user DN
PASSWORD = cloud

# The attribute to be used as user login id.
# By default it's the 'mail' attribute.
LOGIN_ATTR = mail
# mail 一个神奇的设置,他会校验自建DB里登记的邮箱,还会去找域里用户帐号下的电子邮箱项
# 从v2.0.4这个版本开始,登录数据源不再单一,已可以同时从DB和LDAP中取得。
# 除了mail外,针对Win AD 还有其他验证字段可取:
# sAMAccountName AD中的用户名,
# 此方式的缺点是会让 机构 -- 成员 列表里出现设备名,以$结尾,如:LIUDONGKAI-PC$
# userPrincipalName AD中的用户名,再和域名结合,组成邮箱形式登录,
# 如:liudongkai@liudongkai.com

 
更新:
增加过滤禁止用户:

1
FILTER = &(!(UserAccountControl:1.2.840.113556.1.4.803:=2))

参考资料:
http://msdn.microsoft.com/en-us/library/aa746475(VS.85).aspx
https://support.microsoft.com/kb/269181/zh-cn

Apache部分

参考资料:https://github.com/haiwen/seafile/wiki/Deploy-Seafile-with-apache

  1. 首先得确保apache已经安装并可用。
  2. 其次得确保apache proxy模块,和fastcgi模块 已安装并可用。 3. 安装FastCGI模块(mod_fastcgi)
     4.    安装编译相关的依赖包
     
    1
    # yum install httpd-devel apr apr-devel libtool
    5. 下载mod_fastcgi源代码
    1
    # wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
    6. 解压并进行编译安装
    1
    2
    3
    4
    # tar zxvf mod_fastcgi-2.4.6.tar.gz
    # cd mod_fastcgi-2.4.6
    # cp Makefile.AP2 Makefile
    # vim Makefile
    修改top_dir目录到你真实的apache安装目录后,进行编译安装
    1
    2
    # make
    # make install
    7. 加载模块
    1
    # vim /etc/httpd/conf/httpd.conf
    找到LoadModule部分,添加一行加载语句
    1
    2
    3
    ...
    LoadModule fastcgi_module modules/mod_fastcgi.so
    ...
    8. 重启apache
    1
    # /usr/local/apache/bin/apachectl restart
    1
    # /etc/init.d/httpd restart
9.    安装proxy模块(mod_proxy)
    10.    检查现有apache的版本
    
1
2
3
# /usr/local/apache/bin/httpd -v
Server version: Apache/2.2.4 (Unix)
Server built: Jul 27 2009 16:04:11
11. 下载对应的源码包并安装
1
2
3
4
5
6
7
8
9
# cd /tmp/
# wget http://archive.apache.org/dist/httpd/httpd-2.2.4.tar.gz
# tar zxvf httpd-2.2.4.tar.gz
# cd httpd-2.2.4
# ./configure --enable-mods-shared="proxy proxy_http proxy_connect"
# cd modules/proxy/
# /usr/local/apache/bin/apxs -i -a -o mod_proxy.so -c mod_proxy.c proxy_util.c
# /usr/local/apache/bin/apxs -i -a -o mod_proxy_http.so -c mod_proxy_http.c proxy_util.c
# /usr/local/apache/bin/apxs -i -a -o mod_proxy_connect.so -c mod_proxy_connect.c proxy_util.c
12. 重启apache
1
# /usr/local/apache/bin/apachectl restart
1
# /etc/init.d/httpd restart
  1. 修改Apache的vhost配置文件,并重启Apache
    我的路径是/usr/local/apache/conf/extra/httpd-vhosts.conf,请找你对应的配置文件
    在配置末尾添加上以下配置,并重启Apache:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    <VirtualHost *:80>
    ServerName cloud.liudongkai.com
    DocumentRoot /var/www
    Alias /media /home/seafile/seafile-server/seahub/media

    RewriteEngine On

    <Directory /var/www>
    Order allow,deny
    Allow from all
    </Directory>

    <Directory /home/seafile/seafile-server>
    Order allow,deny
    Allow from all
    </Directory>

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

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

    注意: 14. seahub.fcgi只是一个占位符,在你的系统里并不需要存在真实的文件。 15. Directory的Order和Allow配置也尽量添上,这样不会有错。
    如果在你的Apache根配置文件/usr/local/apache/conf/httpd.conf里发现下面的设置,
    目录禁止访问的全局配置,那么不加上这个目录权限配置会报403错误,web禁止访问。

    1
    2
    3
    4
    5
    6
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    </Directory>
  2. 修改 ccnet.conf 和 seahub_setting.py 17. 修改 /home/seafile/ccnet/ccnet.conf 里的 SERVICE_URL 变量值
    SERVICE_URL = http://cloud.liudongkai.com 18. 修改 /home/seafile/seahub_settings.py 里的 HTTP_SERVER_ROOT 变量值
    HTTP_SERVER_ROOT = 'http://cloud.liudongkai.com/seafhttp'

  3. 重启seafile和seahub

    1
    2
    /home/seafile/seafile-server/seafile.sh restart
    /home/seafile/seafile-server/seahub.sh restart-fastcgi

    注意:
    由于启用了apache代理,seahub必须以fastcgi的模式来启动,所以 ./seahub.sh start-fastcgi