Linux 上部署 Seafile 9.0.x 专业版(Seafile Server端)——踩一路坑,溅一身水
1. Seafile 簡介
Seafile 是一款開源的企業云盤,注重可靠性和性能。支持 Windows, Mac, Linux, iOS, Android 平臺。支持文件同步或者直接掛載到本地訪問。Seafile 主要注重的是文件安全工作,寫一個基本的文件同步工具是件簡單的事情,但是要保證在各種極端的場合下都能正確的工作、不丟數據是件不容易的事情。Seafile 專注文件同步的可靠性。同步算法經過 3 年的不斷改進和數十萬用戶的使用,已經非常可靠。Seafile 的文件歷史和資料庫鏡像機制保證了文件可隨時方便的恢復到任意歷史狀態。
其擁有如下特點:
-
可靠的文件同步
文件組織成資料庫。每個資料庫可選擇性的同步到任意設備。可靠高效的文件同步將提高您的工作效率。 -
掛載盤客戶端
直接通過本地 S 盤來訪問云端文件,不占用本地存儲。為電腦提供服務器的海量存儲空間。同操作系統無縫集成,還可以離線修改文件。 -
團隊協作
可以共享文件到群組。權限管理、版本控制、事件通知讓協作更為流暢。 -
高性能
Seafile 服務器內核由 C 語言編寫。運行起來小巧快速。 -
Wiki 與知識管理
融合 Wiki 與網盤的功能,使用 Markdown 格式以所見即所得方式編輯 Wiki 文檔,提供搜索、標簽、評審等知識管理功能,支持對外發布 Wiki 內容。 -
適用于企業環境
可與 AD/LDAP 集成??赏?AD 群組和用戶信息。
來看看官網給的一張示例圖片,和我們正常使用的網盤基本沒什么區別。
官方的介紹文檔:Seafile 簡介
2. Seafile pro Server 下載鏈接
官方下載連接:
Linux 服務器端開源版: Seafile 9.0.5 64bit
Linux 服務器端專業版: Seafile 專業版
其它的支持平臺:Seafile
筆者的當前環境:
OS: Ubuntu server 22.04
選擇的 Seafile Server 專業版本: Seafile pro 9.0.5 64bit
3. 一些安裝前的準備工作
3.1. 安裝依賴
適合 Seafile 9.0.x 版本
imaginemiracle:~$ sudo apt-get updateimaginemiracle:~$ sudo apt-get install -y python3 python3-setuptools python3-pip python3-ldap libmysqlclient-dev imaginemiracle:~$ sudo apt-get install -y memcached libmemcached-dev安裝過程中可能會彈出一個選項框,問你 “哪個服務需要被重新安裝呢?”,你回答 “不!”,就可以了,我們不需要重新安裝之前裝過的服務。
注意,由于依賴項較多,因此下面這行命令非常的長,務必復制完整!!!
接下來根據每個人的網絡情況,如果網絡像筆者一樣不好的朋友就要等稍微久一點的時間了(╮(╯▽╰)╭😔)。(老實說我等了很久,大概有個兩千年吧~)
[注]: Seafile Pro 9.0.x 版本不支持在 Centos 系統 tar 包部署,支持 Docker 方式部署 。
3.1.1. 可能出現的錯誤
安裝過程中有可能會出現各種各樣的錯誤,這里筆者將自己遇到的問題也整理下來供大家參考。
在每次遇到問題的時候我都會這樣想,也會這樣做:
并不會所有人都會遇到問題,
而所有人也不會都出現同樣的問題。
但只要每個人將自己的解決過程分享出來,
那么我相信,
所有人的問題都會迎刃而解。🥰
互相幫助,將會使我們進步的更快!
問題(1). fatal error: libmemcached/memcached.h: No such file or directory
x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE_ZLIB -I/usr/include/python3.10 -c src/_pylibmcmodule.c -o build/temp.linux-x86_64-3.10/src/_pylibmcmodule.o -fno-strict-aliasing -std=c99In file included from src/_pylibmcmodule.c:34:src/_pylibmcmodule.h:42:10: fatal error: libmemcached/memcached.h: No such file or directory42 | #include <libmemcached/memcached.h>| ^~~~~~~~~~~~~~~~~~~~~~~~~~compilation terminated.error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1[end of output]note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure× Encountered error while trying to install package. ╰─> pylibmcnote: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.解決(1)
imaginemiracle:~$ sudo apt-get install libmemcached-dev zlib1g-dev問題(2). fatal error: ffi.h: No such file or directory
x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.10 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.10/c/_cffi_backend.oc/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory15 | #include <ffi.h>| ^~~~~~~compilation terminated.error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1[end of output]note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure× Encountered error while trying to install package. ╰─> cffinote: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.解決(2)
imaginemiracle:~$ sudo apt-get install libffi-dev問題(3). 出現有關 c/_cffi_backend.c 源文件報錯
c/_cffi_backend.c: In function ‘ctypedescr_dealloc’:c/_cffi_backend.c:407:23: error: lvalue required as left operand of assignment407 | Py_REFCNT(ct) = 43;| ^c/_cffi_backend.c:410:23: error: lvalue required as left operand of assignment410 | Py_REFCNT(ct) = 0;| ^c/_cffi_backend.c: In function ‘prepare_callback_info_tuple’:c/_cffi_backend.c:6185:5: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]6185 | PyEval_InitThreads();| ^~~~~~~~~~~~~~~~~~In file included from /usr/include/python3.10/Python.h:130,from c/_cffi_backend.c:2:/usr/include/python3.10/ceval.h:122:37: note: declared here122 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);| ^~~~~~~~~~~~~~~~~~c/_cffi_backend.c: In function ‘b_callback’:c/_cffi_backend.c:6245:5: warning: ‘ffi_prep_closure’ is deprecated: use ffi_prep_closure_loc instead [-Wdeprecated-declarations]6245 | if (ffi_prep_closure(closure, &cif_descr->cif,| ^~In file included from c/_cffi_backend.c:15:/usr/include/x86_64-linux-gnu/ffi.h:347:1: note: declared here347 | ffi_prep_closure (ffi_closure*,| ^~~~~~~~~~~~~~~~error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1[end of output]假的解決(3) 這里耍了小聰明
以下被劃掉的部分為筆者初次解決該錯誤的方法,但這種方法導致了后面出現了嚴重而尷尬的問題,此處展示僅供讀者欣(cháo)賞(fěng)🤣😂😇🥳
對于該問題找了好久,但并沒有解決,因此筆者試著搜了一下 cffi 這個東西。
從當前的官網來看,cffi 目前最新版本號為 1.15.0,而我們使用 pip 下載時候寫的是 cffi==1.14.0,看到這里嘗試將上文那串下載命令后面的版本號更改為 1.15.0再重新下載,問題解決,因此筆者這里猜測應該是新版本與舊版本不兼容導致報錯的。
來吧看看筆者這自以為是的解決方法會導致什么問題。
在一切安裝配置結束后,發現 seafile 的網站運行不起來。
使用 ./seahub.sh start-fastcgi 可以看到更細節的錯誤原因。
seafile:seafile-server-latest$ ./seahub.sh start-fastcgiLC_ALL is not set in ENV, set to en_US.UTF-8 Starting seahub (fastcgi) at 127.0.0.1:8000 ... Traceback (most recent call last): ----------------------------snip-------------------------------- ----------------------------snip--------------------------------File "/usr/local/seafile-pro-server/seafile-pro-server-9.0.5/seahub/thirdpart/cffi/api.py", line 54, in __init__raise Exception("Version mismatch: this is the 'cffi' package version %s, located in %r. When we import the top-level '_cffi_backend' extension module, we get version %s, located in %r. The two versions should be equal; check your installation." % ( Exception: Version mismatch: this is the 'cffi' package version 1.14.0, located in '/usr/local/seafile-pro-server/seafile-pro-server-9.0.5/seahub/thirdpart/cffi/api.py'. When we import the top-level '_cffi_backend' extension module, we get version 1.15.0, located in '/usr/local/lib/python3.10/dist-packages/_cffi_backend.cpython-310-x86_64-linux-gnu.so'. The two versions should be equal; check your installation. Error:Seahub failed to start.這里省略掉無關緊要的輸出,直接看錯誤原因,程序說,他應該要的是 cffi 1.14.0 版本,而卻拿到的是 cffi 1.15.0,純屬找茬是不。這誰能想到這玩意竟然指定版本的,唉😔。
真的解決(3)
這里我們把 cffi 1.14.0 和 cffi 1.15.0 源碼包下載下來,用源碼方式安裝。稍后會解釋為什么要下載兩個。
堅持做免積分的CSDN下載鏈接:cffi 1.14.0 & cffi 1.15.0
git下載: cffi 1.14.0、cffi 1.15.0
cffi 官方下載鏈接: cffi 1.14.0、cffi 1.15.0
這里我們在終端直接下載并解壓
imaginemiracle:Downloads$ git clone https://gitcode.net/imagine-miracle/cffi.git imaginemiracle:Downloads$ cd cffi imaginemiracle:cffi$ ls cffi-1.14.0.tar.gz cffi-1.15.0.tar.gz README.md imaginemiracle:cffi$ tar -xf cffi-1.14.0.tar.gz imaginemiracle:cffi$ tar -xf cffi-1.15.0.tar.gz imaginemiracle:cffi$ ls cffi-1.14.0 cffi-1.14.0.tar.gz cffi-1.15.0 cffi-1.15.0.tar.gz README.md進入 cffi-1.14.0 目錄
imaginemiracle:cffi$ cd cffi-1.14.0/ imaginemiracle:cffi-1.14.0$ ls AUTHORS cffi demo LICENSE PKG-INFO setup_base.py setup.py c cffi.egg-info doc MANIFEST.in README.md setup.cfg testing安裝 python 插件 cffi
imaginemiracle:cffi-1.14.0$ sudo python3 setup.py install輸出如下
---------------------------snip---------------------------------- ---------------------------snip---------------------------------- c/_cffi_backend.c: In function ‘ctypedescr_dealloc’: c/_cffi_backend.c:407:23: error: lvalue required as left operand of assignment407 | Py_REFCNT(ct) = 43;| ^ c/_cffi_backend.c:410:23: error: lvalue required as left operand of assignment410 | Py_REFCNT(ct) = 0;| ^ c/_cffi_backend.c: In function ‘prepare_callback_info_tuple’: c/_cffi_backend.c:6185:5: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]6185 | PyEval_InitThreads();| ^~~~~~~~~~~~~~~~~~ In file included from /usr/include/python3.10/Python.h:130,from c/_cffi_backend.c:2: /usr/include/python3.10/ceval.h:122:37: note: declared here122 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);| ^~~~~~~~~~~~~~~~~~ c/_cffi_backend.c: In function ‘b_callback’: c/_cffi_backend.c:6245:5: warning: ‘ffi_prep_closure’ is deprecated: use ffi_prep_closure_loc instead [-Wdeprecated-declarations]6245 | if (ffi_prep_closure(closure, &cif_descr->cif,| ^~ In file included from c/_cffi_backend.c:15: /usr/include/x86_64-linux-gnu/ffi.h:347:1: note: declared here347 | ffi_prep_closure (ffi_closure*,| ^~~~~~~~~~~~~~~~ error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1這里可以看到出現的錯誤,和我們用 pip3 安裝時候報錯一樣,都是在 c/_cffi_backend.c 文件中出錯,說我們運算符用錯了這個那個的,筆者這里也偷懶一下。
c/_cffi_backend.c: In function ‘ctypedescr_dealloc’:c/_cffi_backend.c:407:23: error: lvalue required as left operand of assignment407 | Py_REFCNT(ct) = 43;| ^c/_cffi_backend.c:410:23: error: lvalue required as left operand of assignment410 | Py_REFCNT(ct) = 0;|我們打開 cffi 1.14.0 里的 _cffi_backend.c 文件,并鎖定到出錯行。可以看到報錯是由 ctypedescr_dealloc 函數引起。
// # File: cffi 1.14.0/c/_cffi_backend.c ##------## ctypedescr_dealloc() static void ctypedescr_dealloc(CTypeDescrObject *ct) {PyObject_GC_UnTrack(ct);if (ct->ct_weakreflist != NULL)PyObject_ClearWeakRefs((PyObject *) ct);if (ct->ct_unique_key != NULL) {/* revive dead object temporarily for DelItem */Py_REFCNT(ct) = 43;PyDict_DelItem(unique_cache, ct->ct_unique_key);assert(Py_REFCNT(ct) == 42);Py_REFCNT(ct) = 0;Py_DECREF(ct->ct_unique_key);}Py_XDECREF(ct->ct_itemdescr);Py_XDECREF(ct->ct_stuff);if (ct->ct_flags & CT_FUNCTIONPTR)PyObject_Free(ct->ct_extra);Py_TYPE(ct)->tp_free((PyObject *)ct); }這里我們對比 cffi 1.15.0 中的 _cffi_backend.c 文件,同樣找到 ctypedescr_dealloc 函數位置。可以看到在 1.15.0 版本中已經修復了這個問題,使用的是新的賦值調用 Py_SET_REFCNT(ct, 43);
static void ctypedescr_dealloc(CTypeDescrObject *ct) {PyObject_GC_UnTrack(ct);if (ct->ct_weakreflist != NULL)PyObject_ClearWeakRefs((PyObject *) ct);if (ct->ct_unique_key != NULL) {/* revive dead object temporarily for DelItem */Py_SET_REFCNT(ct, 43);PyDict_DelItem(unique_cache, ct->ct_unique_key);assert(Py_REFCNT(ct) == 42);Py_SET_REFCNT(ct, 0);Py_DECREF(ct->ct_unique_key);}Py_XDECREF(ct->ct_itemdescr);Py_XDECREF(ct->ct_stuff);if (ct->ct_flags & CT_FUNCTIONPTR)PyObject_Free(ct->ct_extra);Py_TYPE(ct)->tp_free((PyObject *)ct); }這里我們也不深追代碼了,使用最簡單的方法——“文件替換”,我們將用 cffi 1.15.0 中的 _cffi_backend.c 文件替換掉 cffi 1.14.0 中的 _cffi_backend.c 文件。
imaginemiracle:cffi-1.14.0$ cp ../cffi-1.15.0/c/_cffi_backend.c ./c/接下來,重新執行安裝命令,這個時候就會發現我們已經成功安裝好了 cffi-1.14.0。
imaginemiracle:cffi-1.14.0$ sudo python3 setup.py install ----------------------------snip--------------------------------- Installed /usr/local/lib/python3.10/dist-packages/cffi-1.14.0-py3.10-linux-x86_64.egg Processing dependencies for cffi==1.14.0 Searching for pycparser==2.21 Best match: pycparser 2.21 Adding pycparser 2.21 to easy-install.pth fileUsing /usr/local/lib/python3.10/dist-packages Finished processing dependencies for cffi==1.14.03.2. 安裝 MySQL
3.2.1. 使用 apt 安裝 mysql-server
若不提前安裝 MySQL 后面在設置創建數據庫時則會失敗!
imaginemiracle:~$ sudo apt-get update imaginemiracle:~$ sudo apt-get install mysql-server imaginemiracle:~$ sudo systemctl start mysql.service3.2.2. 查看是否安裝成功
使用 netstat 命令查看 MySQL 的 socket 是否為 listen 監聽狀態。若顯示 LISTEN 則說明安裝成功。
imaginemiracle:~$ netstat -tag | gerp mysql tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN查看 mysql.service 服務狀態,看是否在運行狀態。
imaginemiracle:~$ sudo systemctl status mysql.service ● mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2022-06-20 05:54:15 UTC; 15min agoMain PID: 29399 (mysqld)Status: "Server is operational"Tasks: 39 (limit: 19069)Memory: 361.5MCPU: 2.610sCGroup: /system.slice/mysql.service└─29399 /usr/sbin/mysqldJun 20 05:54:14 imaginemiracle-linux systemd[1]: Starting MySQL Community Server... Jun 20 05:54:15 imaginemiracle-linux systemd[1]: Started MySQL Community Server.3.2.3. 配置 MySQL
使用 mysql_secure_installation 對 MySQL 初始化。
使用該命令,會對你提出幾個問題讓你回答:
| 是否安裝密碼校驗插件 VALIDATE PASSWORD COMPONENT | no |
| 請為 root 管理員賬戶設置數據庫密碼 | 我是強壯的密碼(這里需要自己設置哦!) |
| 刪除匿名賬戶嗎 | yes |
| 是否禁止root管理員從遠程登錄 | no |
| 是否刪除test數據庫并取消對它的訪問權限 | yes |
| 是否刷新授權表,讓初始化的設定立即生效 | yes |
執行 MySQL 配置腳本
imaginemiracle:~$ sudo mysql_secure_installation第一個提示將詢問你是否要設置驗證密碼插件,該插件可用于在認為新用戶有效之前測試新 MySQL 用戶的密碼強度。
如果你選擇設置驗證密碼插件,則創建的任何使用密碼進行身份驗證的 MySQL 用戶都需要具有滿足選擇的策略的密碼,所以選擇 No ,便可以使用簡單的密碼。
Securing the MySQL server deployment.Connecting to MySQL using a blank password.VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component?Press y|Y for Yes, any other key for No: YThere are three levels of password validation policy:LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2無論是否選擇設置驗證密碼插件,下一個提示都是為 MySQL root 用戶設置密碼。輸入并確認你設置的密碼:
Please set the password for root here.New password:Re-enter new password:如果第一個問題選擇使用了驗證密碼插件,則將收到有關新密碼強度的反饋。然后腳本將詢問你是要繼續使用剛剛輸入的密碼還是要輸入新密碼。若對剛剛輸入的密碼強度感到滿意,則輸入 Y 以繼續執行腳本:
Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y后續將會繼續詢問,是否需要刪除匿名用戶、禁用 root 用戶遠程登錄和 是否刪除 test 數據庫,是否確認現在重新加載權限表?,分別回答 Y、N、Y、Y 便可。
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : yes 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? (Press y|Y for Yes, any other key for No) : no... skipping. By default, MySQL 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? (Press y|Y for Yes, any other key for No) : yes- 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? (Press y|Y for Yes, any other key for No) : yes Success.All done!3.2.4. 修改 MySQL root 用戶為 mysql_native_password 驗證方式
以 root 用戶登錄 MySQL
imaginemiracle:~$ sudo mysql -u root -p使用 ALTER USER 語句修改用戶信息。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'imaginemiracle'; Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)mysql> exit Bye3.2.5. 可能發生的意外(Error: SET PASSWORD has no significance for user ‘root’@‘localhost’)
有的小伙伴可能在第一次使用登錄時,看到下面提示了 Enter password,并沒有使用回車跳過輸入,而是習慣性的輸入了本機 root 用戶的密碼。
imaginemiracle:~$ sudo mysql -u root -p Enter password: # 未設置的情況下這里可以直接使用 “回車” 跳過事實上如果這個時候輸入的話,則會導致后面使用 mysql_secure_installation 設置 root 密碼失敗。你將會看到這樣的提示。
… Failed! Error: SET PASSWORD has no significance for user ‘root’@‘localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.這個時候也莫需慌張,先直接退出設置,用下面命令重新連接數據庫。
imaginemiracle:~$ sudo mysql這個時候可能需要你輸入剛才輸入過的密碼,也就是你機器的 root 密碼。
進入 sql 命令行后,輸入下面命令,并敲回車,則可以將你的密碼改成 imaginemiracle。(這里設置的密碼根據自己需要替換即可)
這個時候 exit 到終端下,再對 MySQL 重新進行設置,對于前兩個問題直接輸入 no 即可。
imaginemiracle:~$ sudo mysql_secure_installation3.3. 安裝 Java 運行環境
Java 運行時環境 (JRE) 是使用 elasticsearch 進行全文搜索的要求。
執行下面任意一組命令即可:
(1) Debian 10
(2) Ubuntu 16.04/18.04/20.04/22.04
imaginemiracle:~$ sudo apt-get install openjdk-8-jre -y imaginemiracle:~$ sudo ln -sf /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java /usr/bin/(3) CentOS
imaginemiracle:~$ sudo yum install java-1.8.0-openjdk -y3.4. 安裝 poppler-utils
pdf 文件的全文搜索需要包 poppler-utils。
執行下面任意一組命令即可:
(1) Ubuntu/Debian
(2) CentOS
imaginemiracle:~$ sudo yum install poppler-utils -y3.5. 創建安裝目錄
在 /usr/local 目錄下創建 seafile-pro-server/installed(可以自定義命名),由于是在根目錄下 / 創建目錄,因此這里需要超級權限,或者可以直接切換到 root 用戶進行操作。
imaginemiracle:~$ sudo mkdir -p /usr/local/seafile-pro-server/installed3.6. 創建 seafile 用戶
一般來說不要直接使用 root 用戶來運行程序,這里新建一個 seafile 用戶。
使用 adduser 命令創建用戶,并根據屏幕輸出提示設置密碼等其它用戶相關信息。
將在 /usr/local 下剛創建的目錄所有權更改為新用戶 seafile。
imaginemiracle:~$ sudo chown -R seafile: /usr/local/seafile-pro-server給 seafile 用戶授予 sudo 權限。
imaginemiracle:~$ sudo usermod -aG sudo seafile切換到 seafile 用戶
imaginemiracle:~$ su seafile3.7. 下載并解壓 Seafile 安裝包
進入 installed 目錄。
seafile:~$ cd /usr/local/seafile-pro-server/installed下載 seafile pro server。
seafile:installed$ wget https://download.seafile.com/seafhttp/files/7338d67f-3a22-4243-bfe6-99632f01ca63/seafile-pro-server_9.0.5_x86-64_Ubuntu.tar.gz使用 tar 解壓 seafile 壓縮包。
seafile:installed$ tar -zxvf seafile-pro-server_9.0.5_x86-64_Ubuntu.tar.gz -C /usr/local/seafile-pro-server/進入解壓后的目錄:
seafile:installed$ cd /usr/local/seafile-pro-server/seafile-pro-server-9.0.5/創建好的目錄結構大概是這樣的
seafile:seafile-pro-server-9.0.5$ tree /usr/local/seafile-pro-server/ -L 2 /usr/local/seafile-pro-server/ ├── installed │ └── seafile-pro-server_9.0.5_x86-64_Ubuntu.tar.gz └── seafile-pro-server-9.0.5├── check-db-type.py├── check_init_admin.py├── index_op.py├── migrate.py├── migrate-repo.py├── migrate-repo.sh├── migrate.sh├── pro├── remove-objs.py├── remove-objs.sh├── reset-admin.sh├── run_index_master.sh├── run_index_worker.sh├── runtime├── seaf-backup-cmd.py├── seaf-backup-cmd.sh├── seaf-encrypt.sh├── seaf-fsck.sh├── seaf-fuse.sh├── seaf-gc.sh├── seafile├── seafile-background-tasks.sh├── seafile.sh├── seaf-import.sh├── seahub├── seahub.sh├── setup-seafile-mysql.py├── setup-seafile-mysql.sh├── setup-seafile.sh├── sql└── upgrade8 directories, 26 files這樣構建目錄的好處在于:
- 與 seafile 相關配置文件都可以放在 /usr/local/seafile-pro-server/conf 目錄下,便于集中管理;
- 后續升級時,只需要解壓最新的安裝包到 /usr/local/seafile-pro-server 目錄下即可。
4. 開始部署 Seafile 服務器
正常流程的話,我們的當前目錄應該是:
seafile:seafile-pro-server-9.0.5$ pwd /usr/local/seafile-pro-server/seafile-pro-server-9.0.5如果不在 seafile 解壓后的目錄的話,請移步到此目錄,該目錄的文件大概像下面這樣:
seafile:seafile-pro-server-9.0.5$ ls check-db-type.py migrate.sh run_index_worker.sh seaf-fuse.sh seahub upgrade check_init_admin.py pro runtime seaf-gc.sh seahub.sh index_op.py remove-objs.py seaf-backup-cmd.py seafile setup-seafile-mysql.py migrate.py remove-objs.sh seaf-backup-cmd.sh seafile-background-tasks.sh setup-seafile-mysql.sh migrate-repo.py reset-admin.sh seaf-encrypt.sh seafile.sh setup-seafile.sh migrate-repo.sh run_index_master.sh seaf-fsck.sh seaf-import.sh sql4.1. 執行安裝腳本
在安裝目錄下有一個 setup-seafile-mysql.sh 這個文件,運行它。正常情況下它會依次開始詢問一些配置問題,并引導你來安裝它,雖然再上文有寫過安裝 Java 環境(那是后來補上的),但由于筆者剛開始沒有安裝,因此它會提示我來安裝,如果你的系統也缺少的話,那么它也會提示你的,按照提示安裝即可。
seafile:seafile-pro-server-9.0.5$ ./setup-seafile-mysql.sh Checking python on this machine ...Checking for java ... Java is not found. install it first.On Debian/Ubuntu: apt-get install default-jre On CentOS/RHEL: yum install jreError occured during setup. Please fix possible problems and run the script again.看起來是我的系統里沒有 Java 的運行環境,安裝它。
seafile:seafile-pro-server-9.0.5$ sudo apt-get install default-jre -y安裝完畢后,重新執行安裝腳本。
[注]:不是 root 的你記得要加 sudo 哦。
初始化腳本會檢查是否滿足安裝條件,條件滿足后,按回車即可繼續安裝。下面會依次詢問你一些問題,從而引導使用者安裝并配置 Seafile,不輸入直接敲回車則表示使用默認配置。
4.1.1. 設置服務器名稱
命名要求:由 3-15 個字符,只允許英文字母、數字和下劃線(‘_’),不可少也不可多。
4.1.2. 設置服務器 ip 或域名
如果本機使用的是公網 IP 的話并且綁定了域名,那么就可以使用域名來設置,之后便可以通過域名來訪問云盤了。
如果沒有的話,這里設置本機 IP 即可。
4.1.3. 設置端口號
使用哪個端口訪問,這里可以自定義端口,也可以使用默認端口。(在默認端口未被占用時,建議使用默認端口)
4.1.4. 選擇數據庫構建方式
這里提供兩個選項:
[1] 創建新的數據庫 ccnet/seafile/seahub,選擇該項則提供 root 密碼,腳本程序會自動為你創建好數據庫和用戶;
[2] 使用已有數據庫 ccnet/seafile/seahub,選擇該項則說明已經存在創建好的數據庫,否則請選擇 [1]。
選擇“ [1]創建新的 ccnet/seafile/seahub 數據庫”時,該腳本會創建這些數據庫,并且 Seafile Server 將使用Seafile Server 訪問它們的 MySQL 用戶。你將需要回答以下問題:
| mysql 服務器主機 | MySQL 服務器的主機地址 | 默認是本地主機 | 本機 IP |
| mysql 服務器端口 | MySQL 服務器使用的 TCP 端口 | 默認端口為 3306。幾乎每個 MySQL 服務器都使用這個端口 | 聽她的 |
| mysql root 密碼 | MySQL root 賬戶的密碼 | 創建新數據庫和 MySQL 用戶需要 root 密碼 | 給她你 root 密碼 |
| Seafile 的 mysql 用戶 | 由腳本創建的 MySQL 用戶,Seafile 的組件使用它來訪問數據庫 | 默認為seafile;除非用戶存在,否則創建用戶 | 我們早建好了 |
| Seafile 用戶的 mysql 密碼 | 上面用戶的密碼,寫在 Seafile 的配置文件中 | 不允許使用百分號 (‘%’) | 我們也設好了 |
| 數據庫名稱 | ccnet使用的數據庫名稱 | 默認為“ccnet-db”,如果數據庫不存在則創建 | \ |
| seafile 數據庫名稱 | Seafile 使用的數據庫名稱 | 默認為“seafile-db”,如果數據庫不存在則創建 | \ |
| seahub 數據庫名稱 | seahub 使用的數據庫名稱 | 默認為“seahub-db”,如果數據庫不存在則創建 | \ |
| mysql服務器主機 | MySQL服務器的主機地址 | 默認是本地主機 | 本機 IP |
| mysql服務器端口 | MySQL 服務器使用的 TCP 端口 | 默認端口為 3306;幾乎每個 MySQL 服務器都使用這個端口 | 聽她的 |
| Seafile 的 mysql 用戶 | Seafile 組件用來訪問數據庫的用戶 | 用戶必須存在 | \ |
| Seafile 用戶的 mysql 密碼 | 上面用戶的密碼 | \ | \ |
| ccnet 數據庫名稱 | ccnet使用的數據庫名稱,默認為“ccnet-db” | 數據庫必須存在 | \ |
| seafile 數據庫名稱 | Seafile 使用的數據庫名稱,默認為“seafile-db” | 數據庫必須存在 | \ |
| seahub 數據庫名稱 | Seahub 使用的數據庫名稱,默認為“seahub-db” | 數據庫必須存在 | \ |
來看看實際情況,初次安裝都會選擇 [1] 選項。此時則會詢問你如下問題:
(1) 設置數據庫地址
這里可以使用默認,也可以自定義設置。
(2) 設置可連接主機
這里的默認為 %,該通配符代表允許用戶賬戶從任何主機都可以連接。一般情況使用默認就好。
(3) 設置數據庫端口號
沒有特殊情況,使用默認即可。
(4) 輸入數據庫 root 用戶的密碼
4.1.5. 創建 MySQL seafile 用戶
按上文操作的話,我們已經創建好了系統的 seafile 用戶,這里會為我們創建 MySQL seafile 用戶,這里會要求我們設置 MySQL seafile 用戶的密碼。
4.1.6. 創建數據庫
創建數據庫 ccnet-db、seafile-db、seahub-db,這三個數據庫直接使用默認設置即可,這里輸入三次回車即可。(若此處并無權限操作,請看后面手動創建數據庫過程)
4.1.7. 確認設置
確認設置的信息沒問題直接輸入回車,將會自動為我們安裝好 seafile。
4.1.8. 確認完成
若安裝完成將會出現如下輸出。
此時的目錄布局如下:
該文件夾 seafile-server-latest 是指向當前 Seafile Server 文件夾的符號鏈接。當您稍后升級到新版本時,升級腳本會更新此鏈接以指向最新的 Seafile Server 文件夾。
5. 設置 MySQL
以 root 用戶登錄數據庫。
imaginemiracle:~$ sudo mysql -u root -p創建 mtsql seafile 用戶,imaginemiracle 則為 seafile 用戶登錄 mysql 的密碼。
mysql> create user 'seafile'@'localhost' identified by 'imaginemiracle';將用戶 seafile 的身份驗證插件更改為 mysql_native_password:
mysql> ALTER USER 'seafile'@'localhost' identified with mysql_native_password by 'imaginemiracle';手動創建數據庫 ccnet、seafile、seahub(已使用腳本成功創建數據庫的讀者無需執行)
mysql> create database `ccnet_db` character set = 'utf8';mysql> create database `seafile_db` character set = 'utf8';mysql> create database `seahub_db` character set = 'utf8';賦予 seafile 用戶這三個數據庫的訪問權限。(已使用腳本成功創建數據庫的讀者無需執行)
mysql> GRANT ALL PRIVILEGES ON `ccnet_db`.* to `seafile`@localhost;mysql> GRANT ALL PRIVILEGES ON `seafile_db`.* to `seafile`@localhost;mysql> GRANT ALL PRIVILEGES ON `seahub_db`.* to `seafile`@localhost;刷新權限表。
mysql> FLUSH PRIVILEGES;退出 mysql
mysql> exit6. 調整 conf 文件
由安裝腳本創建的 Seafile 配置文件是為在反向代理后面運行的 Seafile 準備的。
要訪問 Seafile 的 Web 界面并在沒有反向代理的情況下創建工作共享鏈接,需要修改以下兩個配置文件 /usr/local/seafile-pro-server/conf:
- seahub_settings.py(適用于 9.0.x): 將端口 8000 添加到 SERVICE_URL(即 SERVICE_URL = http://11.22.33.44:8000/);
[注]:此處的 ip 地址僅作為示例。 - ccnet.conf(適用于 8.0.x 或 7.1.x): 將端口 8000 添加到 SERVICE_URL(即 SERVICE_URL = http://11.22.33.44:8000/)。
- gunicorn.conf.py: 將綁定更改為 "0.0.0.0:8000"(即 bind = “0.0.0.0:8000”)。
7. 啟動 Seafile 服務器
進入 /usr/local/seafile-pro-server/seafile-server-latest 目錄。
seafile:~$ cd /usr/local/seafile-pro-server/seafile-server-latest使用啟動如下兩個腳本。
seafile:seafile-server-latest$ ./seafile.sh start # 啟動 Seafile 服務 seafile:seafile-server-latest$ ./seahub.sh start # 啟動 seahub 網站,默認端口為 127.0.0.1:8000第一次啟動 Seahub 時,腳本會提示您為 Seafile 服務器創建一個管理員帳戶。輸入管理員用戶的電子郵件地址和密碼。
當輸入完你的 seafile 賬戶后,則會提示啟動完成。
7.1. 可能出現的錯誤(Failed to connect to MySQL: Plugin caching_sha2_password could not be loaded)
執行完 seafile.sh start 命令后,有可能會出現如下錯誤。
seafile:seafile-server-latest$ ./seafile.sh start** Message: 06:43:27.575: seafile-controller.c(1023): loading seafdav config from /usr/local/seafile-pro-server/conf/seafdav.conf2022-06-21 06:43:27 ../common/seaf-utils.c(409): Use database Mysql 2022-06-21 06:43:27 http-server.c(236): fileserver: worker_threads = 102022-06-21 06:43:27 http-server.c(249): fileserver: backlog = 32 2022-06-21 06:43:27 http-server.c(264): fileserver: fixed_block_size = 8388608 2022-06-21 06:43:27 http-server.c(279): fileserver: web_token_expire_time = 3600 2022-06-21 06:43:27 http-server.c(294): fileserver: max_indexing_threads = 1 2022-06-21 06:43:27 http-server.c(309): fileserver: max_index_processing_threads= 3 2022-06-21 06:43:27 http-server.c(331): fileserver: cluster_shared_temp_file_mode = 600 2022-06-21 06:43:27 http-server.c(409): fileserver: enable_async_indexing = 0 2022-06-21 06:43:27 http-server.c(421): fileserver: async_indexing_threshold = 700 2022-06-21 06:43:27 http-server.c(433): fileserver: fs_id_list_request_timeout = 300 2022-06-21 06:43:27 http-server.c(446): fileserver: max_sync_file_count = 100000 2022-06-21 06:43:27 http-server.c(461): fileserver: put_head_commit_request_timeout = 10 2022-06-21 06:43:27 ../common/license.c(709): License file /usr/local/seafile-pro-server/seafile-license.txt does not exist, allow at most 3 trial users License file /usr/local/seafile-pro-server/seafile-license.txt does not exist, allow at most 3 trial users 2022-06-21 06:43:27 ../common/seaf-db.c(739): Failed to connect to MySQL: Plugin caching_sha2_password could not be loaded: /usr/lib/mariadb/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory 2022-06-21 06:43:27 ../common/user-mgr.c(97): Failed to get user number from DB. 2022-06-21 06:43:27 seafile-session.c(422): Failed to init user manager. failed to run "seaf-server -t" [65280]該錯誤是 seafile 無法被驗證從而無法連接到數據庫,解決方法如下。
以 root 用戶登錄到 MySQL。
將 seafile 用戶的驗證插件修改為 mysql_native_password:
mysql> ALTER USER 'seafile'@'127.0.0.1' identified with mysql_native_password by 'imaginemiracle';7.2. 這里沒找到你的錯誤???
執行 seafile.sh 文件時一般會輸出詳細的錯誤信息,根據錯誤信息查詢解決方法即可。
而啟動 seahub.sh 是不會給出特別詳細的錯誤信息,這個時候使用如下命令啟動,可以查看更詳細的信息,根據錯誤信息來查詢相應解決方法即可。
8. 訪問 Seafile 云盤服務器
當完全成功通過上文配置后,此時你將可以在內網下通過主機地址和端口 8000(例如 http://11.22.33.44:8000)的 Web 界面訪問 Seafile。
但這個時候在內網的主機也只能通過 IP: Port 的形式訪問網頁,并不能做上傳/下載的操作,只能在本機上上傳/下載,這完全不符合我們的要求,最起碼可以在內網下的主機都可以上傳下載才行。
9. 配置內網(局域網)下上傳/下載
9.1. 修改 MySQL 服務的配置
打開 mysql 的配置文件。
imaginemiracle:~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf找到 bind-address = 127.0.0.1 和 mysqlx-bind-address = 127.0.0.1,將這兩行注釋掉,即在這兩行最前面加上 # 即可。
重啟 mysql.service。
9.2. 修改 MySQL 的 seafile 用戶設置
以 root 用戶登錄 mysql。
imaginemiracle:~$ sudo mysql -u root -p選擇 user 表。
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase change查看 user 表,可以看到 seafile 用戶目前只能通過 localhost 也就是本機的 127.0.0.1 來訪問數據庫,由于目前 seahub 是通過 localhost:8082 上傳和下載文件,這也就是為什么不能在其它主機上上傳和下載的原因。
mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | debian-sys-maint | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | | seafile | localhost | +------------------+-----------+ 6 rows in set (0.00 sec)因此我們需要修改 seafile 用戶的訪問地址,使其可以通過本機的網絡 IP 訪問數據庫,同時刷新權限表。這里使用通用符 % 來表示該用戶可以通過任何途徑訪問數據庫;
mysql> update user set host='%' where user='seafile'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | seafile | % | | debian-sys-maint | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 6 rows in set (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)修改 seafile 用戶信息(修改為可以通過任何途徑連接數據庫,即可通過域名訪問或主機 IP 連接數據庫,同時修改 seafile 用戶的驗證插件為 mysql_native_password),同時刷新權限表。
mysql> ALTER USER 'seafile'@'%' IDENTIFIED WITH mysql_native_password by 'imaginemiracle'; Query OK, 0 rows affected (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)9.3. 修改 seafile 可通過域名或 主機IP 訪問 ccnet、seafile、seahub 數據庫
修改 seafile 訪問數據庫的方式,同時刷新權限表。
mysql> GRANT ALL PRIVILEGES ON `ccnet_db`.* to `seafile`@'%'; Query OK, 0 rows affected (0.00 sec)mysql> GRANT ALL PRIVILEGES ON `seafile_db`.* to `seafile`@'%'; Query OK, 0 rows affected (0.00 sec)mysql> GRANT ALL PRIVILEGES ON `seahub_db`.* to `seafile`@'%'; Query OK, 0 rows affected (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)MySQL 配置完成,退出 mysql。
mysql> exit Bye重啟 mysql.service。
imaginemiracle:~$ sudo systemctl restart mysql.service9.4. 修改 seafile pro server 配置
進入 seafile 服務器的配置目錄。
seafile:~$ cd /usr/local/seafile-pro-server/conf seafile:conf$ ls ccnet.conf gunicorn.conf.py __pycache__ seafdav.conf seafevents.conf seafile.conf seahub_settings.py(1). 打開 ccnet.conf 文件,將其中 HOST = 127.0.0.1 修改為 HOST = www.imaginemiracle.com;
(2). 打開 seafevents.conf 文件,其中 host = 127.0.0.1 修改為 host = www.imaginemiracle.com;
(3). 打開 seafile.conf 文件,其中 host = 127.0.0.1 修改為 host = www.imaginemiracle.com;
(4). 打開 seahub_settings.py 文件,其中 ‘HOST’ : ‘127.0.0.1’ 修改為 ‘HOST’ : ‘www.imaginemiracle.com’;
[注]:以上僅以 www.imaginemiracle.com 作為示例使用,具體應根據實際情況修改為正確域名或本機 IP。
9.5. 重啟 seafile 服務
進入 seafile 安裝目錄。
seafile:~$ cd /usr/local/seafile-pro-server/seafile-server-latest重啟服務。
seafile:seafile-server-latest$ ./seafile.sh start seafile:seafile-server-latest$ ./seahub.sh start9.6. 設置 seafile 網頁的文件服務地址
使用 IP:Prot 進入 seafile 網址的系統設置。(默認設置下的端口應該是 8000)
修改 FILE_SERVER_ROOT 的地址為 http://host ip:port。默認設置這里的端口為 8082,可以通過查看 conf/seafile.conf 文件獲取修改配置后的文件服務端口。
[注]:http://11.22.33.44:8082 僅作為示例,請根據實際情況修改。
10. 啟用 Https(可選——但建議)
將服務器通過加密的 Https 訪問代替現在的從未加密的 Http 訪問。
10.1. 安裝 Nginx
適用于 Debian/Ubuntu
imaginemiracle:~$ sudo apt install nginx -y適用于 CentOS
imaginemiracle:~$ sudo yum install nginx -y安裝成功后,啟動它,并開啟隨系統開機啟動。
適用于 CentOS/Debian/Ubuntu
10.2. 準備工作
適用于 Debian/Ubuntu
在以下位置為 seafile 創建一個配置文件 /etc/nginx/sites-available/:
/etc/nginx/sites-enabled/ 刪除和中的默認文件 /etc/nginx/sites-available:
imaginemiracle:~$ sudo rm /etc/nginx/sites-enabled/default imaginemiracle:~$ sudo rm /etc/nginx/sites-available/default創建符號鏈接:
imaginemiracle:~$ sudo ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf適用于 CentOS
將 SELinux 切換到許可模式并保持設置:
在以下位置為 seafile 創建一個配置文件 /etc/nginx/conf.d:
imaginemiracle:~$ touch /etc/nginx/conf.d/seafile.conf10.3. 配置 Nginx
將以下內容復制到剛創建好的 seafile.conf 文件中,并對以下內容做一些修改。
log_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time';server {listen 80;server_name imaginemiracle.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 Serverclient_max_body_size 10000m;access_log /var/log/nginx/seahub.access.log seafileformat;error_log /var/log/nginx/seahub.error.log;}# If you are using [FastCGI](http://en.wikipedia.org/wiki/FastCGI), # which is not recommended, you should use the following config for location `/`. # # 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; # fastcgi_read_timeout 36000; # # 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 10000m;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_connect_timeout 36000s;proxy_read_timeout 36000s;proxy_send_timeout 36000s;send_timeout 36000s;access_log /var/log/nginx/seafhttp.access.log seafileformat;error_log /var/log/nginx/seafhttp.error.log;}location /media {root /usr/local/seafile-pro-server/seafile-server-latest/seahub;} }- 修改 server_name(必須):
該項的默認值為 "imaginemiracle.com",這里若有域名則修改為域名,無可用域名則修改為本機 IP 即可。 - location /media(必須):
該項描述的是 seafile 的資源目錄,筆者已經在上面提供的配置文件中做出修改,根據本文安裝的讀者可以不用再次修改,安裝在其他目錄的讀者需根據自己安裝的目錄自行修改即可。 - 服務器監聽端口 listen(可選):
若希望配置的 seafile 服務器運行在非標準端口上則修改即可。 - location /::proxy_pass(可選):
如果 Seahub 配置為在不同于 8000 的端口上啟動。 - ** location /seafhttp::proxy_pass(可選):**
如果 seaf-server 配置為在不同于 8082 的端口上啟動。 - 請求正文的最大允許大小 client_max_body_size(可選):
本文給出的默認值為 1000m,表示 Nginx 可支持的請求實體最大為 1GB,可根據實際情況調節。Seahub 的默認值為 1M,上傳較大文件將導致錯誤消息 HTTP 錯誤代碼 413(“請求實體太大”)。建議將 client_max_body_size 的值與 conf/seafile.conf 中 max_upload_size 部分 [fileserver] 中的參數同步。
為所有用戶設置默認配額(例如 2GB)。為此,只需將以下行添加到 conf/seafile.conf 文件中。
[quota] # default user quota in GB, integer only default = 210.4. 為 443 端口添加服務塊(沒有域名的小伙伴可以忽略此小節)
若有域名的小伙伴可以暫停,先看 11 小節內容,完了再回來繼續。。
為端口 443 添加一個服務器塊,并將 http-to-https 重定向 seafile.conf 到 /etc/nginx。
編輯 /etc/nginx/sites-available/seafile.conf 文件。
log_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time';server {listen 80;server_name www.imaginemiracle.com;rewrite ^ https://$http_host$request_uri? permanent; # Forced redirect from HTTP to HTTPSserver_tokens off; # Prevents the Nginx version from being displayed in the HTTP response header }server {listen 443;ssl on;ssl_certificate /etc/letsencrypt/live/www.imaginemiracle.com/fullchain.pem; # Path to your fullchain.pemssl_certificate_key /etc/letsencrypt/live/www.imaginemiracle.com/privkey.pem; # Path to your privkey.pemserver_name www.imaginemiracle.com;server_tokens off;# HSTS for protection against man-in-the-middle-attacks# 啟用 HTTP 嚴格傳輸安全 (HSTS) 以防止中間人攻擊add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";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;# proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Proto https;# used for view/edit office file via Office Online Serverclient_max_body_size 0; ... # No changes beyond this point compared to the Nginx configuration without HTTPS以上是筆者修改部分的全部內容,是文件的部分內容,大家根據對比該內容,并根據實際情況修改相應內容。
10.5. 重啟 Ngnix
確保您的 seafile.conf 不包含語法錯誤并重新啟動 Nginx 以使配置更改生效。
imaginemiracle:~$ sudo nginx -t imaginemiracle:~$ sudo nginx -s reload10.6. 修改 seahub_settings.py
修改 seahub_settings.py 文件中的 SERVICE_URL = “https://11.22.33.44:8000/”,修改為 SERVICE_URL = “https://www.imaginemiracle.com/”。
重啟 seafile 服務。
刪除防火墻的 8000 的入站規則。
seafile:seafile-server-latest$ firewall-cmd --permanent --remove-port=8000/tcp systemctl reload firewalld.service10.7. 修改 seafile.conf 并重啟 seafile 服務
為了提高安全性,文件服務器應該只能通過 Nginx 訪問。
修改 conf/seafile.conf 文件,在 [fileserver] 塊下添加如內容:
更新之后,文件服務器只接受來自 Nginx 的請求。
重啟 Seafile 服務。
10.8. 驗證
使用域名 www.imaginemiracle.com 或 IP 訪問 seafile 網頁,查看網頁的管理設置,就會發現這里已經變為 https 的開頭了。
沒有域名的讀者需要在此處將 FILE_SERVER_ROOT 的值設置為 “http://[host ip]:[port]/seafhttp”
有域名并且根據 11 章節完成 SSL 配置后可將 FILE_SERVER_ROOT 的值設置為 “https://[your domain]/seafhttp”
11. 獲取 Let’s Encrypt 證書 (沒有域名的小伙伴請忽略此章節)
Certbot 讓獲得 Let's Encrypt 證書如此簡單。Certbot 是一個免費的開源軟件工具,用于請求、接收和更新 Let's Encrypt 證書。
11.1 進入 Cerbot 官網
訪問 Cerbot官網 選擇所部署的網絡服務器和操作系統類型。
11.2. 根據提示操作
根據官網提示一步步操作即可。雖然筆者也將具體步驟寫下來了。
11.3. 與官網同樣的步驟——多余的憂心
原諒筆者出于對大家不信任的擔心,這里還是寫下根據官網說明的具體步驟吧。
一般情況下,若使用的是近幾年發行版的 Linux,那么其本身已經預裝過 snapd 了,不過我們也可以再安裝一次,反正無所謂。
11.4. 安裝 snapd
imaginemiracle:~$ sudo apt-get update imaginemiracle:~$ sudo apt-get install snap11.5. 更新 snapd
執行如下命令來確保使用的 snapd 是最新版,若如下輸出則說明已經是最新版。
imaginemiracle:~$ sudo snap install core; sudo snap refresh core snap "core" is already installed, see 'snap help refresh' snap "core" has no updates available可能出現的問題(憂心關鍵點):
當執行更新命令時,也有可能是得到如下錯誤輸出。
那么此時檢查 snapd.service 服務是否開啟。一般這種情況是該服務未打開導致。
imaginemiracle:~$ sudo systemctl status snapd.service ○ snapd.service - Snap DaemonLoaded: loaded (/lib/systemd/system/snapd.service; enabled; vendor preset: enabled)Active: inactive (dead) TriggeredBy: ○ snapd.socket如上顯示的狀態是 “未活動”,那么將其打開即可。
imaginemiracle:~$ sudo systemctl start snapd.service開啟服務后再次執行更新命令便可成功運行。
imaginemiracle:~$ sudo snap install core; sudo snap refresh core11.6. 刪除 cerbot 包
安裝 Cerbot snap 之前需要將之前任意類型的 Cerbot 包卸載掉。
適用于 Debian/Ubuntu:
適用于 CentOS:
imaginemiracle:~$ sudo yum remove certbot適用于 Fedora:
imaginemiracle:~$ sudo dnf remove certbot11.7. 安裝 Cerbot
適用于 Debian/Ubuntu/CentOS/Fedora:
imaginemiracle:~$ sudo snap install --classic certbot在機器上的命令行執行以下指令,保證 certbot 命令可以運行。
imaginemiracle:~$ sudo ln -s /snap/bin/certbot /usr/bin/certbot11.8. 獲取證書
根據官網建議,只獲得一個證書并自己修改 Nginx 配置。
imaginemiracle:~$ sudo certbot certonly --nginx按照屏幕提示操作即可。驗證成功后,Certbot 會將證書文件保存在以主機名命名的目錄中 /etc/letsencrypt/live。對于主機名 www.imaginemiracle.com,文件存儲在/ etc/letsencrypt/live/www.imaginemiracle.com。
[注]:這里的 www.imaginemiracle.com,僅作為示例。
11.9. 啟用 Nginx 的 SSL 模塊 (可選)
如果你的 Nginx 不支持 SSL,你需要重新編譯它。使用以下命令。
imaginemiracle:~$ sudo ./configure --with-http_stub_status_module --with-http_ssl_module imaginemiracle:~$ sudo make && make install12. 開啟 WebDav
12.1. 修改 seafdav.conf 文件
在 seafile 的部署目錄下的 conf 目錄創建或為已有的 seafdav.conf 配置文件添加入內容。
[注]:若以本文的指導此目錄應該為 /usr/local/seafile-pro-server/conf/seafdav.conf
12.2. 修改 nginx 配置文件
若以本文指導安裝的 Nginx,其配置文件目錄應該為 /etc/nginx/sites-available/seafile.conf,其它伙伴可以根據自己的安裝目錄自行匹配。
為配置文件添加如下內容:
12.3. 重啟 Nginx 和 Seafile 服務
重新加載 Nginx 配置
sudo nginx -s reload重啟 Seafile
./seafile.sh restart ./seafhub.sh restart12.4. 驗證
Windwos 端:
可通過瀏覽器使用以配置的域名或 ip 訪問,訪問方式:
也可使用 Windows 資源管理器連接,但該方式僅支持非加密 HTTP 連接。因此,為了安全,唯一可行的選擇是使用第三方客戶端,例如 Cyber??duck 或 Bitkinex。
Linux 端:
在 Linux 上,有更多選擇??梢允褂?Nautilus 等文件管理器連接到 webdav 服務器。
也可在終端命令行中使用 davfs2 打開。
在連接沒有任何報錯后,則會正常的看到 mount 到的目錄下有了網盤上的內容。
使用 sudo umount /media/seafdav 可取消掛載。
建議禁用 davfs2 的 LOCK 操作。編輯 /etc/davfs2/davfs2.conf
13. 開啟郵件服務
修改 seahub_settings.py 在其中添加如下內容:
EMAIL_USE_TLS = True EMAIL_HOST = 'smtp-mail.outlook.com' # smpt server EMAIL_HOST_USER = 'imaginemiracle.wxn@outlook.com' # username and domain EMAIL_HOST_PASSWORD = '*******************' # password EMAIL_PORT = 587 DEFAULT_FROM_EMAIL = EMAIL_HOST_USER SERVER_EMAIL = EMAIL_HOST_USER這里的 EMAIL_HOST_PASSWORD 項需要填寫你的使用郵箱的密碼,為了保護隱私,筆者這里使用 * 代替??梢钥吹焦P者使用的郵件服務器是 smtp-mail.outlook.com,他的指定端口是 587,若大家使用的是其它郵件服務器的話,對應的端口有可能不同,可以在網絡上檢索一下對應的服務器。
這里設置好后們需要開啟對應端口的防火墻,然后重啟 seafile 即可。
14. 日常維護(數據備份)
在服務器端,Seafile 是通過一種內部格式將文件存儲在資料庫中,并對于文件和目錄有其獨有的保存方式(類似于 Git)。默認安裝下,這些內部對象,會被直接存儲在服務器的文件系統中(例如 Ext4,NTFS)。文件在服務器上通過分塊存儲,以支持大文件的斷點續傳和增量同步。
在服務器端可以使用 seaf-fuse.sh 直接將所有目錄掛載到本地目錄下,以普通目錄樹的方式訪問和備份,需要注意的是,此方法掛載的目錄只具有讀權限,即不可以直接修改目錄文件,只可備份。(加密文件不可使用此方法訪問)
進入 seafile 安裝目錄,若如按照本文安裝,則進入下面目錄即可。
seafile:~$ cd /usr/local/seafile-pro-server/seafile-server-latest seafile:seafile-server-latest$ ls check-db-type.py pro seaf-backup-cmd.py seafile-background-tasks.sh setup-seafile.sh check_init_admin.py remove-objs.py seaf-backup-cmd.sh seafile.sh sql index_op.py remove-objs.sh seaf-encrypt.sh seaf-import.sh start-seafile.sh migrate.py reset-admin.sh seaf-fsck.sh seahub tmp.log migrate-repo.py run_index_master.sh seaf-fuse.sh seahub.sh upgrade migrate-repo.sh run_index_worker.sh seaf-gc.sh setup-seafile-mysql.py migrate.sh runtime seafile setup-seafile-mysql.sh使用 seaf-fuse.sh 將所有文件掛載到本地目錄。
# 命令格式 ./seaf-fuse.sh start <path> seafile:seafile-server-latest$ ./seaf-fuse.sh start ~/drive-data/Starting seaf-fuse, please wait ... seaf-fuse startedDone.這個時候進入掛載的目標目錄即可看到對應的所有用戶目錄。
卸載目錄命令。
seafile:seafile-server-latest$ ./seaf-fuse.sh stop14.1 如果出現 “Permission denied” 的錯誤
如果你運行 ./seaf-fuse.sh start 時,遇到 "Permission denied" 的錯誤信息, 很有可能你沒有在 “fuse用戶組” 解決方法:
(1) 把你的用戶加到 fuse 組
sudo usermod -a -G fuse(2) 退出 shell 重新登陸
(3) 現在試著再一次執行 ./seaf-fuse.sh start <path>
#15. 常見問題
以 # 開頭的章節代表的是該部分內容不能算是正文部分,此部分內容為附加章節,一般用于提供針對文章中常常會出現的問題的一些解決辦法,或者分享筆者的一些啰嗦文字,以及對于參考的文章發出的感謝等內容。
#15.1. 無法上傳/下載文件
通過以上的所有配置后,發現仍無法訪問 Web 網址或無法上傳/下載文件。那么需要做的事情有兩點。
(1). 確認防火墻是否開放了設置的端口,若未開放則放開這幾個端口;(默認的幾個需要放開的端口 8000、8082、3306)
防火墻設置命令參考:
(2). 檢查 seahub_settings.py 中的 SERVICE_URL 設置和 seafile 網頁中的 FILE_SERVER_ROOT 設置。
#15.2. 網頁中用戶頭像顯示異常
(1). 進入 seafile 的安裝目錄
若是按照本文的安裝步驟安裝,則目錄位于 /usr/local/seafile-pro-server/seafile-server-latest/seahub/seahub/avatar/templatetags
若非本安裝教程安裝,則按此提示進入,/自己的安裝目錄/seafile-server-latest/seahub/seahub/avatar/templatetags
(2). 編輯 avatar_tags.py 文件
(3). 修改如下兩部分
- return service_url + url, False, date_uploaded 修改為 return url, False, date_uploaded;
- return service_url + get_default_avatar_url(), True, None 修改為 return get_default_avatar_url(), True, None。
[注]:即刪掉 return 語句中的 service_url + 即可。
@cache_result def api_avatar_url(user, size=AVATAR_DEFAULT_SIZE):service_url = get_service_url()service_url = service_url.rstrip('/')# when store avatars in the media directoryif not AVATAR_FILE_STORAGE:# urlparse('https://192.157.12.3:89/demo')# ParseResult(scheme='https', netloc='192.157.12.3:89', path='/demo', params='', query='', fragment='')parse_result = urlparse(service_url)service_url = '%s://%s' % (parse_result[0], parse_result[1])avatar = get_primary_avatar(user, size=size)if avatar:url = avatar.avatar_url(size)date_uploaded = avatar.date_uploaded# /media/avatars/6/9/5011f01afac2a506b9544c5ce21a0a/resized/32/109af9901c0fd38ab39d018f5cd4baf6.png# 修改前# return service_url + url, False, date_uploaded# 修改后return url, False, date_uploadedelse:# /media/avatars/default.png# 修改前# return service_url + get_default_avatar_url(), True, None# 修改后return get_default_avatar_url(), True, None(4). 刪除系統緩存
imaginemiracle:~$ sudo rm -rf /tmp/seahub_cache/*(5). 重啟 Seafile 服務
seafile:seafile-server-latest$ ./seafile.sh restart # 啟動 Seafile 服務 seafile:seafile-server-latest$ ./seahub.sh restart#15.3. 文件夾上傳數量限制
默認的單次上傳文件夾數量為 1000。
如果這個數量也不能滿足你的話,那么打開 conf/seahub_settings.py 文件,并添加或修改項 MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD = 100000,修改并保存后,再重啟 seafile 服務即可。
此時刷新 web 端,再次上傳大數量文件夾則不會限制。
!0. “!” 說明
以 ! 開頭的章節代表著此章節具有一定的 “危險性”(從各方面而言),更多的是提供給讀者用來學習參考。本文示例僅供學習使用,還請各位讀者切勿將所學技術于商業用途以及其它非法用途。本文里 ! 章節試圖去突破 Seafile 對于部署無 lincense 文件的服務器存在人數限制最大免費注冊用戶數量為 3 個。
!1. Seafile 的 Python 部分
首先通過對 seafile 文件的大致分析,其網頁端是使用 django 框架由 Python 語言開發,而后端程序是由 C 實現的。
那么先看其 Python 部分代碼,通過搜查有關 license 的文件。找到了前端檢測 MaxUsers 用戶最大數的部分代碼,此段代碼會影響用戶的登錄、注冊等功能。
修改 ./seahub/seahub/utils/licenseparse.py 文件中的 MaxUsers,能改多大就改多大。
!2. C 部分
再看 C 部分,通過 IDA 軟件可以去查看二進制文件,并將其反編譯為匯編代碼,若覺得匯編代碼還不好看的話,還可以進一步將其反編譯為 C 的偽代碼形式,說是偽代碼,其實已經和真實的代碼差不多了。
[注]:這里所說的偽代碼,實際上這類代碼有一個準確的名稱叫做——中間代碼形式。
經過對 seafile.sh 啟動腳本的分析,找到了啟動時會執行的幾個二進制文件,并將其逐一使用 IDA 打開查看,查找有關 license 部分的代碼,最終被定位到一個具體的二進制文件里。
此處為了一定程度上保護 Seafile 不被破解濫用,就不在這里說明具體的 文件 位置了。畢竟也是國產軟件,支持國產!
通過找到對應二進制文件的 main 函數開始閱讀代碼,很快就找到了于之相關的判斷。
其檢測部分的函數調用結構很簡單。如下:
簡單分析以下這里的判斷,首先我們已經可以明確兩點:
- 第一,這個函數就是 License 的檢查函數;
- 第二,這個函數會返回一個值用來判斷 License 是否檢測成功,若返回值小于 0 則表示不成功程序會直接退出。
查看 sub_9DE30(__int64 a1, unsigned int a2, time_t **a3, _DWORD *a4) 函數的定義。
if ( !(unsigned int)g_file_test(v7, 16LL) ){if ( a4 )*a4 = 3; // Address: 0009DE9Cg_log(0LL,16LL,"%s(%d): License file %s does not exist, allow at most %d trial users\n","../common/license.c",709LL,v7,3LL); // Address: 0009DEC8v8 = 0;__fprintf_chk(stdout, 1LL, "License file %s does not exist, allow at most %d trial users\n", v7, 3LL); // Address: 0009DEDBg_free(v7);goto LABEL_6;}很明顯的找到了判斷無 license 文件時的情況,可以看到這里有一個關鍵變量被賦值為 3,那么這個變量就是用來顯示用戶數量的關鍵點。雖然我們只用修改 a4 變量賦值的那一個地方既可,但為了更加明顯的判斷我們的修改是否有效,這里我們將出現的兩次打印中的 3 也修改一下。
轉回到匯編代碼,使用二進制修改,這樣不容易出問題。建議不要嘗試使用其它方式修改,很容易導致崩潰無法運行。具體做法:
修改:edit > Patch program > Change byte…
保存:edit > Patch program > Apply aptches to input file…
這里由于第二個地方的變量長度只有 8 位,因此只能修改成最大整數 127,其余兩個修改為 0x1F40 十進制的值為 8000。那么按照想法來說修改完后的用戶上限應該為 8000。
修改完并保存后再反編譯為 C 語言再來查看,可以檢查是否修改成功以及是否影響其它代碼。事實證明這樣修改是沒有問題的,也不會影響到其它地方的代碼。
這段代碼最后有一條 goto 跳轉語句千萬不能忽視。goto LABEL_6;,我們看看 LABEL_6 是怎么寫的。
可以看出該函數最終的返回值為 result,該值會在返回之前使用 v8 變量的值對其賦值,雖然我們直接在二進制中不容易修改變量名為整數值,但我們可以做的是將 v8 可能會被賦值為負值的地方改為正數即可,這樣為了保證不讓 main 函數退出而繼續執行下去。也不用全部看只需要修改 LABEL_89 之后的所有便可。
LABEL_89 標簽后一共存在四次對 v8 變量的賦值。如下圖:
(1)&(2) v8 = -1;
(3) v8 = -1;
(4) v8 = -1;
四處的語句是一樣的,因此在匯編中看到的也是一樣的,這里只展示其中一個,將其修改為 0 或者任意大于 0 的數均可。
對文件的修改已經完成,現在重啟 seafile 服務測試。
成功啟動就表示著已經突破完成。我們現在已經成功將沒有 license 的試用人數改為 8000 個用戶,與預期結果一樣,不用管上面顯示的 127,為什么呢?
還記得在修改變量值的時候,那個 127 只是一行輸出,是個無關緊要的值,無需關心它即可,重點只用看后面有無輸出,同時查看網頁端能否新加用戶。
這里筆者已經測試了,現在已經可以任意的添加用戶而不受限制。
!3. 再次聲明
請杜絕傳播破解軟件!
本文內容僅供學習,請勿用于商業用途以及其它非法用途。若按照本文教程學習并成功破解的讀者,請保護網絡環境和軟件環境,請勿以任意途徑分享破解文件或中間文件,否則全部法律責任將由文件分享者全部承擔。
如需商業用途請購買正版,為國產軟件的助力!
#參考文章
(1) Seafile 管理員手冊
(2) 使用 Nginx 啟用 HTTPS
覺得這篇文章對你有幫助的話,就留下一個贊吧v*
請尊重作者,轉載還請注明出處!感謝配合~
[作者]: Imagine Miracle
[版權]: 本作品采用知識共享署名-非商業性-相同方式共享 4.0 國際許可協議進行許可。
[本文鏈接]: https://blog.csdn.net/qq_36393978/article/details/125327701
總結
以上是生活随笔為你收集整理的Linux 上部署 Seafile 9.0.x 专业版(Seafile Server端)——踩一路坑,溅一身水的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 免费HTML5期末大作业:我的家乡网站设
- 下一篇: linux 其他常用命令