How to Install Seafile with Nginx on CentOS 7

Seafile is a private cloud software to that provides similar features like Dropbox, mega.co.nz, and others, just hosted on your own server. Seafile is based on the python programming language and it is released under an open source license so that you can create your own private cloud and it will be much more secure.

Seafile supports encryption to store your data securely. To encrypt files in a storage library, you need to set a password when you create the library. The password won't be stored in the Seafile cloud. So even the administrator of the servers cannot view your encrypted data without the password.

In this tutorial, I will install Seafile on CentOS 7 with Nginx web server and MariaDB as the database server.

Prerequisites

  • CentOS 7 server
  • Root privileges

Step 1 - Prepare CentOS for Seafile

Login to the centOS server with your ssh root password.

ssh root@192.168.1.115
TYPE YOUR PASSWORD

Edit the SELinux configuration file with vim.

vim /etc/sysconfig/selinux

Replace value 'enforcing' with 'disabled'.

SELINUX=disabled

Save the file and exit the editor.

Reboot the server to apply the change of the SELinux policy.

reboot

Wait for server rebooting, then login to your server again as root user.

Check the selinux with command below:

getenforce

You should see 'Disabled' as the result.

Step 2 - Install the Seafile Dependencies

Seafile is based on python, so we need to install python for the installation first. Seafile has support for SQLite and MySQL/MariaDB databases, I will use MariaDB as the database for seafile here as it provides a better performance than SQLite. Nginx is used as the reverse proxy for Seafile and Seahub.

In this step, we will install several python packages, MariaDB and Nginx. We begin with the installation of the EPEL repository on our CentOS server.

yum -y install epel-release

Next, install python the packages, MariaDB and Nginx.

yum -y install python-imaging MySQL-python python-simplejson python-setuptools mariadb mariadb-server nginx

Wait until all packages are installed.

Step 3 - Configure MariaDB

In step 2, we've already installed the MariaDB server, we just need to start the service and configure the root password now.

Start MariaDB and configure the root password with the commands below:

systemctl start mariadb
mysql_secure_installation

Type in your root password.

Set root password? [Y/n] Y
New password:
Re-enter new password:

Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

The MariaDB root password is configured and we can login to the mysql shell now.
Notice: The MariaDB commandline shell is named mysql.

We will create 3 databases for seafile:

  1. ccnet_db
  2. seafile_db
  3. seahub_db

And we will create a new user 'seacloud' with the password 'yourpassword'. Replace yourpassword with a secure password!

Login to the mysql shell with the mysql client.

mysql -u root -p
TYPE YOUR PASSWORD

Run the mysql queries below to create the databases and the user for the seafile installation.

create database ccnet_db character set = 'utf8';
create database seafile_db character set = 'utf8';
create database seahub_db character set = 'utf8';

create user seacloud@localhost identified by 'yourpassword';

grant all privileges on ccnet_db.* to seacloud@localhost identified by 'yourpassword';
grant all privileges on seafile_db.* to seacloud@localhost identified by 'yourpassword';
grant all privileges on seahub_db.* to seacloud@localhost identified by 'yourpassword';
flush privileges;
exit

Replace yourpassword in the above commands with your own password.

001.png

Step 4 - Install Seafile

In this step, we will install Seafile. Seafile will be executed under the nginx user so we can use nginx as the reverse proxy for the seafile and seahub services.

We will install seafile under the nginx user in the directory '/var/www/seafile', create that dirctory and enter it with cd.

mkdir -p /var/www/seafile
cd /var/www/seafile

Download Seafile with the wget command, and extract the downloaded archive.

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

Rename the directory to 'seafile-server' and switch to that directory.

mv seafile-server-6.0.5 seafile-server
cd seafile-server/

Execute the 'setup-seafile-mysql.sh' file to configure the database.

./setup-seafile-mysql.sh

Press Enter and you will be asked for information below:

  • server name - I will use the server hostname 'natsume'
  • server's ip or domain - ip address of the server, in my case '192.168.1.115'
  • default data dirctory - just press Enter
  • default port - press Enter
  • Now for the database configuration, choose number 2

For the MySQL configuration:

  • use deafult host - localhost
  • default port - 3306
  • the mysql user - 'seacloud'
  • and the password is 'yourpassword'
  • ccnet database is 'ccnet_db'
  • seafile database is 'seafile_db'
  • seahub database is 'seahub_db'

Press enter and the script will create the database tables for the seafile.

002.png

Now we can start the seafile and seahub services.

./seafile.sh start
./seahub.sh start

When the seahub.sh file is executed, we will be asked for the admin configuration.

Type in your admin email and password, then the seahub service will runing.

003.png

Seafile is installed and running now, we can access Seafile from a web browser with the server IP on port 8000 (in my case - 192.168.1.115:8000), but we will not do it now because we will use a reverse proxy for the seafile server and we will run seafile with a systemd service file.

So we need to stop seafile and seahub service for now.

./seafile.sh stop
./seahub.sh stop

Step 5 - Configure Seafile and Seahub Service

We will run seafile as nginx user, so we need to change the owner of seafile installation directory and seahub_cache directory to nginx user:

cd /var/www/
chown -R nginx:nginx *
chown -R nginx:nginx /tmp/seahub_cache

Next, go to the systemd directory and create a seafile.service file with vim:

cd /etc/systemd/system/
vim seafile.service

Paste seafile service configuration below:

[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</pre>

Save and exit.

Now create new seahub.service file.

vim seahub.service

And paste configuration below.

[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</pre>

Save and exit.

Reload the systemd service and start seafile and seahub with systemctl.

systemctl daemon-reload
systemctl start seafile
systemctl start seahub

Make sure there is no error and check that the seafile and seahub service is running on port 8082 and 8000.

netstat -plntu
004.png

Step 6 - Generate SSL Certificate Files

For this tutorial, we will run seafile over a Nginx proxy, and Nginx will provide secure (HTTPS) connections for data security. We can use a free SSL certificate file or the paid SSL certificate, this does not matter for the configuration. In this step, I will generate a self-signed SSL certificate file with the OpenSSL in the '/etc/nginx/ssl' directory.

Create the ssl directory.

mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl

Generate self signed certificate files and a dhparam file with command below:

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

Answer the certificate details as requested by OpenSSL like your name, state, email, domain name etc. Then change the permissions of the directory and certificate files.

chmod -R 700 /etc/nginx/ssl
chmod 400 server.*
chmod 400 dhparam.pem

The SSL certificate files have been generated.

Step 7 - Configure Nginx as Reverse Proxy

In this step, we will configure Nginx as a reverse proxy for the seafile-server on port 8000 and 8002.

Go to the nginx configuration directory and create a new virtual host file for seafile.

cd /etc/nginx/
vim conf.d/seafile.conf

Paste virtual host configuration below:

server {  
        listen        80;
        server_name   cloud.natsume.co;
        return 301  https://$host$request_uri;
}

server {  
    listen 443 ssl;
    server_name cloud.natsume.co;
    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;
    }

}

Save and exit.

I will use use 'cloud.natsume.co' as the domain name. Please replace that with your own domain name in the config above.

Now test the Nginx configuration and make sure that there are no errors.

nginx -t

Start Nginx with the systemctl command:

systemctl start nginx

Make sure port 80 and 443 are available in the list that netstat provides:

netstat -plntu
005.png

Next, we have to add the domain name to the seafile configuration. Go to the seafile directory and edit the configuration file.

cd /var/www/seafile/
vim conf/ccnet.conf

Change the service URL to your domain name.

SERVICE_URL = https://cloud.natsume.co

Save and exit.

Edit the seahub configuration file.

vim conf/seahub_settings.py

On the second line, add configuration below:

HTTP_SERVER_ROOT = 'https://cloud.natsume.co/seafhttp'

Replace the domain name with your domain here again. Save and exit.

Restart seafile and add all services to start at boot time:

systemctl restart seafile
systemctl restart seahub

systemctl enable nginx
systemctl enable mariadb
systemctl enable seafile
systemctl enable seahub

Step 8 - Configure FirewallD

In step 7, we've configured Nginx to use the HTTP and HTTPS port. Now we have to open that ports in the Firewall by adding them to firewalld.

Start firewalld.

systemctl start firewalld
systemctl enable firewalld

Add HTTP and HTTPS port to the firewall configuration with the firewall-cmd command below:

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent

Reload the firewall configuration and check the port list.

firewall-cmd --reload
firewall-cmd --list-all
006.png

Step 9 - Testing Seafile

Open your browser, type the seafile domain name, in my case cloud.natsume.co and you will be redirected to the https connection.

Type your admin email and password and click 'Log in'.

007.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末魂莫,一起剝皮案震驚了整個(gè)濱河市雀摘,隨后出現(xiàn)的幾起案子换棚,更是在濱河造成了極大的恐慌蹭劈,老刑警劉巖妥曲,帶你破解...
    沈念sama閱讀 216,496評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件棺亭,死亡現(xiàn)場(chǎng)離奇詭異当悔,居然都是意外死亡蚓曼,警方通過(guò)查閱死者的電腦和手機(jī)绩聘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)沥割,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人凿菩,你說(shuō)我怎么就攤上這事机杜。” “怎么了衅谷?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,632評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵椒拗,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我,道長(zhǎng)蚀苛,這世上最難降的妖魔是什么在验? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,180評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮堵未,結(jié)果婚禮上腋舌,老公的妹妹穿的比我還像新娘。我一直安慰自己渗蟹,他們只是感情好块饺,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,198評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著拙徽,像睡著了一般刨沦。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上膘怕,一...
    開(kāi)封第一講書(shū)人閱讀 51,165評(píng)論 1 299
  • 那天想诅,我揣著相機(jī)與錄音,去河邊找鬼岛心。 笑死来破,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的忘古。 我是一名探鬼主播徘禁,決...
    沈念sama閱讀 40,052評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼髓堪!你這毒婦竟也來(lái)了送朱?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,910評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤干旁,失蹤者是張志新(化名)和其女友劉穎驶沼,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體争群,經(jīng)...
    沈念sama閱讀 45,324評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡回怜,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,542評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了换薄。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片玉雾。...
    茶點(diǎn)故事閱讀 39,711評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖轻要,靈堂內(nèi)的尸體忽然破棺而出复旬,到底是詐尸還是另有隱情,我是刑警寧澤冲泥,帶...
    沈念sama閱讀 35,424評(píng)論 5 343
  • 正文 年R本政府宣布赢底,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏幸冻。R本人自食惡果不足惜粹庞,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,017評(píng)論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望洽损。 院中可真熱鬧庞溜,春花似錦、人聲如沸碑定。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,668評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)延刘。三九已至,卻和暖如春碘赖,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背播掷。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,823評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留撼班,地道東北人歧匈。 一個(gè)月前我還...
    沈念sama閱讀 47,722評(píng)論 2 368
  • 正文 我出身青樓砰嘁,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親矮湘。 傳聞我的和親對(duì)象是個(gè)殘疾皇子斟冕,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,611評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,322評(píng)論 0 10
  • 夜色一點(diǎn)一點(diǎn)沉浸,悲愴與蒼涼一起冗長(zhǎng)板祝。聽(tīng)花開(kāi)花落走净,夢(mèng)燈火闌珊券时,紅塵落滿惆悵伏伯。 風(fēng)倦倦無(wú)力,纏綿昔日溫柔...
    金永輝煌閱讀 850評(píng)論 15 12
  • 碧玉妝成一樹(shù)高炸枣, 白果纏枝把秋報(bào), 忽如一夜西風(fēng)至适肠, 繽紛金麟更妖嬈。
    清風(fēng)8351閱讀 485評(píng)論 1 3