1 基础知识
本章节需要你先掌握Linux系统的JDK部署,如你尚未具备此知识,请按如下方法熟悉“jdk-8u65-linux-x64.tar.gz”版本的JDK部署,
本章节需要你先掌握Linux系统的Tigase部署,如你尚未具备此知识,请按如下方法熟悉“tigase-server-7.0.1-b3810-dist-max.tar.gz”版本的Tigase部署,
另外,如果你有闲暇时间,建议你先掌握Docker JDK的部署,
2 最佳实践
2.1 部署前的准备
2.1.1 部署Docker环境
本章使用如下Docker环境部署,参阅本章建议你先搭建以下Docker集群环境并熟悉,
2.1.2 准备系统镜像
In docker01
cd /data/docker/images/ docker load -i centos_centos7.3.1611.tar docker tag centos:centos7.3.1611 docker01.cmdschool.org:5000/centos:centos7.3.1611 docker push docker01.cmdschool.org:5000/centos:centos7.3.1611 docker image rm centos:centos7.3.1611
另外,安装包的离线下载请在能上网的docker环境的机器上使用如下命令,
docker pull centos:centos7.3.1611 docker save centos:centos7.3.1611 -o centos_centos7.3.1611.tar
另外,其他版本请从以下链接下载,
https://hub.docker.com/_/centos
2.1.3 下载JDK二进制安装包
cd ~ wget http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u65-linux-x64.tar.gz?AuthParam=1479977626_06aed8a715c8fbbc10f72c89ee38910b -O jdk-8u65-linux-x64.tar.gz
以上只是演示,如果不能下载请从JDK历史版本下载,
https://www.oracle.com/technetwork/java/javase/archive-139210.html
更新版本的JDK下载页面请参阅,
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2.1.4 下载Tigase二进制安装包
wget https://tigase.tech/attachments/2455/tigase-server-7.0.1-b3810-dist-max.tar.gz
如果需要其他版本,请从以下链接下载(请注意JAR包可能不齐全,需要向官方索取),
https://github.com/tigase/tigase-server/tags
2.2 创建Tigase镜像
2.2.1 创建镜像项目文件夹
cd ~ mkdir ~/imageProject-tigase-server-7.0.1
2.2.2 创建Dockerfile
vim ~/imageProject-tigase-server-7.0.1/Dockerfile
加入如下配置,
FROM docker01.cmdschool.org:5000/centos:centos7.3.1611 MAINTAINER will@cmdschool.org # Install Tools RUN yum install -y net-tools RUN rm -rf /var/cache/yum/* # Deploy Java jdk COPY jdk1.8.0_65 /usr/java/jdk1.8.0_65 ENV JAVA_HOME=/usr/java/jdk1.8.0_65 ENV JRE_HOME=${JAVA_HOME}/jre ENV CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib ENV PATH=${JAVA_HOME}/bin:$PATH # Deploy Tigase ENV TIGASE_HOME=/usr/tigase COPY tigase-server-7.0.1-b3810 ${TIGASE_HOME} RUN mkdir -p /etc/tigase /var/log/tigase /var/run/tigase RUN ln -s ${TIGASE_HOME}/etc/init.properties /etc/tigase/init.properties RUN ln -s ${TIGASE_HOME}/etc/tigase.conf /etc/tigase/tigase.conf RUN echo '#!/bin/bash' > /root/start.sh RUN echo 'echo "Starting Tigase XMPP Server...";' >> /root/start.sh RUN echo 'cd ${TIGASE_HOME}/scripts' >> /root/start.sh RUN echo './tigase.sh run /etc/tigase/tigase.conf' >> /root/start.sh RUN chmod +x /root/start.sh EXPOSE 5222 5223 5277 5280 5281 5290 5291 8080 9050 9070 WORKDIR /root CMD ["/bin/bash","./start.sh"]
“FROM”指令声明基于“centos7.3.1611”镜像打包
“COPY”指令声明复制当前目录的具体文件到打包的镜像
“ENV”指令声明JAVA JDK或Tigase所需的环境变量
“RUN”指令声明容器环境执行的命令
“EXPOSE ”指令声明容器使用的端口
“WORKDIR”指令声明切换容器内部的某个目录
“CMD”指令声明启动容器执行的启动服务命令
所以我们需要根据定义的文件准备需要复制的文件,
cd ~ tar -xf jdk-8u65-linux-x64.tar.gz -C ~/imageProject-tigase-server-7.0.1/ tar -xf tigase-server-7.0.1-b3810-dist-max.tar.gz -C ~/imageProject-tigase-server-7.0.1/
确认所需的文件存在,
ls ~/imageProject-tigase-server-7.0.1
可见如下显示,
Dockerfile jdk1.8.0_65 tigase-server-7.0.1-b3810
然后,我们需要修改Tigase的默认配置,
cp ~/imageProject-tigase-server-7.0.1/tigase-server-7.0.1-b3810/etc/tigase.conf ~/imageProject-tigase-server-7.0.1/tigase-server-7.0.1-b3810/etc/tigase.conf.default vim ~/imageProject-tigase-server-7.0.1/tigase-server-7.0.1-b3810/etc/tigase.conf
修改如下参数,
osgiEnabled=true JAVA_HOME="/usr/java/jdk1.8.0_65" TIGASE_HOME="/usr/tigase" TIGASE_CONSOLE_LOG="/var/log/tigase/tigase-console.log" TIGASE_CONFIG="/etc/tigase/tigase.xml" TIGASE_OPTIONS=" --property-file /etc/tigase/init.properties " TIGASE_PID="/var/run/tigase/tigase.pid"
2.2.3 执行打包操作
cd ~/imageProject-tigase-server-7.0.1 docker build -t tigase-server:7.0.1 .
以上“.”指当前目录为编译目录,编译程序会自动加载“Dockerfile”文件定义,可见如下显示,
Sending build context to Docker daemon 425.2MB Step 1/20 : FROM docker01.cmdschool.org:5000/centos:centos7.3.1611 ---> c5d48e81b986 [...] Step 20/20 : CMD ["/bin/bash","./start.sh"] ---> Running in 6430092f5f15 Removing intermediate container 6430092f5f15 ---> 59a2e75ae522 Successfully built 59a2e75ae522 Successfully tagged tigase-server:7.0.1
如果镜像集群公用,还需要执行以下命令,
docker tag tigase-server:7.0.1 docker01.cmdschool.org:5000/tigase-server:7.0.1 docker push docker01.cmdschool.org:5000/tigase-server:7.0.1 docker image rm tigase-server:7.0.1
完成后,可使用如下命令查看镜像,
docker images
可见如下显示,
REPOSITORY TAG IMAGE ID CREATED SIZE docker01.cmdschool.org:5000/tigase-server 7.0.1 59a2e75ae522 2 minutes ago 614MB [...]
2.2.4 测试软件运行
docker run -d --name tigase -p 8080:8080 -p 5222:5222 docker01.cmdschool.org:5000/tigase-server:7.0.1
以上运行容器环境后,我们使用以下命令登录容器虚拟机,
docker exec -it `docker container ls | grep 'tigase' | cut -d" " -f1 ` /bin/bash
测试Java运行
java -version
可见如下显示,
java version "1.8.0_65" Java(TM) SE Runtime Environment (build 1.8.0_65-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
可使用如下命令查看软件倾听的端口,
netstat -antp
可见如下显示,
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:5280 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:5222 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:5223 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:5290 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:5269 0.0.0.0:* LISTEN -
测试完成后可使用如下命令退出容器虚拟机,
exit
另外,你可以使用如下命令查询当前运行的container,
docker ps -a
可见如下显示,
13e3420ff551 docker01.cmdschool.org:5000/tigase-server:7.0.1 "/bin/bash ./start.sh" 54 seconds ago Up 54 seconds 5223/tcp, 5277/tcp, 5280-5281/tcp, 0.0.0.0:5222->5222/tcp, 5290-5291/tcp, 9050/tcp, 0.0.0.0:8080->8080/tcp, 9070/tcp tigase [...]
然后可以使用如下命令停止并删除,
docker container stop 13e3420ff551 docker container rm 13e3420ff551
参阅文档
====================
https://docs.docker.com/engine/reference/builder/
https://github.com/tigase/tigase-xmpp-server-docker/blob/master/8.1.0/Dockerfile
https://github.com/tigase/tigase-xmpp-server-docker
没有评论