Seafile là một phầm mềm điện toán đám mây cung cấp các tính năng lưu trữ tương tự như Dropbox , mega.co.nz .... Seafile được dựa trên python ngôn ngữ lập trình và nó được phát hành theo một mã nguồn mở giấy phép để bạn có thể tạo ra các đám mây riêng tư của bạn và nó sẽ được an toàn hơn nhiều.
Seafile hỗ trợ mã hóa để lưu trữ dữ liệu của bạn an toàn. Để mã hóa các tập tin trong một thư viện lưu trữ, bạn cần phải thiết lập một mật khẩu khi bạn tạo thư viện. Mật khẩu sẽ không được lưu trữ trong đám mây Seafile. Vì vậy, ngay cả các quản trị viên của máy chủ không thể xem dữ liệu được mã hóa mà không cần mật khẩu.
Sau đâu chúng ta sẽ tiến hành cài đặt Seafile
Để cài đặt Seafile các bạn cần có vps . Thuê vps ở đây https://maxserver.com/
Mở các port cần thiết
# firewall-cmd --zone=public --add-port=80/tcp --permanent
# firewall-cmd --zone=public --add-port=443/tcp --permanent
# firewall-cmd --reload
Kiểm tra các port đã mở
# firewall-cmd --list-all
[root@maxserver seafile]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ssh
ports: 443/tcp 80/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
Bước 1: Cài đặt kho epel và một số dịch vụ khác
Ta gõ lệnh sau để cài đặt kho epel
# yum -y install epel-release
Sau khi cài xong kho epel ,ta cần có một số các service khác là python, nginx, mariadb
# yum -y install python-imaging MySQL-python python-simplejson python-setuptools mariadb mariadb-server nginx
Bước 2: Cấu hình MariaDB
Cho mariadb khởi động cùng hệ thống
# systemctl enable mariadb.service
Khởi động dịch vụ mariadb
# systemctl start mariadb.service
Xem trang thái của mariadb
# systemctl status mariadb
Đặt mật khẩu cho tài khoản root MySQL:
# mysql_secure_installation
Sẽ hiện ra các câu sau
[root@maxserver]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):<Nhập mật khẩu hiện tại cho root (nhập cho không có)> : cứ enter là xong
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y<Đặt mật khẩu gốc> chọn Y và nhập mật khẩu
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y<xóa người dùng vô danh> chọn Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y<Không cho phép đăng nhập root từ xa> chọn Y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y<xóa cơ sở dữ liệu kiểm tra và truy cập vào nó> chọn Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y<khởi động lại> Chọn Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Sau khi xong thiết lập mariaDB ,ta đăng nhập để tạo cơ sở dữ liệu
# mysql -u root -p
Đăng nhập xong, ta sẽ tạo 3 databases sau
- ccnet_db
- seafile_db
- seahub_db
MariaDB [(none)]> create database ccnet_db character set = 'utf8';
MariaDB [(none)]> create database seafile_db character set = 'utf8';
MariaDB [(none)]> create database seahub_db character set = 'utf8';
MariaDB [(none)]> create user seacloud@localhost identified by 'yourpassword';
MariaDB [(none)]> grant all privileges on ccnet_db.* to seacloud@localhost identified by 'yourpassword';
MariaDB [(none)]> grant all privileges on seafile_db.* to seacloud@localhost identified by 'yourpassword';
MariaDB [(none)]> grant all privileges on seahub_db.* to seacloud@localhost identified by 'yourpassword';
MariaDB [(none)]> flush privileges;
Khởi động lại mariadb
# systemctl restart mariadb
Bước 3: Cài đặt Seafile
Ta tạo 1 thư mục để chứa các file của seafile
# mkdir -p /var/www/seafile
# cd /var/www/seafile
Chạy lệnh sau để download seafile và giải nén chúng ra
# wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_6.0.5_x86-64.tar.gz
# tar -xzvf seafile-server_6.0.5_x86-64.tar.gz
Đổi tên thư mục và di chuyển vào thư mục đó
# mv seafile-server-6.0.5 seafile-server
# cd seafile-server/
Chạy lệnh sau để thực hiện cấu hình
# ./setup-seafile-mysql.sh
[root@maxserver seafile-server]# ./setup-seafile-mysql.sh
Checking python on this machine ...
Checking python module: setuptools ... Done.
Checking python module: python-imaging ... Done.
Checking python module: python-mysqldb ... Done.
-----------------------------------------------------------------
This script will guide you to setup your seafile server using MySQL.
Make sure you have read seafile server manual at
https://github.com/haiwen/seafile/wiki
Press ENTER to continue ấn enter để vào thiết lập
-----------------------------------------------------------------
What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] maxserver # Điền server name
What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] maxserver.net # Điền địa chỉ ip hoặc domain
Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/var/www/seafile/seafile-data" ] # ấn Enter
Which port do you want to use for the seafile fileserver?
[ default "8082" ] # ấn Enter
-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------
[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases
[ 1 or 2 ] 2 # Chọn 2 để thiết lập cơ sở dữ liệu
What is the host of mysql server?
[ default "localhost" ] # ấn Enter
What is the port of mysql server?
[ default "3306" ] # ấn Enter
Which mysql user to use for seafile?
[ mysql user for seafile ] seacloud # Nhập user
What is the password for mysql user "seacloud"?
[ password for seacloud ] # Nhập mật khẩu của user
verifying password of user seacloud ... done
Enter the existing database name for ccnet:
[ ccnet database ] ccnet_db # Nhập database
verifying user "seacloud" access to database ccnet_db ... done
Enter the existing database name for seafile:
[ seafile database ] seafile_db # Nhập database
verifying user "seacloud" access to database seafile_db ... done
Enter the existing database name for seahub:
[ seahub database ] seahub_db # Nhập database
verifying user "seacloud" access to database seahub_db ... done
Các bảng cơ sở dữ liệu đã đc tạo xong
-----------------------------------------------------------------
Your seafile server configuration has been finished successfully.
-----------------------------------------------------------------
run seafile server: ./seafile.sh { start | stop | restart }
run seahub server: ./seahub.sh { start <port> | stop | restart <port> }
-----------------------------------------------------------------
If you are behind a firewall, remember to allow input/output of these tcp ports:
-----------------------------------------------------------------
port of seafile fileserver: 8082
port of seahub: 8000
When problems occur, Refer to
https://github.com/haiwen/seafile/wiki
for information.
Chúng ta sẽ chạy lệnh sau để bật seafile và seahub
# ./seafile.sh start
# ./seahub.sh start
[root@maxserver seafile-server]# ./seafile.sh start
[11/24/16 04:01:21] ../common/session.c(132): using config file /var/www/seafile/conf/ccnet.conf
Starting seafile server, please wait ...
Seafile server started
Done.
[root@maxserver seafile-server]# ./seahub.sh start
LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...
----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------
What is the email for the admin account?
[ admin email ] [email protected]
What is the password for the admin account?
[ admin password ]
Enter the password again:
[ admin password again ]
Đến đây seafile đã hoàn toàn có thể chạy đc trên port 8000 nhưng chúng ta sẽ thiết lập nó vơi 1 proxy nêu chúng ta tạm thời tắt seafile đi
# ./seafile.sh stop
# ./seahub.sh stop
Bước 4: Cấu hình seafile và service seahub
Chúng ta sẽ chạy seafile như người sử dụng nginx, vì vậy chúng ta cần phải thay đổi chủ sở hữu của thư mục cài đặt seafile và thư mục seahub_cache để nginx sử dụng
# cd /var/www/
# chown -R nginx:nginx *
# chown -R nginx:nginx /tmp/seahub_cache
Tiếp theo, hãy vào thư mục systemd và tạo ra một tập tin seafile.service
# cd /etc/systemd/system/
# nano seafile.service
Nội dung cấu hình dịch vụ seafile dưới đây:
[Unit]
Description=Seafile Server
Before=seahub.service
After=network.target mariadb.service
[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seafile.sh start
ExecStop=/var/www/seafile/seafile-server/seafile.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx
[Install]
WantedBy=multi-user.target
Bây giờ tạo tập tin seahub.service mới.
# nano seahub.service
[Unit]
Description=Seafile Hub
After=network.target seafile.target mariadb.service
[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seahub.sh start-fastcgi
ExecStop=/var/www/seafile/seafile-server/seahub.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx
[Install]
WantedBy=multi-user.target
Khởi động lại service
# systemctl daemon-reload
Khởi động service seafile và seahub
# systemctl start seafile
# systemctl start seahub
# systemctl enable seafile
# systemctl enable seahub
Kiểm tra các dịch vụ seafile và seahub đang chạy trên cổng 8082 và 8000
# netstat -tulpn
Bước 5: Tạo SSL
Chúng ta sẽ để seafile chạy qua proxy nginx , chúng ta có thể tạo 1 ssl để nginx cung cấp 1 kết nối an toàn
Tạo thư mục ssl.
# mkdir -p /etc/nginx/ssl
# cd /etc/nginx/ssl
Tạo giấy chứng nhận file và một tập tin dhparam với lệnh dưới đây:
# openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
# openssl req -new -x509 -sha256 -days 365 -newkey rsa:2048 -nodes -keyout server.key -out server.crt
Điền các thông tin theo yêu cầu của OpenSSL như tên, trạng thái, email, tên miền vv Sau đó, thay đổi các điều khoản của các tập tin thư mục và giấy chứng nhận
# chmod -R 700 /etc/nginx/ssl
# chmod 400 server.*
# chmod 400 dhparam.pem
Các tập tin chứng nhận SSL đã được tạo ra.
Bước 6: Cấu hình Nginx làm Proxy
Tới thư mục cấu hình nginx và tạo ra một tập tin máy chủ ảo mới cho seafile
# cd /etc/nginx/
# nano conf.d/seafile.conf
Với nội dung như sau, ở đây ta có domain là maxserver.net
server {
listen 80;
server_name maxserver.net;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name maxserver.net;
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_prefer_server_ciphers on;
location / {
fastcgi_pass 127.0.0.1:8000;
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;
access_log /var/log/nginx/seahub.access.log;
error_log /var/log/nginx/seahub.error.log;
fastcgi_read_timeout 36000;
}
# Reverse Proxy for seahub
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;
proxy_send_timeout 36000s;
send_timeout 36000s;
}
#CHANGE THIS PATH WITH YOUR OWN DIRECTORY
location /media {
root /var/www/seafile/seafile-server/seahub;
}
}
Kiểm tra nginx bằng lệnh sau
# nginx -t
[root@maxserver ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Khởi động nginx
# systemctl start nginx
# systemctl enable nginx
Kiểm tra port
# netstat -tulpn
[root@maxserver ~]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2381/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2445/nginx: master
tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN 2527/seaf-server
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1038/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2224/master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 2445/nginx: master
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 2611/python2.7
tcp6 0 0 :::80 :::* LISTEN 2445/nginx: master
tcp6 0 0 :::22 :::* LISTEN 1038/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2224/master
udp 0 0 0.0.0.0:36883 0.0.0.0:* 436/avahi-daemon: r
udp 0 0 0.0.0.0:5353 0.0.0.0:* 436/avahi-daemon: r
Thêm domain cho file cấu hình seafile
# cd /var/www/seafile/
# nano conf/ccnet.conf
Thay đổi dòng sau ,điền domain của bạn vào
SERVICE_URL = https://maxserver.net:8000
# nano conf/seahub_settings.py
Thay dổi dòng sau
HTTP_SERVER_ROOT = 'https://maxserver.net/seafhttp'
Khởi động lại service seafile
# systemctl restart seafile
# systemctl restart seahub
Đến đây chúng ta đã hoàn thành việc cài đặt seafile với nginx làm proxy
Các bạn có thể dùng trình duyệt web truy cập vào domain của bạn
Đăng nhập bằng email và pass bạn vừa thiết lập ở trên