2021SC@SDUSC
本篇内容记录如何在本地部署山大智云。
原篇内容来源于:https://blog.csdn.net/rentenglong2012/article/details/117335295
本篇内容最后更新于2021年9月29日,对原篇内容(2021年5月27日)做出了一小部分更正。
操作系统
Ubuntu 18.04 (.1~.6)
前置操作
在外环境下配置基础环境。此时建议使用root身份。
-
自动安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
若执行后阻塞或报错,则为网络问题,考虑尝试手动安装。
-
手动安装
sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0EBFCD88 sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \ $(lsb_release -cs) \ stable" sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io sudo docker run hello-world # 测试,可有可无
-
apt换源
为了提高apt-get的下载速度,并降低出错率,考虑更换源为国内镜像。此步骤可选。
-
备份源
mv /etc/apt/sources.list /etc/apt/sources.list.bak
-
更换源为国内镜像
-
创建源
vim /etc/apt/sources.list
-
输入以下内容,然后保存并关闭
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
-
-
部署
-
创建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相关操作
-
退出
在容器中
Ctrl+D
,或者输入exit
。 -
查看所有容器
docker ps -a
-
进入容器
docker attach [容器名]
-
启动容器
docker start [容器名]
-
注意:以下所有操作都需要在容器内部完成
-
-
安装中文语言
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
-
安装前置组件
-
更新软件列表并升级apt
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 vim
-
安装nodejs
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - apt-get install -y nodejs
-
安装python及依赖模块
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 json5 pyyaml jinja2
(原篇内容中缺少
json5
,pyyaml
,jinja2
,此处已补)
-
-
准备数据库
apt-get install -y mariadb-server service mysql start mysqladmin -u root password 123456 # 设置root密码为123456 mysql
此时进入mysql终端。
-
下载项目源代码
源代码均来自于:https://github.com/orgs/SDU-NetdiskTeam/repositories
cd ~/ mkdir -p ~/dev/source-code cd ~/dev/source-code git clone https://github.com.cnpmjs.org/SDU-NetdiskTeam/libevhtp.git git clone https://github.com.cnpmjs.org/SDU-NetdiskTeam/libsearpc.git git clone https://github.com.cnpmjs.org/SDU-NetdiskTeam/seafile-server.git git clone https://github.com.cnpmjs.org/SDU-NetdiskTeam/seahub.git git clone https://github.com.cnpmjs.org/SDU-NetdiskTeam/seahub-extra.git seahub_extra git clone https://github.com.cnpmjs.org/SDU-NetdiskTeam/pro-set.git pro git clone https://github.com.cnpmjs.org/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
使用Screen进行后台并发管理
本篇内容中的所有模块都在同一机器内部署,为了使各个模块能并发运行,考虑使用Screen进行并发管理。
-
安装screen
apt-get install screen
-
创建窗口
screen -S [窗口名]
-
不挂起并回到主窗口
Ctrl+D
,然后按A
。 -
回到窗口
screen -r [窗口名]
-
关闭窗口
screen -S [窗口名] -X quit
seafile-server
seafile-server是seafile的服务端核心。
-
启动
service mysql start seaf-server -c /root/dev/conf -d /root/dev/seafile-data -D all -f -l - &
seafile-server默认后台运行,因此不需要额外使用screen启动。
-
关闭
kill `ps -aux | grep seaf-server | sed -n 1p | awk '{print $2}'`
(部署过程中不涉及)
seahub
seahub是seafile的Web服务。
-
配置环境变量
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
-
配置服务器
-
启动
如果没创建
seahub
窗口,则创建seahub
窗口:screen -S seahub
然后在此窗口内执行:
cd /root/dev/source-code/seahub python manage.py runserver 0.0.0.0:8000
最后回到主窗口。此时seahub在seahub窗口内并发运行。
seahub-frontend
seahub/frontend是seahub的前端。部署React开发环境是为了加快其重新编译的速度,使得修改立即生效。
-
安装
cd ~/dev/source-code/seahub/frontend npm i core-js@2.6.9 -D npm install npm audit fix # 这步可省略 npm run-script build
(此处需要安装降级的core-js,否则会编译失败。)
-
配置
vim /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
-
启动
如果没创建
frontend
窗口,则创建frontend
窗口:screen -S frontend
然后在此窗口内执行:
cd /root/dev/source-code/seahub/frontend npm run dev
最后回到主窗口。此时seahub前端在frontend窗口内并发运行。
-
开发
在完成了前端的开发后,使用如下命令重新编译:
cd ~/dev/souece-code/seahub/frontend npm run-script build cd .. make clean make dist
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
-
启动
如果没创建
seafevents
窗口,则创建seafevents
窗口:screen -S seafevents
然后在此窗口内执行:
cd /root/dev/source-code/pro/python/seafevents ./run.sh
最后回到主窗口。此时周期事件脚本在seafevents窗口内并发运行。
Elastic Search
用于提供全文搜索服务。
-
安装Elastic Search
创建es用户:
groupadd es useradd es -g es passwd es
然后输入密码。
接下来从proset中复制elastic search:
mkdir /home/es cp -r /root/dev/source-code/pro/elasticsearch /home/es/ chown -R es /home/es
-
配置
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
(此脚本用于刷新或清空索引)
-
启动
如果没创建
seafes
窗口,则创建seafes
窗口:screen -S seafes
然后在此窗口内执行:
-
切换至此用户:
su es
-
运行Elastic Search
cd /home/es/elasticsearch/bin ./elasticsearch
最后回到主窗口。此时Elastic Search在es窗口内并发运行。
-
seafdav
用于支持Web DAV服务。
-
配置
vim /root/dev/source-code/seafdav/run.sh
然后输入以下内容:
#!/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
最后添加可执行权限:
chmod +x /root/dev/source-code/seafdav/run.sh
-
启动
如果没创建
seafdav
窗口,则创建seafdav
窗口:screen -S seafdav
然后在此窗口内执行:
cd /root/dev/source-code/seafdav ./run.sh
最后回到主窗口。此时DAV服务在seafdav窗口内并发运行。
(推荐在最后完成此步骤)
安装ClamAV
用于扫描病毒。
groupadd clamav
useradd -g clamav clamav
sudo apt-get install clamav clamav-freshclam
freshclam # 刷新病毒库,较慢
测试
当在窗口seahub
、frontend
、seafevents
、seafes
、seafdav
启动了各自的服务进程后,打开火狐浏览器,输入localhost:8000
进入网站进行测试。(用户名密码为此前设置的超级用户)
建立临时公网访问隧道
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
各端口释义:
- 8000 Seahub
- 8001 Office
- 8082 Seafile server
- 9200 Elastic search