docker+seafile+mysql部署
==備注==:默認(rèn)構(gòu)建的鏡像maridb不允許外部連接轩缤,需要修改maridb啟動(dòng)腳本構(gòu)建本地鏡像
本次部署包括初次安裝和升級(jí)版本怀浆,升級(jí)版本從6.0.9升級(jí)到6.1.1恬叹,maridb默認(rèn)已經(jīng)集成到docker鏡像里面腹躁,建議使用默認(rèn)的maridb退个,如果使用外部mysql募壕,升級(jí)很麻煩,升級(jí)過程可能存在數(shù)據(jù)庫(kù)結(jié)構(gòu)的變化语盈。
操作步驟
- 更新構(gòu)建seafile代碼庫(kù)
[root@localhost var]# git clone https://github.com/haiwen/seafile-docker.git /var/seafile/
正克隆到 '/var/seafile'...
remote: Counting objects: 652, done.
remote: Total 652 (delta 0), reused 0 (delta 0), pack-reused 652
接收對(duì)象中: 100% (652/652), 110.65 KiB | 143.00 KiB/s, done.
處理 delta 中: 100% (362/362), done.
[root@localhost var]#
- 代碼庫(kù)目前最新版本是6.1.1舱馅,因?yàn)楹竺嬉v升級(jí)操作,所以先把版本切換到6.0.9刀荒,然后再升級(jí)到6.1.1
[root@localhost var]# cd seafile/ #切換到代碼目錄
[root@localhost seafile]# git tag # 參看標(biāo)簽版本
v6.0.7
v6.0.9
v6.1.1
[root@localhost seafile]# git checkout v6.0.9 #切換到v6.0.9
Note: checking out 'v6.0.9'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD 目前位于 5f89412... Updated to seafile server 6.0.9
[root@localhost seafile]# git status #查看當(dāng)前代碼庫(kù)的標(biāo)簽版本
# 頭指針分離于 v6.0.9
無(wú)文件要提交习柠,干凈的工作區(qū)
[root@localhost seafile]#
- 復(fù)制服務(wù)配置文件到bootstrap目錄匀谣,根據(jù)需求,修改配置文件內(nèi)容
[root@localhost seafile]# pwd
/var/seafile
[root@localhost seafile]# cp samples/server.conf bootstrap/bootstrap.conf
[root@localhost seafile]# ls -la bootstrap/
總用量 8
drwxr-xr-x. 2 root root 44 10月 10 11:00 .
drwxr-xr-x. 11 root root 4096 10月 10 10:54 ..
-rw-r--r--. 1 root root 351 10月 10 11:00 bootstrap.conf
-rwxr-xr-x. 1 root root 0 10月 10 10:52 .gitkeep
[root@localhost seafile]#
[root@localhost seafile]# cat bootstrap/bootstrap.conf
# If you edit this file, remember to run ./launcher rebuild
[server]
server.hostname = seafile.example.com #修改主機(jī)名為服務(wù)器的ip地址
admin.email = me@example.com #修改管理員郵件
admin.password = asecret #修改管理員密碼
# Comment out this line and uncomment the two lines below to use letsencrypt SSL certificate
server.port_mappings = 80:80 #nginx端口映射资溃,mysql端口映射
# server.letsencrypt = true
# server.port_mappings = 80:80,443:443
[root@localhost seafile]#
#修改后的內(nèi)容如下
[root@localhost seafile]# cat bootstrap/bootstrap.conf
# If you edit this file, remember to run ./launcher rebuild
[server]
server.hostname = 192.168.100.196
admin.email = huangmeng4520@163.com
admin.password = password
# Comment out this line and uncomment the two lines below to use letsencrypt SSL certificate
server.port_mappings = 80:80,3316:3306
# server.letsencrypt = true
# server.port_mappings = 80:80,443:443
[root@localhost seafile]#
- 修改maridb啟動(dòng)腳本和dockerfile默認(rèn)的模板武翎,目的讓外部能夠訪問maridb
# /var/seafile/templates/Dockerfile.template 文件最后增加如下內(nèi)容
&& \
cat /app/image/base/services/mysql.sh > /etc/service/mysql/run
#maridb啟動(dòng)腳本增加 --bind-address=0.0.0.0
/var/seafile/image/base/services/mysql.sh文件內(nèi)容修改如下
/sbin/setuser mysql /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-log-error --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --bind-address=0.0.0.0 --port=3306 >/var/log/mysql.log 2>&1
- 執(zhí)行構(gòu)建seafile本地docker鏡像,此過程先pull seafile基礎(chǔ)鏡像(seafileltd/seafile 6.0.9)溶锭,然后創(chuàng)建數(shù)據(jù)庫(kù)目錄宝恶,初始化數(shù)據(jù)庫(kù),構(gòu)建本地seafile鏡像(local_seafile/server latest)
[root@localhost seafile]# ./launcher bootstrap
[2017-10-09 15:19:00] Pulling Seafile server image 6.0.9, this may take a while.
6.0.9: Pulling from seafileltd/seafile # 1趴捅、pull6.0.9版本基礎(chǔ)鏡像
f069f1d21059: Pull complete
ecbeec5633cf: Pull complete
ea6f18256d63: Pull complete
54bde7b02897: Pull complete
a3ed95caeb02: Pull complete
ce9e695a6234: Pull complete
346026b9659b: Pull complete
5416dcf47cda: Pull complete
5822c8cc29ab: Pull complete
d96fa9a845b5: Pull complete
867a50b477be: Pull complete
d4a99a640cd4: Pull complete
Digest: sha256:38ec596f3a6fbcf03a17ab8a62fdcd413fb3247ae66ebaa97b0b07d93bd6079c
Status: Downloaded newer image for seafileltd/seafile:6.0.9
[2017-10-09 15:27:46] Seafile server image 6.0.9 pulled. Now bootstrapping the server ...
Rebuilding mysql data dir #構(gòu)建mysql數(shù)據(jù)庫(kù)存儲(chǔ)目錄
Starting mysqld
Waiting for mysqld to come online
Fixing root password
Shutting down mysqld
[2017-10-09 07:28:04] Generating local Dockerfile ... #構(gòu)建本地docker images
[2017-10-09 07:28:06] Now running setup-seafile-mysql.py in auto mode.
Checking python on this machine ...
Checking python module: setuptools ... Done.
Checking python module: python-imaging ... Done.
Checking python module: python-mysqldb ... Done.
verifying password of user root ...
verifying password of user root ... done
---------------------------------
This is your configuration
---------------------------------
server name: seafile
server ip/domain: seafile.example.com
seafile data dir: /opt/seafile/seafile-data
fileserver port: 8082
database: create new
ccnet database: ccnet_db
seafile database: seafile_db
seahub database: seahub_db
database user: seafile
Generating ccnet configuration ...
done
Successly create configuration dir /opt/seafile/ccnet.
Generating seafile configuration ...
Done.
done
Generating seahub configuration ...
----------------------------------------
Now creating seahub database tables ...
----------------------------------------
creating seafile-server-latest symbolic link ... done
-----------------------------------------------------------------
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.
[2017-10-09 07:28:33] Updating version stamp
[2017-10-09 07:28:33] Generated local config.
[2017-10-09 15:28:37] Now building the local docker image.
[2017-10-09 15:28:48] Image built.
[root@localhost seafile]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
local_seafile/server latest d6289863c8b5 31 seconds ago 824MB
seafileltd/seafile 6.0.9 0d630bc508cc 4 months ago 823MB
[root@localhost seafile]#
- 啟動(dòng)seafile服務(wù)
[root@localhost seafile]# ./launcher -v start
[2017-10-10 11:22:58] [debug] Your version: 6.0.9, latest version: 6.0.9
[2017-10-10 11:22:59] Starting up new seafile server container
+ docker run -d --name seafile -h seafile -e SEAFILE_DOCKER_VERBOSE=true -v /var/seafile/shared:/shared -v /var/seafile/shared/logs/var-log:/var/log -v /var/seafile/shared/db:/var/lib/mysql -v /var/seafile/shared/.bash_history:/root/.bash_history -p 80:80 -p 3316:3306 local_seafile/server:latest
fafcbd53bbb6af27eb2d882b6c39960534bd83c8841ad16a21ff9d3954f3037f
[root@localhost seafile]#
- 默認(rèn)maridb不支持root遠(yuǎn)程連接垫毙,可以通過一下操作外部訪問
[root@localhost seafile]# docker exec -it seafile bash #進(jìn)入容器命令
root@seafile:/opt/seafile# mysql #登陸mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.0.27-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; #授權(quán)root遠(yuǎn)程登陸和設(shè)置密碼
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
此時(shí)可以通過宿主機(jī)ip+3316端口登陸mysql(3個(gè)庫(kù)ccnet_db,seafile_db,seahub_db)
- 訪問seafile http://192.168.100.196(用戶名:huangmeng4520@163.com 密碼:password)
目錄結(jié)構(gòu)
[root@localhost shared]# pwd
/var/seafile/shared
[root@localhost shared]# tree -L 2
.
├── db #數(shù)據(jù)庫(kù)存儲(chǔ)目錄
│ ├── aria_log.00000001
│ ├── aria_log_control
│ ├── ccnet_db
│ ├── ibdata1
│ ├── ib_logfile0
│ ├── ib_logfile1
│ ├── multi-master.info
│ ├── mysql
│ ├── performance_schema
│ ├── seafile_db
│ └── seahub_db
├── logs #日志文件目錄
│ ├── seafile
│ └── var-log
└── seafile
├── ccnet #配置文件
├── conf # 配置文件
├── seafile-data # 數(shù)據(jù)存儲(chǔ)目錄
└── seahub-data #數(shù)據(jù)存儲(chǔ)目錄
14 directories, 6 files
[root@localhost shared]#
升級(jí)seafile(6.0.9->6.1.1)
為了保證升級(jí)逼真,先在目前的6.0.9版本中創(chuàng)建幾個(gè)用戶拱绑,上傳一些文件综芥。
- 切換git庫(kù)到v6.1.1版本
[root@localhost seafile]# git checkout v6.1.1
警告:您正丟下 1 個(gè)提交,未和任何分支關(guān)聯(lián):
cfcbfaa xiuga
如果您想要通過創(chuàng)建新分支保存他們猎拨,這可能是一個(gè)好時(shí)候膀藐。
如下操作:
git branch new_branch_name cfcbfaa
HEAD 目前位于 6333307... docker image: move up infrequently-changed layers
[root@localhost seafile]# git status
# 頭指針分離于 v6.1.1
無(wú)文件要提交,干凈的工作區(qū)
[root@localhost seafile]#
- 修改maridb啟動(dòng)腳本和dockerfile默認(rèn)的模板红省,目的讓外部能夠訪問maridb
# /var/seafile/templates/Dockerfile.template 文件最后增加如下內(nèi)容
&& \
cat /app/image/base/services/mysql.sh > /etc/service/mysql/run
#maridb啟動(dòng)腳本增加 --bind-address=0.0.0.0
/var/seafile/image/base/services/mysql.sh文件內(nèi)容修改如下
/sbin/setuser mysql /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-log-error --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --bind-address=0.0.0.0 --port=3306 >/var/log/mysql.log 2>&1
- 執(zhí)行升級(jí)命令
[root@localhost seafile]# ./launcher -v rebuild
fatal: ref HEAD is not a symbolic ref
[2017-10-10 11:42:33] Stopping old container
+ docker stop -t 10 seafile
seafile
*** Running /etc/my_init.d/99_mysql_setup.sh...
*** Running /etc/my_init.d/create_data_links.sh...
*** Running /etc/rc.local...
*** Booting runit daemon...
*** Runit started as PID 10
*** Running /scripts/bootstrap.py...
[2017-10-10 03:42:37] Generating local Dockerfile ...
[2017-10-10 03:42:37] [debug] waiting for mysql server to be ready
[2017-10-10 03:42:39] [debug] mysql server is ready
[2017-10-10 03:42:39] Skip running setup-seafile-mysql.py because there is existing seafile-data folder.
[2017-10-10 03:42:39] Generated local config.
*** /scripts/bootstrap.py exited with status 0.
*** Shutting down runit daemon (PID 10)...
*** Killing all processes...
[2017-10-10 11:42:42] Now building the local docker image.
[2017-10-10 11:42:49] Image built.
[2017-10-10 11:42:49] Rebuilt successfully.
[2017-10-10 11:42:49] Removing old container
+ docker rm seafile
seafile
[2017-10-10 11:42:49] Checking if there is major version upgrade
[2017-10-10 11:42:49] ********************************
[2017-10-10 11:42:49] Major upgrade detected: You have 6.0.9, latest is 6.1.1
[2017-10-10 11:42:49] ********************************
[2017-10-10 11:42:49] Going to launch the docker container for manual upgrade
+ docker run -it --rm --name seafile-upgrade -h seafile -e SEAFILE_DOCKER_VERBOSE=true -v /var/seafile/shared:/shared -v /var/seafile/shared/logs/var-log:/var/log -v /var/seafile/shared/db:/var/lib/mysql -v /var/seafile/shared/.bash_history:/root/.bash_history local_seafile/server:latest /sbin/my_init -- /scripts/upgrade.py
*** Running /etc/my_init.d/99_mysql_setup.sh...
*** Running /etc/my_init.d/create_data_links.sh...
*** Running /etc/rc.local...
*** Booting runit daemon...
*** Runit started as PID 21
*** Running /scripts/upgrade.py...
[2017-10-10 03:42:50] [debug] waiting for mysql server to be ready
[2017-10-10 03:42:52] [debug] mysql server is ready
[2017-10-10 03:42:52] Running scripts /opt/seafile/seafile-server-6.1.1/upgrade/upgrade_6.0_6.1.sh
-------------------------------------------------------------
This script would upgrade your seafile server from 6.0 to 6.1
Press [ENTER] to contiune
-------------------------------------------------------------
Updating seafile/seahub database ... #自動(dòng)更新數(shù)據(jù)庫(kù)
[INFO] You are using MySQL
[INFO] updating seahub database...
Done
migrating avatars ...
Done
updating /opt/seafile/seafile-server-latest symbolic link to /opt/seafile/seafile-server-6.1.1 ...
-----------------------------------------------------------------
Upgraded your seafile server successfully.
-----------------------------------------------------------------
*** /scripts/upgrade.py exited with status 0.
*** Shutting down runit daemon (PID 21)...
*** Killing all processes...
[2017-10-10 11:42:58] [debug] Your version: 6.1.1, latest version: 6.1.1
[2017-10-10 11:42:59] Starting up new seafile server container
+ docker run -d --name seafile -h seafile -e SEAFILE_DOCKER_VERBOSE=true -v /var/seafile/shared:/shared -v /var/seafile/shared/logs/var-log:/var/log -v /var/seafile/shared/db:/var/lib/mysql -v /var/seafile/shared/.bash_history:/root/.bash_history -p 80:80 -p 3316:3306 local_seafile/server:latest
0375d08222b6031562eb6b296090fd39ea034007a601e51aa6b6debb0056516c
[2017-10-10 11:42:59] Your seafile server is now running.
[root@localhost seafile]#
- 訪問seafile服務(wù)器额各,驗(yàn)證文件是否丟失
- 升級(jí)之前最好備份下數(shù)據(jù)庫(kù)和存儲(chǔ)數(shù)據(jù)
連接外部mysql
修改配置文件下面的mysql連接
[root@localhost conf]# pwd
/var/seafile/shared/seafile/conf
[root@localhost conf]# tree
.
├── ccnet.conf #修改mysql連接
├── seafdav.conf
├── seafile.conf #修改mysql連接
├── seahub_settings.py #修改mysql連接
└── seahub_settings.pyc
0 directories, 5 files
[root@localhost conf]#