由于网盘项目一直在更新,旧的安装指南已经过时,需要新的指南。
本安装教程最后更新时间 2021年5月27日
使用以下命令创建基于 Ubuntu 18.04 的 Docker 容器:
docker run -it -p 8000:8000 -p 8080:8080 -p 8082:8082 -p 3000:3000 -p 9200:9200 --name seafile-ce-env ubuntu:18.04 bash
Docker 内部的文件夹:
/root/dev/conf
:存放配置文件/root/dev/source-code
:存放源代码/tmp
:存放日志和 Cache 文件apt-get install language-pack-zh-hans
locale-gen zh_CN.UTF-8
echo "export LC_ALL=zh_CN.UTF-8">>/root/.bashrc
source /root/.bashrc
输入 locale
查看当前语言:
LANG=
LANGUAGE=
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=zh_CN.UTF-8
在实体机 Ubuntu 上可意不用担心这个问题,因为它们默认会安装 UTF-8 语言包。但是在 docker 容器中,必须进行此步骤,因为绝大多数 docker 的 ubuntu 容器都是最精简的镜像,通常不会安装中文包。
apt-get update && apt-get upgrade -y
apt-get install -y ssh libevent-dev libcurl4-openssl-dev libglib2.0-dev uuid-dev intltool libsqlite3-dev libmysqlclient-dev libarchive-dev libtool libjansson-dev valac libfuse-dev python-dateutil cmake re2c flex sqlite3 python-pip python-simplejson git libssl-dev libldap2-dev libonig-dev vim vim-scripts wget cmake gcc autoconf automake mysql-client librados-dev libxml2-dev curl sudo telnet netcat unzip netbase ca-certificates apt-transport-https build-essential libxslt1-dev libffi-dev libpcre3-dev libz-dev xz-utils nginx pkg-config poppler-utils libmemcached-dev openjdk-11-jdk aria2 sudo
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt-get install -y nodejs
apt-get install -y python3-pip python3.6 python3.6-dev
python3.6 -m pip install --upgrade pip
rm /usr/bin/python
rm /usr/bin/python3
ln -s /usr/bin/python3.6 /usr/bin/python
ln -s /usr/bin/python3.6 /usr/bin/python3
rm /usr/bin/pip
rm /usr/bin/pip3
ln -s /usr/local/bin/pip3.6 /usr/bin/pip
ln -s /usr/local/bin/pip3.6 /usr/bin/pip3
pip install python-cas djangosaml2 cffi sqlalchemy pymysql pillow pycryptodome configparser pylibmc django-pylibmc elasticsearch==5.5.0 elasticsearch-dsl==5.4.0 Django==2.2.14 future captcha django-statici18n django-post_office==3.3.0 django-webpack_loader==0.7.0 gunicorn mysqlclient django-picklefield==2.1.1 openpyxl qrcode django-formtools django-simple-captcha djangorestframework==3.11.1 python-dateutil requests pillow pyjwt pycryptodome requests_oauthlib mock nose exam splinter pytest pytest-django
apt-get install -y mariadb-server
service mysql start
mysqladmin -u root password 123456
建表用的 SQL(在控制台先运行 mysql 命令后,进入数据库命令行):
create database ccnet charset utf8;
create database seafile charset utf8;
create database seahub charset utf8;
然后创建一个 master 用于消除 seafevents 的错误(方便起见,后面的配置也用这个用户了):
CREATE USER 'master'@'localhost' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'master'@'localhost';
cd ~/
mkdir -p ~/dev/source-code
cd ~/dev/source-code
git clone https://github.com/SDU-NetdiskTeam/libevhtp.git
git clone https://github.com/SDU-NetdiskTeam/libsearpc.git
git clone https://github.com/SDU-NetdiskTeam/seafile-server.git
git clone https://github.com/SDU-NetdiskTeam/seahub.git
git clone https://github.com/SDU-NetdiskTeam/seahub-extra.git seahub_extra
git clone https://github.com/SDU-NetdiskTeam/pro-set.git pro
git clone https://github.com/SDU-NetdiskTeam/seafdav.git
cd libsearpc/
git checkout 8.0
cd ../seafile-server
git checkout develop
cd ../seahub
git checkout develop
cd ../libevhtp
cmake -DEVHTP_DISABLE_SSL=ON -DEVHTP_BUILD_SHARED=OFF .
make
make install
ldconfig
cd ../libsearpc
./autogen.sh
./configure
make
make install
ldconfig
cd ../seafile-server
./autogen.sh
./configure --disable-fuse
make
make install
ldconfig
mkdir ~/dev/conf
cd ~/dev/conf
cat > ccnet.conf <<EOF
[Database]
ENGINE = mysql
HOST = localhost
PORT = 3306
USER = master
PASSWD = 123456
DB = ccnet
CONNECTION_CHARSET = utf8
CREATE_TABLES = true
[General]
SERVICE_URL = http://127.0.0.1:8000
EOF
cat > seahub_settings.py <<EOF
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'seahub',
'USER': 'master',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': '3306',
}
}
FILE_SERVER_ROOT = 'http://127.0.0.1:8082'
EOF
cat > seafevents.conf <<EOF
[DATABASE]
type = mysql
host = localhost
port = 3306
username = master
password = 123456
name = seahub
[AUDIT]
enabled = false
[INDEX FILES]
external_es_server = true
es_host = 127.0.0.1
es_port = 9200
enabled = true
interval = 10m
highlight = fvh
## If true, indexes the contents of office/pdf files while updating search index
## Note: If you change this option from "false" to "true", then you need to clear the search index and update the index again. See the FAQ for details.
index_office_pdf = true
[OFFICE CONVERTER]
port = 6000
host = 127.0.0.1
enabled = false
workers = 1
[SEAHUB EMAIL]
enabled = false
## interval of sending Seahub email. Can be s(seconds), m(minutes), h(hours), d(days)
interval = 30m
# Enable statistics
[STATISTICS]
enabled=false
# Enable Aria2 offline download
[OFFLINE DOWNLOAD]
enabled = true
tempdir = /tmp/offline-download
workers = 10
## time limit of download. Can be s(seconds), m(minutes), h(hours), d(days)
time-limit = 900s
# Enable auto deletion
[AUTO DELETION]
enabled = true
interval = 1d
EOF
cat > seafile.conf <<EOF
[database]
type = mysql
host = localhost
port = 3306
user = master
password = 123456
db_name = seafile
connection_charset = utf8
create_tables = true
[virus_scan]
scan_command = clamscan
virus_code = 1
nonvirus_code = 0
scan_interval = 60
# scan_size_limit = (size limit for files to be scanned)
# scan_skip_ext = (a comma (',') separated list of file extensions to be ignored)
# threads = (number of concurrent threads for scan, one thread for one file, default to 4)
EOF
cat > seafdav.conf <<EOF
[WEBDAV]
# Default is false. Change it to true to enable SeafDAV server.
enabled = true
port = 8080
# If you deploy seafdav behind nginx/apache, you need to modify "share_name".
share_name = /
EOF
mkdir ~/dev/seafile-data
cd ~/dev/seafile-data
ln -s ../conf/seafile.conf ./
mkdir ~/dev/logs
service mysql start
seaf-server -c /root/dev/conf -d /root/dev/seafile-data -D all -f -l - &
如果先前已经开过一个 Seafile-server,则其 Socket 文件可能被占用。用以下命令杀死旧的 Server 进程:
kill `ps -aux | grep seaf-server | sed -n 1p | awk '{print $2}'`
cd ~/dev/source-code/seahub/
export PYTHONPATH=/usr/local/lib/python3.6/site-packages/:/root/dev/source-code/seahub/thirdpart:$PYTHONPATH
export PYTHONPATH=/root/dev/source-code:/root/dev/source-code/pro/python:$PYTHONPATH
export CCNET_CONF_DIR=/root/dev/conf
export SEAFILE_CONF_DIR=/root/dev/seafile-data
export SEAFILE_CENTRAL_CONF_DIR=/root/dev/conf
export SEAFES_DIR=/root/dev/source-code/pro/python/seafes
export SEAHUB_DIR=/root/dev/source-code/seahub
export SEAHUB_LOG_DIR=/root/dev/logs
python manage.py migrate
然后看到 seahub_extra 文件夹,里面有一个 raw_table_sql.sql
文件,那里面包含了使得高级功能运行所需的表格代码,请将其中描述的表格插入到 seahub 数据库中,操作方法如下:
首先 cd 进入 seahub_extra 文件夹,然后输入 mysql
命令打开 MariaDB 控制台,接着输入:
source raw_table_sql.sql
即可完成数据表创建。
python manage.py createsuperuser
需要先准备环境变量。
python manage.py runserver 0.0.0.0:8000
.
`-- dev
|-- conf
| |-- __pycache__
| |-- ccnet.conf
| |-- seafevents.conf
| |-- seafile.conf
| `-- seahub_settings.py
|-- seafile-data
| |-- httptemp
| |-- library-template
| |-- seafile.conf -> ../conf/seafile.conf
| |-- seafile.sock
| |-- storage
| |-- tmpfiles
| `-- webdavtmp
`-- source-code
|-- libevhtp
|-- libsearpc
|-- pro
|-- seafile
|-- seafile-server
|-- seahub
`-- seahub_extra
完成前端开发环境部署后,所有对前端页面的请求将被转到 npm 服务。因此,一旦完成配置后,必须保证三端(server,django,npm)同时启动后,才能正常使用。
前端开发环境的作用:加快 React JS 的重新编译速度,修改后立即能在前端看到改动。
注意,完成前端开发后,不要忘了在 seahub 项目中使用如下命令:
cd ~/dev/souece-code/seahub/frontend
npm build
cd ..
make clean
make dist
如果在 npm build
时出错了,尝试使用以下命令,然后再 build:
npm install
向 /root/dev/conf/seahub_settings.py
文件中添加如下内容:
import os
PROJECT_ROOT = '/root/dev/source-code/seahub'
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'frontend/',
'STATS_FILE': os.path.join(PROJECT_ROOT,
'frontend/webpack-stats.dev.json'),
}
}
DEBUG = True
安装 node 模块
cd /root/dev/source-code/seahub/frontend
npm install
执行 npm run dev
cd /root/dev/source-code/seahub/frontend
npm run dev
最后,启动 Seafile-server 和 seahub,完成。
Seafevents 主要就是各种周期性任务的执行。比如,每 10 分钟一次的搜索 Indexing,还有 Auditing,Virus Scan 等。没有 Seafevents,搜索系统数据将不会得到及时更新。
cp /root/dev/source-code/pro/python/seafevents/main.py /root/dev/source-code/pro/python/seafevents/seafile_events.py
cat > /root/dev/source-code/pro/python/seafevents/run.sh << EOD
#!/bin/bash
# Your ccnet conf dir
export CCNET_CONF_DIR=/root/dev/conf
# Your seafile conf dir
export SEAFILE_CONF_DIR=/root/dev/seafile-data
# Your extra python path.
export PYTHONPATH=/usr/local/lib/python3.6/site-packages/:/root/dev/source-code/seahub/thirdpart:/root/dev/source-code:/root/dev/source-code/pro/python:/usr/local/lib/python3.6/site-packages/:/root/dev/source-code/seahub/thirdpart:
export PYTHONPATH=/root/dev/source-code:/root/dev/source-code/pro/python:/root/dev/source-code:/root/dev/source-code/pro/python:/usr/local/lib/python3.6/site-packages/:/root/dev/source-code/seahub/thirdpart:
pkill -f "python seafile_events.py"
python seafile_events.py --loglevel=info --logfile=/root/dev/logs/events.log --reconnect --config-file=/root/dev/conf/seafevents.conf
EOD
chmod +x /root/dev/source-code/pro/python/seafevents/run.sh
注意,本命令需要完成环境变量配置后才可运行。
cd /root/dev/source-code/pro/python/seafevents
./run.sh
首先创建好用户和用户组,并设置好密码。
groupadd es
useradd es -g es
passwd es
mkdir /home/es
cp -r /root/dev/source-code/pro/elasticsearch /home/es/
chown -R es /home/es
将 Elastic Search 的目录
然后通过 su 命令切换用户。
su es
启动 Elastic search:
cd /home/es/elasticsearch/bin
./elasticsearch
启动完成后,Elastic Search 会在默认端口 9200 启动。
然后别忘了配置一下 Seafes。
cat > /root/dev/source-code/pro/python/seafes/run.sh <<EOF
export PYTHONPATH=/usr/local/lib/python3.6/site-packages/:/root/dev/source-code/seahub/thirdpart:$PYTHONPATH
export PYTHONPATH=/root/dev/source-code:/root/dev/source-code/pro/python:$PYTHONPATH
export SEAHUB_DIR=/root/dev/source-code/seahub
export CCNET_CONF_DIR=/root/dev/conf
export SEAFILE_CONF_DIR=/root/dev/seafile-data
export EVENTS_CONFIG_FILE=/root/dev/conf/seafevents.conf
if [[ $# == 1 && $1 == "clear" ]]; then
python -m seafes.index_local --loglevel debug clear
else
python -m seafes.index_local --loglevel debug update
fi
EOF
chmod +x /root/dev/source-code/pro/python/seafes/run.sh
如果运行了 Elastic Search 主程序后,出现了一段时间后自动 Kill 的问题,请打开 /home/es/elasticsearch/config/jvm.options
文件,并找到其中的字段:
-Xms1g
-Xmx1g
-XX:-AssumeMP
将其改成
-Xms512m
-Xmx512m
-XX:-AssumeMP
即可解决问题。
配置在 seafile.conf
文件夹中,这份文件是用 ClamAV 进行的。
刷新病毒库:freshclam
Seafdav 用于支持 WebDAV 服务。
#!/bin/bash
export CCNET_CONF_DIR=/root/dev/conf
export SEAFILE_CONF_DIR=/root/dev/seafile-data
export SEAFILE_CENTRAL_CONF_DIR=/root/dev/conf
export PYTHONPATH=/usr/local/lib/python3.6/site-packages/:/root/dev/source-code/seahub/thirdpart:$PYTHONPATH
export PYTHONPATH=/root/dev/source-code:/root/dev/source-code/pro/python:$CCNET_CONF_DIR:$PYTHONPATH
TOP_DIR=$(python -c "import os; print(os.path.dirname(os.path.realpath('$0')))")
cd "$TOP_DIR"
python -m wsgidav.server.server_cli --host=0.0.0.0 --port=8080 --root=/ --server=gunicorn
cd /root/dev/source-code/seafdav
./run.sh
用户可以设置资料库内文件自动删除的时间,时间到以后会自动删除文件。
按照前面的配置把 seafevents.conf
文件中的 AUTO DELETION
下的 enabled
设置为 true
即可。
此功能运行必须有 seafevents 支持。如果 seafevents 没有运行,那么用户即使设置了自动删除,也不会自动删除文件。
假设能被公网访问到的计算机 ip 为 <ip>,用户名为 <user>,命令为:
ssh <user>@<ip> -R 0.0.0.0:8000:127.0.0.1:8000 -R 0.0.0.0:8080:127.0.0.1:8080 -R 0.0.0.0:8082:127.0.0.1:8082 -R 0.0.0.0:9200:127.0.0.1:9200 -R 0.0.0.0:8001:127.0.0.1:8001
各端口释义: