2021SC@SDUSC
简介
山大智云在学长们的开发下,现在已经可以投入使用了。环境的搭建和项目的部署也是按照学长给的指示进行的。本博客中记录了一些重要步骤,并将遇到的问题和解决方法进行了介绍。
项目概述
山大智云是基于开源的Seafile开发的一款云盘,项目可以分成前端,API服务器,事件服务器,存储服务器端。再具体一些分为 seafdav:webdav扩展模块,seahub:Seafile的Web应用,包括了Web前端,seafile-server 文件存储服务,seafobj:seafile面向对象工具组,seafile-client:qt客户端,libsearpc:seafileRPC框架,libevhtp:http框架,用于接收文件传输请求,提供文件传输服务,seahub-extra、proset:基于seafile写的框架或应用,其中核心代码是开源的seafile,组员都需要在这个基础上进行进一步的系统分析。
分工
在经过小组讨论分工后,我负责seahub以及seahub-extra的代码分析任务。在代码分析过程中希望可以提高自己前端开发的能力和python应用能力。
目录
一、Docker容器的创建
使用 Docker 可以为每个项目创建单独的运行环境(容器),而不影响其他的项目环境。
但docker作为一个空的容器,首先要进行curl的安装
sudo apt-get update
sudo apt install curl
然后采用菜鸟教程中docker的安装教程:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
再创建基于 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中进行项目的环境配置了。
二、中文语言包的安装
在 虚拟机中,绝大多数 docker 的 ubuntu 容器都是最精简的镜像,通常不会安装中文包。为了在环境配置时更容易发现问题,这里选择安装一下中文语言包:
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
三、搭建项目运行环境
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
第二条指令在执行的时候可能会有部分文件下载失败,原因是SDU校园网不太给力,切换成移动热点下载就没问题了!
三、Seafile-Server环境配置
1.准备数据库
首先安装mariadb-server数据库服务,然后启动数据库
apt-get install -y mariadb-server
service mysql start
mysqladmin -u root password 123456
在控制台先运行 mysql
命令后,进入数据库命令行,复制以下命令创建数据库
create database ccnet charset utf8;
create database seafile charset utf8;
create database seahub charset utf8;
上一届的学长为了在后续消除seafevents 的错误,在这里专门创建了个用户master
指令如下:
CREATE USER 'master'@'localhost' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'master'@'localhost';
2.源文件的下载编译和安装
在指定目录下下载源码
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
我在下载时只有两个下载成功,其余均显示连接失败。在查找资料后,将链接中https
改成 git
后,再进行下载就可以了,而且速度可观。
然后输入以下命令,对源码进行编译
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
3.配置文件的创建
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
4.启动Seafile-Server
输入以下命令启动Seafile-Server
service mysql start
seaf-server -c /root/dev/conf -d /root/dev/seafile-data -D all -f -l - &
如果启动失败,考虑端口占用问题,输入jobs
命令查看进程,也可以
输入以下命令杀死别的Server进程:
kill `ps -aux | grep seaf-server | sed -n 1p | awk '{print $2}'`
运行截图:
四、Seahub环境配置
1.准备环境变量
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
2.创建 Seahub 表格
python manage.py migrate
然后进入 seahub_extra 文件夹,然后输入mysql
命令打开 MariaDB 控制台,接着输入:
source raw_table_sql.sql
以上命令使得raw_table_sql.sql
中包含的高级功能运行所需的表格代码插入到 seahub 数据库中。
3.创建超级管理用户
首先要知道manage.py文件在哪个目录下,经查找在 seahub下
python manage.py createsuperuser
然后运行指令
4.启动 Seahub
输入指令:
python manage.py runserver 0.0.0.0:8000
运行截图:
五、部署前端(React)开发环境
进入目录/root/dev/source-code/seahub/frontend
执行指令:npm install
这样依赖集就下载好了,下面执行命令npm run dev
启动本项目。如果出错,可以删除frontend
中的node_module
,重新执行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
六、Seafevents配置与启动
Seafevents是针对本项目写的一个周期任务脚本。包括定期更新索引,文件定时删除等。
根据要求完成配置后,进入指定目录下,运行可执行文件:
cd /root/dev/source-code/pro/python/seafevents
./run.sh
七、Seafdav配置与启动
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
最后在浏览器中输入http://localhost:8000/
账户名和密码在设置超级用户的时候注册的。