Seafile(云盘)

前言

开源网盘、云盘搭建

环境准备

name value
系统 centOS 7
yum源 阿里云、本地镜像
seafile下载地址 seafile官网
seafile版本 Linux服务器端6.2.3 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-python python-memcached memcached python-urllib3 \
    pwgen curl openssl python-ldap java-1.7.0-openjdk poppler-utils libreoffice python-requests \
    libreoffice-headless libreoffice-pyuno wqy-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_name seafile.example.com;

    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 for view/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_pass http://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_type application/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.log main;
  error_log /var/log/nginx/error.log warn;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  client_body_timeout 12;
  client_header_timeout 12;
  keepalive_timeout 15;
  send_timeout 10;
  # Fully disabled gzip compression to mitigate Django BREACH attack: https://www.djangoproject.com/weblog/2013/aug/06/breach-and-django/
  gzip off;
  #gzip_vary on;
  #gzip_proxied expired 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/plain text/css text/xml text/javascript application/javascript application/x-javascript application/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.sh start
ExecStop=/opt/seafile/seafile-server-latest/seafile.sh stop
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.sh start 8000
ExecStop=/opt/seafile/seafile-server-latest/seahub.sh stop
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 in seafile seahub ; do
      systemctl ${ACTION} ${SERVICE}
    done
done

chmod 700 /usr/local/sbin/seafile-server-restart

  • 11.创建seafile目录
mkdir -p /opt/seafile/installed
cd /opt/seafile/
cp /opt/seafile-server_6.2.3_x86-64.tar.gz .
tar zxf seafile-server_6.2.3_x86-64.tar.gz
mv seafile-server_6.2.3_x86-64.tar.gz installed
  • 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.sh start

[12/01/17 13:38:40] ../common/session.c(132): using config file /opt/seafile/conf/ccnet.conf
Starting seafile server, please wait ...
Seafile server started

Done.

[root@seafile seafile-server-6.2.3]# ./seahub.sh start

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.sh stop

Stopping seahub ...
Done.

[root@seafile seafile-server-6.2.3]# ./seafile.sh stop

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

你可能感兴趣的:(Seafile(云盘))