1. 程式人生 > >如何基於滴滴雲構建更私密的企業/個人網盤空間Seafile

如何基於滴滴雲構建更私密的企業/個人網盤空間Seafile

Seafile 介紹

Seafile 是一個開源的檔案雲端儲存平臺,解決檔案集中儲存、同步、多平臺訪問的問題,注重安全和效能。

Seafile 通過“資料庫”來分類管理檔案,每個資料庫可單獨同步,使用者可加密資料庫, 且密碼不會儲存在伺服器端,所以即使是伺服器管理員也無權訪問你的檔案。

Seafile 允許使用者建立“群組”,在群組內共享和同步檔案,方便了團隊協同工作。

如何基於滴滴雲來搭建Seafile

目前滴滴雲提供的伺服器和SSD儲存盤價格低,產品操作易用,且通過了多項資訊保安認證,資料可靠性很高。

準備工作

  • 1臺滴滴雲DC2伺服器,1個彈性IP地址
  • 作業系統:Linux CentOS7.4
  • 規格:2CPU 4GB記憶體 40GBSSD系統盤
  • 頻寬:5M
  • 1臺雲資料庫Mysql(可選,也可以自建Mysql)
  • 1臺雲盤EBS
  • 規格:50GB
  • 配置:SSD雲盤
  • 掛載的雲伺服器:選擇之前準備的伺服器主機名
  • 在安全組規則中,新增8000和8012埠允許訪問策略

當一切準備就緒,我們就可以按照下面的操作步驟開始搭建Seafile了。

安裝過程

Step 1:Seafile目錄設計和軟體下載

首先,在滴滴雲伺服器上對安裝軟體的目錄和資料存放的空間進行規劃,確保所有的軟體程式和檔案資料,都有序的存放在伺服器上,方便後期的維護。另外,下載最新版本的Seafile Server安裝包到目錄上。

首先,使用使用者名稱dc2-user登陸到你的滴滴雲伺服器

$ ssh [email protected]

切換到root使用者,併為root使用者設定登陸密碼

$ sudo su
# passwd

使用mkdir建立一個起名為Seafile的資料夾,用於存放所有Seafile的配置檔案和資料檔案

# mkdir seafile

在Seafile資料夾中,使用wget命令下載最新的seafile server版安裝包

# cd seafile
# wget http://seafile-downloads.oss-cn-shanghai.aliyuncs.com/seafile-server_6.3.3_x86-64.tar.gz

使用tar命令將軟體包解壓

# tar -xzf seafile-server_6.3.3_x86-64.tar.gz

Step 2:安裝Seafile前的軟體依賴環境檢查

安裝Seafile伺服器之前,請確認以下軟體已經安裝在了作業系統中,滴滴雲DC2伺服器上預設已經配置好了yum源,可以通過yum的相關命令直接檢視軟體的安裝情況或直接進行安裝,併為安裝好的Mysql設定密碼,以便後續建立Seafile資料庫使用。

  • MariaDB 或者 MySQL 伺服器 (或者使用滴滴雲提供的Mysql產品)
  • python 2.7 (從 Seafile 5.1 開始,python 版本最低要求為2.7)
  • python-setuptools
  • python-mysqldb
  • python-ldap
  • python-urllib3
  • python-memcache (或者 python-memcached)

使用rpm命令,檢視軟體包的安裝情況

# rpm -qa mysql python python-setuptools python-mysqldb python-ldap python-urllib3 python-memcache
python-setuptools-0.9.8-7.el7.noarch
python-2.7.5-58.el7.x86_64
python-urllib3-1.10.2-3.el7.noarch

接下來,使用yum命令,安裝還未安裝的系統軟體包

# yum -y install mariadb mariadb-server python-ldap python-memcached MySQL-python

啟動Mariadb資料庫,並驗證3306埠啟用情況

# service mariadb start
# netstat -tulpn | grep 3306
tcp 0  0 0.0.0.0:3306  0.0.0.0:*  LISTEN  12879/mysqld    

使用命令mysql_secure_installation,為Mariadb進行初始化配置,併為root設定密碼

# mysql_secure_installation #除了密碼設定,其餘選項可以直接輸入y通過

Step 3:安裝Seafile

這一步,開始安裝Seafile軟體包,在安裝的過程中,指令碼會依次詢問一些伺服器的配置問題,從而引導你完成整個配置過程,如果上面步驟的軟體包沒有安裝完成,Seafile初始化指令碼會提醒你進行安裝。

執行安裝指令碼並回答預設問題

# cd seafile-server-6.3.3/
# ./setup-seafile-mysql.sh
What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] didiyun #輸入伺服器名稱

What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] 116.85.10.39 #輸入滴滴雲伺服器的EIP公網地址

Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/root/seafile/seafile-data" ] #直接回車

Which port do you want to use for the seafile fileserver?
[ default "8082" ] #直接回車
-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------

[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases
#如果選擇1,你需要提供根密碼.指令碼程式會建立資料庫和使用者。
#如果選擇2,使用已經存在的ccnet/seafile/seahub資料庫檔案。

我們選擇1,建立新的資料庫和使用者

[ 1 or 2 ] 1

What is the host of mysql server?
[ default "localhost" ] #直接回車

What is the port of mysql server?
[ default "3306" ] #直接回車

What is the password of the mysql root user?
[ root password ] #輸入之前設定的root密碼

密碼驗證完成後,進入到對於Seafile使用者的資訊配置

Enter the name for mysql user of seafile. It would be created if not exists.
[ default "seafile" ] #直接回車

Enter the password for mysql user "seafile":
[ password for seafile ] #設定seafile使用者密碼

Enter the database name for ccnet-server:
[ default "ccnet-db" ] #直接回車

Enter the database name for seafile-server:
[ default "seafile-db" ] #直接回車

Enter the database name for seahub:
[ default "seahub-db" ] #直接回車

Seafile使用者資訊配置完成後,如果你正常的安裝了Seafile,你將得到如下的輸出

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

Step 4:啟動Seafile伺服器

在 seafile-server-latest 目錄下,執行如下命令啟動Seafile伺服器

  • 啟動Seafile
# ./seafile.sh start
  • 啟動Seahub
# ./seahub.sh start
  • 在第一次啟動Seahub時,seahub.sh指令碼會提示您建立一個Seafile管理員賬號
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 ] 

服務啟動後,開啟瀏覽器並輸入以下地址,你就會被重定向到登陸頁面,輸入管理員使用者名稱和密碼,即可登入。

http://116.85.10.39:8000/   #IP地址為您個人的伺服器IP

恭喜 您的Seafile已經安裝成功!您可以登入到Seafile中任意上傳或者下載您所需要的檔案,一個私密的個人網盤,就搭建完成了。

更優化、更安全的檔案儲存方式

在Seafile安裝完成後,通常情況下,我們會建議把系統盤和資料盤做分離,由於Seafile的功能主要是用於儲存檔案,所以可以將存放檔案的seafile-data目錄,單獨掛載一塊大容量的SSD雲盤,方便對資料目錄做統一的備份和管理。

在滴滴雲購買的EBS雲盤,在控制檯可以直接掛載到DC2伺服器上,完成掛載的操作,就可以直接通過lsblk的命令顯示出來

# lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    253:0    0  40G  0 disk 
└─vda1 253:1    0  40G  0 part /
vdb    253:16   0  50G  0 disk 
  • 首先我們使用fdisk命令,對資料盤vdb進行磁碟分割槽
# fdisk /dev/vdb

分割槽過程不做贅述,具體可以訪問滴滴雲官網的連線檢視
https://help.didiyun.com/hc/kb/article/1121818/

  • 使用mkfs.xfs命令,將已經分割槽的磁碟進行格式化
# mkfs.xfs /dev/vdb1
  • 將磁碟掛載到seafile-data目錄之前,先將seafile-data目錄中已經存在的檔案轉移到另外的資料夾中,做臨時中轉
# mkdir /root/backup
# mv /root/seafile/seafile-data/* /root/backup/
  • 使用mount命令,將已經格式化好的資料盤掛載到/root/seafile/seafile-data/下,注意需要加入讀寫許可權
# mount -rw /dev/vdb1 /root/seafile/seafile-data/
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G  2.1G   38G   6% /
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G   17M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs           380M     0  380M   0% /run/user/1001
/dev/vdb1        50G   33M   50G   1% /root/seafile/seafile-data
  • 掛載完成後,將seafile-data之前移出的檔案轉回seafile-data資料夾
# mv /root/backup/* /root/seafile/seafile-data/

到此,您已經具備了一個私密性和可靠性極高的Seafile網盤空間

本文作者:宋佩