前言
开源网盘、云盘搭建,自动同步(亲测成功案例分享)
环境准备
系统 centOS 7.4
yum源 阿里云、本地镜像
seafile下载地址 seafile官网
seafile版本 Linux服务器端6.2.3 X86 64bit
seafile存放路径 /opt/
安装用户 root
操作步骤
1.设置selinux
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=permissive/'/etc/selinux/config
2.设置防火墙
yum install firewalld fail2ban -y
for i in ssh http https ; do firewall-cmd --zone=public--add-service=${i} --permanent ; done
firewall-cmd --reload
3.安装依赖包
yum install epel-release -y
yum upgrade -y
yum install python-setuptools python-imaging MySQL-pythonpython-memcached memcached python-urllib3 pwgen curl openssl python-ldapjava-1.7.0-openjdk poppler-utils libreoffice python-requests libreoffice-headless libreoffice-pyunowqy-microhei-fonts wqy-zenhei-fonts wqy-unibit-fonts -y
4.将memcached设置为开机自启
systemctl enable memcached
5.安装nginx
yum install nginx -y
systemctl enable nginx
rm -rf /etc/nginx/conf.d/*
vi /etc/nginx/conf.d/seafile.conf
server {
listen 80;
server_nameseafile.example.com; #此处填写阿里云给的公网IP地址
proxy_set_header X-Forwarded-For $remote_addr;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_read_timeout 1200s;
# used forview/edit office file via Office Online Server
client_max_body_size 0;
access_log /var/log/nginx/seahub.access.log;
error_log /var/log/nginx/seahub.error.log;
}
location /seafhttp{
rewrite ^/seafhttp(.*)$$1 break;
proxy_passhttp://127.0.0.1:8082;
client_max_body_size 0;
proxy_connect_timeout 36000s;
proxy_read_timeout 36000s;
}
location /media{
root /opt/seafile/seafile-server-latest/seahub;
}
location /seafdav{
fastcgi_pass 127.0.0.1:8080;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REMOTE_ADDR $remote_addr;
client_max_body_size 0;
access_log /var/log/nginx/seafdav.access.log;
error_log /var/log/nginx/seafdav.error.log;
}
}
6.创建nginx配置文件
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
vi /etc/nginx/nginx.conf
user nginx nginx;
worker_processes 4;
events {
worker_connections 8096;
multi_accept on;
use epoll;
}
pid /var/run/nginx.pid;
worker_rlimit_nofile 40000;
http {
server_tokens off;
server_names_hash_bucket_size 128;
client_max_body_size 50M;
include /etc/nginx/mime.types;
default_typeapplication/octet-stream;
log_format main '$remote_addr- $remote_user [$time_local] "$request" '
'$status$body_bytes_sent "$http_referer" '
'"$http_user_agent""$http_x_forwarded_for"';
access_log /var/log/nginx/access.logmain;
error_log /var/log/nginx/error.logwarn;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout15;
send_timeout 10;
# Fully disabledgzip compression to mitigate Django BREACH attack
gzip off;
#gzip_vary on;
#gzip_proxiedexpired no-cache no-store private auth any;
#gzip_comp_level 9;
#gzip_min_length 10240;
#gzip_buffers 16 8k;
#gzip_http_version 1.1;
#gzip_types text/plaintext/css text/xml text/javascript application/javascript application/x-javascriptapplication/xml font/woff2;
#gzip_disable "MSIE[1-6].";
include /etc/nginx/conf.d/*.conf;
}
7.重启nginx
systemctl restart nginx
8.安装MySQL
yum install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
mysqladmin -u root password pwgen
vi /root/.my.cnf
[client]
user=root
password=pwgen
chmod 600 /root/.my.cnf
9.创建seafile的systemctl服务脚本
vi /etc/systemd/system/seafile.service
[Unit]
Description=Seafile Server
After=network.target mariadb.service
[Service]
Type=oneshot
ExecStart=/opt/seafile/seafile-server-latest/seafile.shstart
ExecStop=/opt/seafile/seafile-server-latest/seafile.shstop
RemainAfterExit=yes
User=root
Group=root
[Install]
WantedBy=multi-user.target
命令行
systemctl enable seafile
vi /etc/systemd/system/seahub.service
[Unit]
Description=Seafile Seahub
After=network.target seafile.service
[Service]
ExecStart=/opt/seafile/seafile-server-latest/seahub.shstart 8000
ExecStop=/opt/seafile/seafile-server-latest/seahub.shstop
User=root
Group=root
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
命令行
systemctl enable seahub
10.创建seafile重启脚本
vi /usr/local/sbin/seafile-server-restart
#!/bin/bash
for ACTION in stop start ; do
for SERVICE inseafile seahub ; do
systemctl${ACTION} ${SERVICE}
done
done
命令行
chmod 700 /usr/local/sbin/seafile-server-restart
11.创建seafile目录
mkdir -p /opt/seafile/installed
cd /opt/
wgethttp://seafile-downloads.oss-cn-shanghai.aliyuncs.com/seafile-server_6.2.3_x86-64.tar.gz
cd /opt/seafile/
cp /opt/seafile-server_6.2.3_x86-64.tar.gz .
tar -zxvf seafile-server_6.2.3_x86-64.tar.gz
mv seafile-server_6.2.3_x86-64.tar.gz installed
##./setup-seafile-mysql.sh
##下面按照seafile官网要求进行设置,记住你的公网IP
12.配置seafile 数据库
vi /opt/seafile.my.cnf
[client]
user=root
password=pwgen
命令行
chmod 600 /opt/seafile.my.cnf
cd /opt/seafile/seafile-server-6.2.3/
mkdir -p /opt/seafile/conf
./setup-seafile-mysql.sh auto -u seafile -w pwgen -r pwgen
13.配置seafile WebDAV服务
vi /opt/seafile/conf/seafdav.conf
[WEBDAV]
enabled = true
port = 8080
fastcgi = true
share_name = /seafdav/
14.配置seahub_settings.py
vi /opt/seafile/conf/seahub_settings.py ##在末尾插入
ACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
# EMAIL_USE_TLS = False
# EMAIL_HOST = 'localhost'
# EMAIL_HOST_USER = ''
# EMAIL_HOST_PASSWORD = ''
# EMAIL_PORT = '25'
# DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
# SERVER_EMAIL = EMAIL_HOST_USER
TIME_ZONE = Asia/Shanghai
SITE_BASE = 'http://127.0.0.1'
SITE_NAME = 'Seafile Server'
SITE_TITLE = 'Seafile Server'
SITE_ROOT = '/'
ENABLE_SIGNUP = False
ACTIVATE_AFTER_REGISTRATION = False
SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER = True
SEND_EMAIL_ON_RESETTING_USER_PASSWD = True
CLOUD_MODE = False
FILE_PREVIEW_MAX_SIZE = 30 * 1024 * 1024
SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2
SESSION_SAVE_EVERY_REQUEST = False
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
FILE_SERVER_ROOT = 'http://127.0.0.1/seafhttp'
15.备份check_init_admin.py
cp /opt/seafile/seafile-server-6.2.3/check_init_admin.py/opt/seafile/seafile-server-6.2.3/check_init_admin.py.backup
16.设置管理证书
vi /opt/seafile/seafile-server-6.2.3/check_init_admin.py ##修改第366、367行
修改前
email = ask_admin_email()
passwd = ask_admin_password()
修改后
email = "[email protected]"
passwd = "pwgen"
17.启动和关闭服务,以便生成管理员用户
[root@seafile seafile-server-6.2.3]# pwd
/opt/seafile/seafile-server-6.2.3
[root@seafile seafile-server-6.2.3]# ./seafile.shstart
[12/01/17 13:38:40] ../common/session.c(132): usingconfig file /opt/seafile/conf/ccnet.conf
Starting seafile server, please wait ...
Seafile server started
Done.
[root@seafile seafile-server-6.2.3]# ./seahub.shstart
LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...
----------------------------------------
Successfully created seafile admin
----------------------------------------
Seahub is started
Done.
[root@seafile seafile-server-6.2.3]# ./seahub.shstop
Stopping seahub ...
Done.
[root@seafile seafile-server-6.2.3]# ./seafile.shstop
Stopping seafile server ...
Done.
18.恢复原来的check_init_admin.py
mv check_init_admin.py.backup check_init_admin.py
重启seafile服务
/usr/local/sbin/seafile-server-restart
19.设置你的SEAFILE 服务器
网页以管理员登录你的服务器,设置2个主要参数
SERVICE_URL 为http://你的公网IP(或者127.0.0.1):8000
FILE_SERVER)ROOT 为http://你的公网IP/seahttp