docker+seafile+maridb部署

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)

目录结构

[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]# 

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,723评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,485评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,998评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,323评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,355评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,079评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,389评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,019评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,519评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,971评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,100评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,738评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,293评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,289评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,517评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,547评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,834评论 2 345

推荐阅读更多精彩内容