docker+seafile+mysql部署
==备注==:默认构建的镜像maridb不允许外部连接,需要修改maridb启动脚本构建本地镜像
本次部署包括初次安装和升级版本,升级版本从6.0.9升级到6.1.1,maridb默认已经集成到docker镜像里面,建议使用默认的maridb,如果使用外部mysql,升级很麻烦,升级过程可能存在数据库结构的变化。
操作步骤
- 更新构建seafile代码库
[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
接收对象中: 100% (652/652), 110.65 KiB | 143.00 KiB/s, done.
处理 delta 中: 100% (362/362), done.
[root@localhost var]#
- 代码库目前最新版本是6.1.1,因为后面要讲升级操作,所以先把版本切换到6.0.9,然后再升级到6.1.1
[root@localhost var]# cd seafile/ #切换到代码目录
[root@localhost seafile]# git tag # 参看标签版本
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 #查看当前代码库的标签版本
# 头指针分离于 v6.0.9
无文件要提交,干净的工作区
[root@localhost seafile]#
- 复制服务配置文件到bootstrap目录,根据需求,修改配置文件内容
[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 #修改主机名为服务器的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]#
#修改后的内容如下
[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启动脚本和dockerfile默认的模板,目的让外部能够访问maridb
# /var/seafile/templates/Dockerfile.template 文件最后增加如下内容
&& \
cat /app/image/base/services/mysql.sh > /etc/service/mysql/run
#maridb启动脚本增加 --bind-address=0.0.0.0
/var/seafile/image/base/services/mysql.sh文件内容修改如下
/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
- 执行构建seafile本地docker镜像,此过程先pull seafile基础镜像(seafileltd/seafile 6.0.9),然后创建数据库目录,初始化数据库,构建本地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版本基础镜像
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 #构建mysql数据库存储目录
Starting mysqld
Waiting for mysqld to come online
Fixing root password
Shutting down mysqld
[2017-10-09 07:28:04] Generating local Dockerfile ... #构建本地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]#
- 启动seafile服务
[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]#
- 默认maridb不支持root远程连接,可以通过一下操作外部访问
[root@localhost seafile]# docker exec -it seafile bash #进入容器命令
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; #授权root远程登陆和设置密码
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
此时可以通过宿主机ip+3316端口登陆mysql(3个库ccnet_db,seafile_db,seahub_db)
- 访问seafile http://192.168.100.196(用户名:huangmeng4520@163.com 密码:password)
目录结构
[root@localhost shared]# pwd
/var/seafile/shared
[root@localhost shared]# tree -L 2
.
├── db #数据库存储目录
│ ├── 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 # 数据存储目录
└── seahub-data #数据存储目录
14 directories, 6 files
[root@localhost shared]#
升级seafile(6.0.9->6.1.1)
为了保证升级逼真,先在目前的6.0.9版本中创建几个用户,上传一些文件。
- 切换git库到v6.1.1版本
[root@localhost seafile]# git checkout v6.1.1
警告:您正丢下 1 个提交,未和任何分支关联:
cfcbfaa xiuga
如果您想要通过创建新分支保存他们,这可能是一个好时候。
如下操作:
git branch new_branch_name cfcbfaa
HEAD 目前位于 6333307... docker image: move up infrequently-changed layers
[root@localhost seafile]# git status
# 头指针分离于 v6.1.1
无文件要提交,干净的工作区
[root@localhost seafile]#
- 修改maridb启动脚本和dockerfile默认的模板,目的让外部能够访问maridb
# /var/seafile/templates/Dockerfile.template 文件最后增加如下内容
&& \
cat /app/image/base/services/mysql.sh > /etc/service/mysql/run
#maridb启动脚本增加 --bind-address=0.0.0.0
/var/seafile/image/base/services/mysql.sh文件内容修改如下
/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
- 执行升级命令
[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 ... #自动更新数据库
[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服务器,验证文件是否丢失
- 升级之前最好备份下数据库和存储数据
连接外部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]#
网友评论