如何部署Docker Tigase?

Docker

1 基础知识

由于笔者需要将生产环境的Tigase迁移到Docker环境,所有产生本章节。

2 最佳实践

2.1 部署前的准备

2.1.1 部署Docker环境

本章使用如下Docker环境部署,参阅本章建议你先搭建以下Docker集群环境并熟悉,

如何部署Docker生产环境?

2.1.2 准备Tigase镜像

In docker01
如果你需要参阅本章节,请参阅以下章节完成打包Tigase的私有镜像,

如何打包Docker Tigase镜像?

2.1.3 准备MySQL镜像

In docker01

cd /data/docker/images/
docker load -i mysql_5.6.34.tar
docker tag mysql:5.6.34 docker01.cmdschool.org:5000/mysql:5.6.34
docker push docker01.cmdschool.org:5000/mysql:5.6.34
docker image rm mysql:5.6.34

另外,安装包的离线下载请在能上网的docker环境的机器上使用如下命令,

docker pull mysql:5.6.34
docker save mysql:5.6.34 -o mysql_5.6.34.tar

另外,其他版本请从以下链接下载,
https://hub.docker.com/_/mysql

2.2 部署Tigase

In docker01

2.2.1 创建服务配置文件

vim /data/docker/yml/tigase-stack.yml

加入如下配置,

version: '3.1'

services:

  db:
    image: docker01.cmdschool.org:5000/mysql:5.6.34
    volumes:
      - /data/docker/service/mysql/data:/var/lib/mysql
      - /data/docker/service/mysql/conf:/etc/mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: mysqlpwd
      TZ: Asia/Shanghai
    deploy:
      replicas: 1
      placement:
        constraints: [node.labels.mysql == true]
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "5"
  tigase:
    image: docker01.cmdschool.org:5000/tigase-server:7.0.1
    restart: always
    environment:
      TZ: Asia/Shanghai
    ports:
      - 8080:8080
      - 5222:5222
    deploy:
      replicas: 1
      placement:
        constraints: [node.labels.tigase == true]
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "5"

根据配置需求创建数据存放目录,
In docker02

mkdir -p /data/docker/service/mysql/data
mkdir -p /data/docker/service/mysql/conf/conf.d/

根据配置需求创建MySQL主配置文件,

vim /data/docker/service/mysql/conf/my.cnf

加入如下配置,

[mysqld]
skip-host-cache
skip-name-resolve

# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1

#log-error      = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

根据MySQL的主配置文件创建子目录配置,

vim /data/docker/service/mysql/conf/conf.d/docker.cnf

加入如下配置,

[mysqld]
skip-host-cache
skip-name-resolve

根据配置的需求设置运行标记,
In docker01

docker node update --label-add mysql=true docker02.cmdschool.org
docker node update --label-add tigase=true docker01.cmdschool.org

2.2.2 部署服务

docker stack deploy -c /data/docker/yml/tigase-stack.yml tigase

2.3 使用Web向导配置tigase

2.3.1 生成配置文件

http://10.168.0.210:8080/setup/
按照以上向导提示生成配置(按照向导跑,简单这里不详述)并单击保存,对应的参数可按如下输入,

company name: cmdschool
Your XMPP (Jabber) domains: cmdschool.org
Server administrators: admin@cmdschool.org
Admin password: ******
Select database: MySQL
MySQL Super user account name: root
MySQL Super user account password: mysqlpwd
MySQL Database account: tigase
MySQL Database Account password: tigasepwd
MySQL Database name: tigasedb
MySQL Database host or IP: 10.0.4.188
MySQL Additional database parameters: 留空

另外,需要注意的是,数据库主机需要用IP,IP查询的方法如下,

docker exec -it `docker container ls | grep 'tigase' | cut -d" " -f1 ` bash

然后通过Ping获取MySQL DB的地址,

ping db

可见如下显示,

PING db (10.0.4.188) 56(84) bytes of data.
64 bytes from 10.0.4.188 (10.0.4.188): icmp_seq=1 ttl=64 time=0.056 ms
64 bytes from 10.0.4.188 (10.0.4.188): icmp_seq=2 ttl=64 time=0.049 ms
64 bytes from 10.0.4.188 (10.0.4.188): icmp_seq=3 ttl=64 time=0.042 ms
64 bytes from 10.0.4.188 (10.0.4.188): icmp_seq=4 ttl=64 time=0.049 ms
[...]

2.3.2 校验保存的配置

In docker01

docker exec -it `docker container ls | grep 'tigase' | cut -d" " -f1 ` bash

然后使用如下命令查看配置,

cat /etc/tigase/init.properties

可见如下配置,

config-type=--gen-config-def

--virt-hosts=cmdschool.org
--admins=admin@cmdschool.org

--debug=server

--user-db-uri=jdbc:mysql://localhost/tigasedb?user=tigase&password=tigasepwd


--sm-plugins=+jabber\:iq\:auth,+urn\:ietf\:params\:xml\:ns\:xmpp-sasl,+urn\:ietf\:params\:xml\:ns\:xmpp-bind,+urn\:ietf\:params\:xml\:ns\:xmpp-session,+jabber\:iq\:register,+jabber\:iq\:roster,+presence,+basic-filter,+domain-filter,+jabber\:iq\:privacy,+jabber\:iq\:version,+http\://jabber.org/protocol/stats,+starttls,-msgoffline,+vcard-temp,+http\://jabber.org/protocol/commands,+jabber\:iq\:private,+urn\:xmpp\:ping,+pep,+zlib,+message-archive-xep-0136,+amp

--comp-name-1=muc
--comp-class-1=tigase.muc.MUCComponnet

--comp-name-2=pubsub
--comp-class-2=tigase.pubsub.PubSubComponent

--comp-name-3=http
--comp-class-3=tigase.http.HttpMessageReceiver

2.4 客户端测试

以上仅仅完成服务端的配置,如果需要进行客户端测试,请按照如下链接配置客户端,
https://www.cmdschool.org/archives/2670

参阅文档
====================

https://docs.docker.com/engine/reference/builder/

没有评论

发表回复

Docker
如何自定义Docker Registry的地址?

1 前言 一个问题,一篇文章,一出故事。 由于公司内部服务器由于不允许直接连接Internet,因此 …

Docker
如何代理Docker Registry?

1 前言 一个问题,一篇文章,一出故事。 由于公司内部服务器由于不允许直接连接Internet,因此 …

Docker
如何部署Oracle 9.x Docker 环境?

1 基础知识 1.1 基本概念 1.1.1 Docker的基本概念 – Docker是开 …