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

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)


一、准备


下载安装预装了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






二、下载和安装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,你会被问三个问题::

 
Question Description Note
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, 你会被问到如下三个问题::

 
Question Description Note
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   # 启动 Seahub 网站 (默认运行在8000端口上)

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

服务启动后, 打开浏览器并输入服务器地址(假设为192.168.1.111):

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 进程

 

三、在Apache环境下部署Seafile


1)准备工作



  1. Ubuntu 下安装python-flup库:
  2. sudo apt-get install python-flup
  3. 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。
  4. sudo apt-get install libApache2-mod-fastcgi
  5. sudo a2enmod rewrite

sudo a2enmod fastcgi

  1. 启用 Apache proxy
  2. 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



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}]


3)修改 ccnet.conf 和 seahub_setting.py


修改 ccnet.conf

你需要在/data/haiwen/ccnet/ccnet.conf的SERVICE_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更多信息请移至..

  • 在Nginx环境下部署Seafile / 在Apache环境下部署Seafile
  • Seafile Web在Nginx环境下启用Https / Seafile Web在Apache环境下启用Https
  • Seafile LDAP配置
  • 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/seafhttp时HTTP_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]

 

四、Start seafile server at system bootup


Table of Contents


    • For Ubuntu

      • Create a script /etc/init.d/seafile-server
      • Add Directory for Logfiles
      • Create a file /etc/init/seafile-server.conf

        • If you're not using MySQL
        • If you're using MySQL


      • Make the seafile-sever script executable
      • Done


    • For other Debian based Linux

      • Create a script /etc/init.d/seafile-server
      • Add Directory for Logfiles
      • Make the seafile-sever script executable
      • Add seafile-server to rc.d
      • Done


    • For RHEL/CentOS
    • For RHEL/CentOS run as service

      • Create a file /etc/sysconfig/seafile
      • Create a script /etc/init.d/seafile
      • Create a script /etc/init.d/seahub


    • For systems running systemd

      • Create systemd service file /etc/systemd/system/seafile.service
      • Create systemd service file /etc/systemd/system/seahub.service
      • Create systemd service file /etc/systemd/system/seafile-client.service (optional)
      • Done





For Ubuntu


On Ubuntu, we make use of the  /etc/init.d/ scripts to start seafile/seahub at system boot.

Create a script /etc/init.d/seafile-server


sudo vim /etc/init.d/seafile-server

The content of this script is: (You need to modify the value of  user and  seafile_dir accordingly)

#!/bin/bash

# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "seafile_dir" to your path of seafile installation

seafile_dir=/data/haiwen

script_path=${seafile_dir}/seafile-server-latest

seafile_init_log=${seafile_dir}/logs/seafile.init.log

seahub_init_log=${seafile_dir}/logs/seahub.init.log

 

# Change the value of fastcgi to true if fastcgi is to be used

fastcgi=false

# Set the port of fastcgi, default is 8000. Change it if you need different.

fastcgi_port=8000

 

case "$1" in

start)

sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}

fi

;;

restart)

sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}

fi

;;

stop)

sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}

sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}

;;

*)

echo "Usage: /etc/init.d/seafile {start|stop|restart}"

exit 1

;;

esac

Note: If you want to start seahub in fastcgi, just change the  fastcgi variable to  true

Add Directory for Logfiles


mkdir /path/to/seafile/dir/logs

Create a file /etc/init/seafile-server.conf


If you're not using MySQL

start on (runlevel [2345])

stop on (runlevel [016])

 

pre-start script

/etc/init.d/seafile-server start

end script

 

post-stop script

/etc/init.d/seafile-server stop

end script
If you're using MySQL

start on (started mysql

and runlevel [2345])

stop on (runlevel [016])

 

pre-start script

/etc/init.d/seafile-server start

end script

 

post-stop script

/etc/init.d/seafile-server stop

end script

Make the seafile-sever script executable


sudo chmod +x /etc/init.d/seafile-server

Done


Don't forget to update the value of  script_path later if you update your seafile server.

 

For other Debian based Linux


Create a script /etc/init.d/seafile-server


sudo vim /etc/init.d/seafile-server

The content of this script is: (You need to modify the value of  user and  script_path accordingly)

#!/bin/sh

 

### BEGIN INIT INFO

# Provides:          seafile-server

# Required-Start:    $local_fs $remote_fs $network

# Required-Stop:     $local_fs

# Default-Start:     2 3 4 5

# Default-Stop:      0 1 6

# Short-Description: Starts Seafile Server

# Description:       starts Seafile Server

### END INIT INFO

 

# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "script_path" to your path of seafile installation

seafile_dir=/data/haiwen

script_path=${seafile_dir}/seafile-server-latest

seafile_init_log=${seafile_dir}/logs/seafile.init.log

seahub_init_log=${seafile_dir}/logs/seahub.init.log

 

# Change the value of fastcgi to true if fastcgi is to be used

fastcgi=false

# Set the port of fastcgi, default is 8000. Change it if you need different.

fastcgi_port=8000

 

case "$1" in

start)

sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}

fi

;;

restart)

sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}

fi

;;

stop)

sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}

sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}

;;

*)

echo "Usage: /etc/init.d/seafile {start|stop|restart}"

exit 1

;;

esac

Note: If you want to start seahub in fastcgi, just change the  fastcgi variable to  true

Add Directory for Logfiles


mkdir /path/to/seafile/dir/logs

Make the seafile-sever script executable


sudo chmod +x /etc/init.d/seafile-server

Add seafile-server to rc.d


sudo update-rc.d seafile-server defaults

Done


Don't forget to update the value of  script_path later if you update your seafile server.

For RHEL/CentOS


On RHEL/CentOS, the script  /etc/rc.local is executed by the system at bootup, so we start seafile/seahub there.

  • Locate your python executable (python 2.6 or 2.7)

which python2.6 # or "which python2.7"

  • In /etc/rc.local, add the directory of python2.6(2.7) to PATH, and add the seafile/seahub start command

# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "script_path" to your path of seafile installation

seafile_dir=/data/haiwen

script_path=${seafile_dir}/seafile-server-latest

 

sudo -u ${user} ${script_path}/seafile.sh start > /tmp/seafile.init.log 2>&1

sudo -u ${user} ${script_path}/seahub.sh start > /tmp/seahub.init.log 2>&1

Note: If you want to start seahub in fastcgi, just change the  "seahub.sh start" in the last line above to  "seahub.sh start-fastcgi"

  • Done. Don't forget to update the value of script_path later if you update your seafile server.

For RHEL/CentOS run as service


On RHEL/CentOS , we make use of the /etc/init.d/ scripts to start seafile/seahub at system boot as service.

Create a file /etc/sysconfig/seafile


# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "script_path" to your path of seafile installation

seafile_dir=/home/haiwen

script_path=${seafile_dir}/seafile-server-latest

seafile_init_log=${seafile_dir}/logs/seafile.init.log

seahub_init_log=${seafile_dir}/logs/seahub.init.log

 

# Change the value of fastcgi to true if fastcgi is to be used

fastcgi=false

 

# Set the port of fastcgi, default is 8000. Change it if you need different.

fastcgi_port=8000

Create a script /etc/init.d/seafile


#!/bin/bash

#

# seafile

 

#

# chkconfig: - 68 32

# description: seafile

 

# Source function library.

. /etc/init.d/functions

 

# Source networking configuration.

. /etc/sysconfig/network

 

if [ -f /etc/sysconfig/seafile ];then

. /etc/sysconfig/seafile

else

echo "Config file /etc/sysconfig/seafile not found! Bye."

exit 200

fi

 

RETVAL=0

 

start() {

# Start daemons.

echo -n $"Starting seafile: "

ulimit -n 30000

su - ${user} -c"${script_path}/seafile.sh start >> ${seafile_init_log} 2>&1"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seafile

return $RETVAL

}

 

stop() {

echo -n $"Shutting down seafile: "

su - ${user} -c"${script_path}/seafile.sh stop >> ${seafile_init_log} 2>&1"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seafile

return $RETVAL

}

 

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

restart|reload)

stop

start

RETVAL=$?

;;

*)

echo $"Usage: $0 {start|stop|restart}"

RETVAL=3

esac

 

exit $RETVAL

Create a script /etc/init.d/seahub


#!/bin/bash

#

# seahub

 

#

# chkconfig: - 69 31

# description: seahub

 

# Source function library.

. /etc/init.d/functions

 

# Source networking configuration.

. /etc/sysconfig/network

 

if [ -f /etc/sysconfig/seafile ];then

. /etc/sysconfig/seafile

else

echo "Config file /etc/sysconfig/seafile not found! Bye."

exit 200

fi

 

RETVAL=0

 

start() {

# Start daemons.

echo -n $"Starting seahub: "

ulimit -n 30000

if [  $fastcgi = true ];

then

su - ${user} -c"${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} 2>&1"

else

su - ${user} -c"${script_path}/seahub.sh start >> ${seahub_init_log} 2>&1"

fi

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seahub

return $RETVAL

}

 

stop() {

echo -n $"Shutting down seafile: "

su - ${user} -c"${script_path}/seahub.sh stop >> ${seahub_init_log} 2>&1"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seahub

return $RETVAL

}

 

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

restart|reload)

stop

start

RETVAL=$?

;;

*)

echo $"Usage: $0 {start|stop|restart}"

RETVAL=3

esac

 

exit $RETVAL

Next, enable services:

chmod 550 /etc/init.d/seafile

chmod 550 /etc/init.d/seahub

chkconfig --add seafile

chkconfig --add seahub

chkconfig seahub on

chkconfig seafile on

and run:

service seafile start

service seahub start

For systems running systemd


Create systemd service files, change  ${seafile_dir} to your  seafile installation location and seafile to user, who runs  seafile (if appropriate). Then you need to reload systemd's daemons: systemctl daemon-reload.

Create systemd service file /etc/systemd/system/seafile.service


[Unit]

Description=Seafile

# add mysql.service or postgresql.service depending on your database to the line below

After=network.target

 

[Service]

Type=oneshot

ExecStart=${seafile_dir}/seafile-server-latest/seafile.sh start

ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop

RemainAfterExit=yes

User=seafile

Group=seafile

 

[Install]

WantedBy=multi-user.target

Create systemd service file /etc/systemd/system/seahub.service


[Unit]

Description=Seafile hub

After=network.target seafile.service

 

[Service]

# change start to start-fastcgi if you want to run fastcgi

ExecStart=${seafile_dir}/seafile-server-latest/seahub.sh start

ExecStop=${seafile_dir}/seafile-server-latest/seahub.sh stop

User=seafile

Group=seafile

Type=oneshot

RemainAfterExit=yes

 

[Install]

WantedBy=multi-user.target

Create systemd service file /etc/systemd/system/seafile-client.service (optional)


You need to create this service file only if you have  seafile console client and you want to run it on system boot.

[Unit]

Description=Seafile client

# Uncomment the next line you are running seafile client on the same computer as server

# After=seafile.service

# Or the next one in other case

# After=network.target

 

[Service]

Type=oneshot

ExecStart=/usr/bin/seaf-cli start

ExecStop=/usr/bin/seaf-cli stop

RemainAfterExit=yes

User=seafile

Group=seafile

 

[Install]

WantedBy=multi-user.target

 

Done

 

 

Start seafile server at system bootup


Table of Contents?                     For Ubuntu?                                       Create a script /etc/init.d/seafile-server

?                                       Add Directory for Logfiles

?                                       Create a file /etc/init/seafile-server.conf

?                                                         If you're not using MySQL

?                                                         If you're using MySQL

?                                       Make the seafile-sever script executable

?                                       Done

?                     For other Debian based Linux

?                                       Create a script /etc/init.d/seafile-server

?                                       Add Directory for Logfiles

?                                       Make the seafile-sever script executable

?                                       Add seafile-server to rc.d

?                                       Done

?                     For RHEL/CentOS

?                     For RHEL/CentOS run as service

?                                       Create a file /etc/sysconfig/seafile

?                                       Create a script /etc/init.d/seafile

?                                       Create a script /etc/init.d/seahub

?                     For systems running systemd

?                                       Create systemd service file /etc/systemd/system/seafile.service

?                                       Create systemd service file /etc/systemd/system/seahub.service

?                                       Create systemd service file /etc/systemd/system/seafile-client.service (optional)

?                                       Done

 

For Ubuntu

On Ubuntu, we make use of the /etc/init.d/ scripts to start seafile/seahub at system boot.

 

Create a script /etc/init.d/seafile-server

sudo vim /etc/init.d/seafile-server

The content of this script is: (You need to modify the value of user and seafile_dir accordingly)

#!/bin/bash

 

# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "seafile_dir" to your path of seafile installation

seafile_dir=/data/haiwen

script_path=${seafile_dir}/seafile-server-latest

seafile_init_log=${seafile_dir}/logs/seafile.init.log

seahub_init_log=${seafile_dir}/logs/seahub.init.log

 

# Change the value of fastcgi to true if fastcgi is to be used

fastcgi=false

# Set the port of fastcgi, default is 8000. Change it if you need different.

fastcgi_port=8000

 

case "$1" in

start)

sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}

fi

;;

restart)

sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}

fi

;;

stop)

sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}

sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}

;;

*)

echo "Usage: /etc/init.d/seafile {start|stop|restart}"

exit 1

;;

esac

Note: If you want to start seahub in fastcgi, just change the fastcgi variable to true

 

Add Directory for Logfiles

mkdir /path/to/seafile/dir/logs

 

Create a file /etc/init/seafile-server.conf

 

If you're not using MySQL

start on (runlevel [2345])

stop on (runlevel [016])

 

pre-start script

/etc/init.d/seafile-server start

end script

 

post-stop script

/etc/init.d/seafile-server stop

end script

 

If you're using MySQL

start on (started mysql

and runlevel [2345])

stop on (runlevel [016])

 

pre-start script

/etc/init.d/seafile-server start

end script

 

post-stop script

/etc/init.d/seafile-server stop

end script

 

Make the seafile-sever script executable

sudo chmod +x /etc/init.d/seafile-server

 

Done

Don't forget to update the value of script_path later if you update your seafile server.

 

For other Debian based Linux

 

Create a script /etc/init.d/seafile-server

sudo vim /etc/init.d/seafile-server

The content of this script is: (You need to modify the value of user and script_path accordingly)

#!/bin/sh

 

### BEGIN INIT INFO

# Provides:          seafile-server

# Required-Start:    $local_fs $remote_fs $network

# Required-Stop:     $local_fs

# Default-Start:     2 3 4 5

# Default-Stop:      0 1 6

# Short-Description: Starts Seafile Server

# Description:       starts Seafile Server

### END INIT INFO

 

# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "script_path" to your path of seafile installation

seafile_dir=/data/haiwen

script_path=${seafile_dir}/seafile-server-latest

seafile_init_log=${seafile_dir}/logs/seafile.init.log

seahub_init_log=${seafile_dir}/logs/seahub.init.log

 

# Change the value of fastcgi to true if fastcgi is to be used

fastcgi=false

# Set the port of fastcgi, default is 8000. Change it if you need different.

fastcgi_port=8000

 

case "$1" in

start)

sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}

fi

;;

restart)

sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}

if [  $fastcgi = true ];

then

sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}

else

sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}

fi

;;

stop)

sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}

sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}

;;

*)

echo "Usage: /etc/init.d/seafile {start|stop|restart}"

exit 1

;;

esac

Note: If you want to start seahub in fastcgi, just change the fastcgi variable to true

 

Add Directory for Logfiles

mkdir /path/to/seafile/dir/logs

 

Make the seafile-sever script executable

sudo chmod +x /etc/init.d/seafile-server

 

Add seafile-server to rc.d

sudo update-rc.d seafile-server defaults

 

Done

Don't forget to update the value of script_path later if you update your seafile server.

 

For RHEL/CentOS

On RHEL/CentOS, the script /etc/rc.local is executed by the system at bootup, so we start seafile/seahub there.

  • Locate your python executable (python 2.6 or 2.7)

which python2.6 # or "which python2.7"

  • In /etc/rc.local, add the directory of python2.6(2.7) to PATH, and add the seafile/seahub start command

# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "script_path" to your path of seafile installation

seafile_dir=/data/haiwen

script_path=${seafile_dir}/seafile-server-latest

 

sudo -u ${user} ${script_path}/seafile.sh start > /tmp/seafile.init.log 2>&1

sudo -u ${user} ${script_path}/seahub.sh start > /tmp/seahub.init.log 2>&1

Note: If you want to start seahub in fastcgi, just change the "seahub.sh start" in the last line above to "seahub.sh start-fastcgi"

  • Done. Don't forget to update the value of script_path later if you update your seafile server.

 

For RHEL/CentOS run as service

On RHEL/CentOS , we make use of the /etc/init.d/ scripts to start seafile/seahub at system boot as service.

 

Create a file /etc/sysconfig/seafile

# Change the value of "user" to your linux user name

user=haiwen

 

# Change the value of "script_path" to your path of seafile installation

seafile_dir=/home/haiwen

script_path=${seafile_dir}/seafile-server-latest

seafile_init_log=${seafile_dir}/logs/seafile.init.log

seahub_init_log=${seafile_dir}/logs/seahub.init.log

 

# Change the value of fastcgi to true if fastcgi is to be used

fastcgi=false

 

# Set the port of fastcgi, default is 8000. Change it if you need different.

fastcgi_port=8000

 

Create a script /etc/init.d/seafile

#!/bin/bash

#

# seafile

 

#

# chkconfig: - 68 32

# description: seafile

 

# Source function library.

. /etc/init.d/functions

 

# Source networking configuration.

. /etc/sysconfig/network

 

if [ -f /etc/sysconfig/seafile ];then

. /etc/sysconfig/seafile

else

echo "Config file /etc/sysconfig/seafile not found! Bye."

exit 200

fi

 

RETVAL=0

 

start() {

# Start daemons.

echo -n $"Starting seafile: "

ulimit -n 30000

su - ${user} -c"${script_path}/seafile.sh start >> ${seafile_init_log} 2>&1"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seafile

return $RETVAL

}

 

stop() {

echo -n $"Shutting down seafile: "

su - ${user} -c"${script_path}/seafile.sh stop >> ${seafile_init_log} 2>&1"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seafile

return $RETVAL

}

 

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

restart|reload)

stop

start

RETVAL=$?

;;

*)

echo $"Usage: $0 {start|stop|restart}"

RETVAL=3

esac

 

exit $RETVAL

 

Create a script /etc/init.d/seahub

#!/bin/bash

#

# seahub

 

#

# chkconfig: - 69 31

# description: seahub

 

# Source function library.

. /etc/init.d/functions

 

# Source networking configuration.

. /etc/sysconfig/network

 

if [ -f /etc/sysconfig/seafile ];then

. /etc/sysconfig/seafile

else

echo "Config file /etc/sysconfig/seafile not found! Bye."

exit 200

fi

 

RETVAL=0

 

start() {

# Start daemons.

echo -n $"Starting seahub: "

ulimit -n 30000

if [  $fastcgi = true ];

then

su - ${user} -c"${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} 2>&1"

else

su - ${user} -c"${script_path}/seahub.sh start >> ${seahub_init_log} 2>&1"

fi

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seahub

return $RETVAL

}

 

stop() {

echo -n $"Shutting down seafile: "

su - ${user} -c"${script_path}/seahub.sh stop >> ${seahub_init_log} 2>&1"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seahub

return $RETVAL

}

 

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

restart|reload)

stop

start

RETVAL=$?

;;

*)

echo $"Usage: $0 {start|stop|restart}"

RETVAL=3

esac

 

exit $RETVAL

Next, enable services:

chmod 550 /etc/init.d/seafile

chmod 550 /etc/init.d/seahub

chkconfig --add seafile

chkconfig --add seahub

chkconfig seahub on

chkconfig seafile on

and run:

service seafile start

service seahub start

 

For systems running systemd

Create systemd service files, change ${seafile_dir} to your seafile installation location and seafile to user, who runs seafile (if appropriate). Then you need to reload systemd's daemons: systemctl daemon-reload.

 

Create systemd service file /etc/systemd/system/seafile.service

[Unit]

Description=Seafile

# add mysql.service or postgresql.service depending on your database to the line below

After=network.target

 

[Service]

Type=oneshot

ExecStart=${seafile_dir}/seafile-server-latest/seafile.sh start

ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop

RemainAfterExit=yes

User=seafile

Group=seafile

 

[Install]

WantedBy=multi-user.target

 

Create systemd service file /etc/systemd/system/seahub.service

[Unit]

Description=Seafile hub

After=network.target seafile.service

 

[Service]

# change start to start-fastcgi if you want to run fastcgi

ExecStart=${seafile_dir}/seafile-server-latest/seahub.sh start

ExecStop=${seafile_dir}/seafile-server-latest/seahub.sh stop

User=seafile

Group=seafile

Type=oneshot

RemainAfterExit=yes

 

[Install]

WantedBy=multi-user.target

 

Create systemd service file /etc/systemd/system/seafile-client.service (optional)

You need to create this service file only if you have seafile console client and you want to run it on system boot.

[Unit]

Description=Seafile client

# Uncomment the next line you are running seafile client on the same computer as server

# After=seafile.service

# Or the next one in other case

# After=network.target

 

[Service]

Type=oneshot

ExecStart=/usr/bin/seaf-cli start

ExecStop=/usr/bin/seaf-cli stop

RemainAfterExit=yes

User=seafile

Group=seafile

 

[Install]

WantedBy=multi-user.target

 

Done

你可能感兴趣的:(apache)