一、部署环境说明

docker服务版本:
version 18.09.0
nginx服务版本:
version: nginx/1.15.10
redis服务版本:
version: redis/5.0.3
tomcat服务版本:
version: tomcat/8.5.30
JDK服务版本:
alpine-oraclejdk8

二、安装docker服务

配置阿里yum源并安装docker

# yum install docker -y

三、项目部署

1、准备工作

拉取如下镜像

# docker images

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.15. 2bcb04bdb83f months ago 109MB
tomcat 8.5. 38bdcf7a367c months ago 546MB
redis latest 82629e941a38 months ago 95MB
huanwei/alpine-oraclejdk8 latest 28e66d63b8a4 years ago 167MB

拉取命令如下:

# docker pull docker.io/huanwei/alpine-oraclejdk8

# docker pull daocloud.io/library/tomcat:8.5.30

# docker pull daocloud.io/library/nginx:1.15.10

# docker pull daocloud.io/library/redis:5.0.3

镜像重命名

# docker tag daocloud.io/library/nginx:1.15.10 nginx:1.15.10

# docker tag daocloud.io/library/tomcat:8.5.30 tomcat:8.5.30

删除旧的镜像名

# docker rmi daocloud.io/library/nginx:1.15.10

# docker rmi daocloud.io/library/tomcat:8.5.30

软件版本说明:
nginx version: nginx/1.15.
redis version: redis/5.0.
tomcat version: tomcat/8.5.
alpine-oraclejdk8

2、创建两个tomcat容器

创建一个测试tomcat容器,用于拷贝tomcat原文件

# docker run --name test -d -i -t tomcat:8.5.30 /bin/bash

[root@localhost docker-server]# docker run --name test -d -i -t tomcat:8.5. /bin/bash
1287b583d3b7b85a65ea4d80640124fc5dbd1905d0fc5c33ef05e0ba9872c681

进入测试容器熟悉tomcat安装位置

# docker exec -it test bash

[root@localhost docker-server]# docker exec -it test bash
root@1287b583d3b7:/usr/local/tomcat#
root@1287b583d3b7:/usr/local/tomcat# ls
LICENSE NOTICE RELEASE-NOTES RUNNING.txt bin conf include lib logs native-jni-lib temp webapps work
root@1287b583d3b7:/usr/local/tomcat#
root@1287b583d3b7:/usr/local/tomcat# pwd
/usr/local/tomcat
root@1287b583d3b7:/usr/local/tomcat#
root@1287b583d3b7:/usr/local/tomcat# cd ..
root@1287b583d3b7:/usr/local#
root@1287b583d3b7:/usr/local# ls
bin etc games include lib man sbin share src tomcat
root@1287b583d3b7:/usr/local#
root@1287b583d3b7:/usr/local# exit
exit

拷贝容器的tomcat文件用于后期的tomcat映射挂载

# docker cp test:/usr/local/tomcat /home/tjsp/

[root@localhost docker-server]# docker cp test:/usr/local/tomcat /home/tjsp/
[root@localhost docker-server]# cd ..
[root@localhost tjsp]# ls
docker-server tomcat
[root@localhost tjsp]#
[root@localhost tjsp]# cd tomcat/
[root@localhost tomcat]#
[root@localhost tomcat]#
[root@localhost tomcat]# ls
LICENSE NOTICE RELEASE-NOTES RUNNING.txt bin conf include lib logs native-jni-lib temp webapps work
[root@localhost tomcat]#

复制tomcat文件用于映射挂载tomcat1服务

[root@localhost tjsp]# cp -r tomcat/ tomcat1
[root@localhost tjsp]#
[root@localhost tjsp]#
[root@localhost tjsp]# ls
docker-server tomcat tomcat1
[root@localhost tjsp]#

创建容器

# docker run -p 8081:8080 --name tomcat1 -h Front-end1 -v /home/tjsp/tomcat1:/usr/local/tomcat -d tomcat:8.5.30

# docker run -p 8082:8080 --name tomcat2 -h Front-end2 -v /home/tjsp/tomcat2:/usr/local/tomcat -d tomcat:8.5.30

[root@localhost tjsp]# docker run -p : --name tomcat1 -h Front-end1 -v /home/tjsp/tomcat1:/usr/local/tomcat -d tomcat:8.5.
d41f7b69ebbf9717629b220907fc7c88e8d106f2b99a805c6b0465b4bc49f484
[root@localhost tjsp]#
[root@localhost tjsp]# docker run -p : --name tomcat2 -h Front-end2 -v /home/tjsp/tomcat2:/usr/local/tomcat -d tomcat:8.5.
78b5482a0a9546f5355fccb8f28bf4e08751f58e74b8a3b66af36a775ae31788
[root@localhost tjsp]#

查看运行状态

# docker ps

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78b5482a0a95 tomcat:8.5. "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp tomcat2
d41f7b69ebbf tomcat:8.5. "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp tomcat1
1287b583d3b7 tomcat:8.5. "/bin/bash" About an hour ago Up About an hour /tcp test

添加office服务,运行一个tomcat跑war包

# cp -r tomcat tomcat3

[root@localhost ~]# cd /home/tjsp/
[root@localhost tjsp]#
[root@localhost tjsp]# ls
docker-server nginx tomcat tomcat1 tomcat2
[root@localhost tjsp]#
[root@localhost tjsp]# cp -r tomcat tomcat3
[root@localhost tjsp]#
[root@localhost tjsp]# ls
docker-server nginx tomcat tomcat1 tomcat2 tomcat3

创建一个tomcat容器

# docker run -p 8086:8080 --name tomcat3 -h tjsp_office -v /home/tjsp/tomcat3:/usr/local/tomcat -d tomcat:8.5.30

[root@localhost tjsp]# docker run -p : --name tomcat3 -h tjsp_office -v /home/tjsp/tomcat3:/usr/local/tomcat -d tomcat:8.5.
9fe494bf43bc446f9f021d19e25ec5e030e6031c8fc65dcc8f08609f3b4bc946
[root@localhost tjsp]#
[root@localhost tjsp]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fe494bf43bc tomcat:8.5. "catalina.sh run" seconds ago Up seconds 0.0.0.0:->/tcp tomcat3

3、创建nginx容器

创建一个测试nginx容器,用于拷贝nginx原文件

# docker run --name nginx_test -h nignx1.15.10 -d nginx:1.15.10

# docker cp nginx_test:/etc/nginx /home/tjsp/

[root@localhost tjsp]# docker run --name nginx_test -h nignx1.15.10 -d nginx:1.15.
0b02f6f222ef38aa2f39fa7ac5d5a588b5df24bb6d7e28fba90aa55b0a4bf82e
[root@localhost tjsp]#
[root@localhost tjsp]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b02f6f222ef nginx:1.15. "nginx -g 'daemon of…" seconds ago Up seconds /tcp nginx_test
78b5482a0a95 tomcat:8.5. "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp tomcat2
d41f7b69ebbf tomcat:8.5. "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp tomcat1
1287b583d3b7 tomcat:8.5. "/bin/bash" About an hour ago Up About an hour /tcp test
[root@localhost tjsp]#
[root@localhost tjsp]# docker cp nginx_test:/etc/nginx /home/tjsp/
[root@localhost tjsp]#
[root@localhost tjsp]# ls
docker-server nginx tomcat tomcat1 tomcat2
[root@localhost tjsp]#
[root@localhost tjsp]# cd nginx/
[root@localhost nginx]#
[root@localhost nginx]# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
[root@localhost nginx]#

创建容器

# docker run --name nginx_tjsp -h nignx1.15.10 -p 7080:80 -v /home/tjsp/nginx:/etc/nginx/ -d nginx:1.15.10

[root@localhost nginx]# docker run --name nginx_tjsp -h nignx1.15.10 -p : -v /home/tjsp/nginx:/etc/nginx/ -d nginx:1.15.
39e65baa524a62e2a07ad0ccc035baf829f3f9736148529b79d18452011bf390
[root@localhost nginx]#
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
39e65baa524a nginx:1.15. "nginx -g 'daemon of…" seconds ago Up seconds 0.0.0.0:->/tcp nginx_tjsp
0b02f6f222ef nginx:1.15. "nginx -g 'daemon of…" minutes ago Up minutes /tcp nginx_test
78b5482a0a95 tomcat:8.5. "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp tomcat2
d41f7b69ebbf tomcat:8.5. "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp tomcat1
1287b583d3b7 tomcat:8.5. "/bin/bash" About an hour ago Up About an hour /tcp test

修改nginx配置文件

# vi /home/tjsp/nginx/nginx.conf

配置文件如下:

user  root;
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ; ## Proxy
upstream tjsp_client_proxy {
server 192.168.2.207: weight= max_fails= fail_timeout=30s;
server 192.168.2.207: weight= max_fails= fail_timeout=30s;
} upstream tjsp_server_proxy {
server 192.168.2.207: weight= max_fails= fail_timeout=30s;
server 192.168.2.207: weight= max_fails= fail_timeout=30s;
server 192.168.2.207: weight= max_fails= fail_timeout=30s;
} upstream etl_server_proxy {
server 192.168.2.207: weight= max_fails= fail_timeout=30s;
#server 172.17.8.20: weight= max_fails= fail_timeout=30s;
} upstream exp_server_proxy {
server 192.168.2.207: weight= max_fails= fail_timeout=30s;
} server {
listen ;
server_name localhost;
error_page /50x.html;
location / {
root html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
index index.html index.htm; }
location /tjsp {
root html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
proxy_pass http://tjsp_client_proxy/tjsp;
#try_files $uri $uri/ /main
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /a_ssets {
root html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
proxy_pass http://tjsp_client_proxy/assets;
#try_files $uri $uri/ /main
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /zjb {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
proxy_pass http://tjsp_server_proxy/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
} location /etl {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
proxy_pass http://etl_server_proxy/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /exp {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
proxy_pass http://exp_server_proxy/office;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /exl {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
proxy_pass http://etl_server_proxy/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
} } }

4、创建redis容器

说明:

redis的密码为123456

保护模式已经关闭

集群模式未开启

# docker run --name redis -h redis_tjsp -p 6379:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no

进入redis查看

# docker exec -it redis bash

[root@localhost tjsp]# docker run --name redis -h redis_tjsp -p : -d redis redis-server --requirepass "" --appendonly yes --protected-mode no
7626b4b8f3c1b2f8161341209f159167876cdc3fee8b3b90c180770dc426f3bd
[root@localhost tjsp]#
[root@localhost tjsp]# docker exec -it redis bash
root@redis_tjsp:/data#
root@redis_tjsp:/data# ls
appendonly.aof
root@redis_tjsp:/data#
root@redis_tjsp:/data# exit
exit
[root@localhost tjsp]#

5、构建jdk镜像

创建一个构建目录
# mkdir -p /home/tjsp/docker-server
编写Dockerfile文件
# cd /home/tjsp/docker-server/
# vi Dockerfile
FROM docker.io/huanwei/alpine-oraclejdk8
ADD app.jar /
EXPOSE
ENTRYPOINT ["java","-D java.security.egd=file:/dev./urandom","-jar","/app.jar","--spring.profiles.active=dev207"]
VOLUME /tmp

构建镜像

# docker build -t cnbi-tjsp:latest .

[root@localhost tjsp]# cd docker-server/
[root@localhost docker-server]#
[root@localhost docker-server]# ls
Dockerfile app.jar
[root@localhost docker-server]#
[root@localhost docker-server]# docker build -t cnbi-tjsp:latest .
Sending build context to Docker daemon 113MB
Step / : FROM docker.io/huanwei/alpine-oraclejdk8
---> 28e66d63b8a4
Step / : ADD /app.jar //
---> 063e68f2e01a
Step / : EXPOSE
---> Running in 9ab4a3c0fc63
Removing intermediate container 9ab4a3c0fc63
---> 7522d6d8ea7f
Step / : ENTRYPOINT ["java","-D java.security.egd=file:/dev./urandom","-jar","/app.jar"]
---> Running in 3726768330c0
Removing intermediate container 3726768330c0
---> d6ddeff92429
Step / : VOLUME /tmp
---> Running in b7ac287ab1c9
Removing intermediate container b7ac287ab1c9
---> 692144a74536
Successfully built 692144a74536
Successfully tagged cnbi-tjsp:latest
[root@localhost docker-server]#

查看构建的镜像

# docker images

[root@localhost docker-server]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cnbi-tjsp latest 692144a74536 minutes ago 280MB

6、创建djk镜像容器

创建挂载目录

# mkdir -p /home/tjsp/nginx/html/file

[root@localhost tjsp]# cd nginx/
[root@localhost nginx]# pwd
/home/tjsp/nginx
[root@localhost nginx]# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
[root@localhost nginx]#
[root@localhost nginx]# mkdir -p html/file
[root@localhost nginx]#
[root@localhost nginx]# ls
conf.d fastcgi_params html koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
[root@localhost nginx]#
[root@localhost nginx]# ls html/
file
[root@localhost nginx]#

创建容器

# docker run -itd -p 8083:8082 -v /home/tjsp/nginx/html/file/:/home/upload/ --name tjsp1 cnbi-tjsp

# docker run -itd -p 8084:8082 -v /home/tjsp/nginx/html/file/:/home/upload/ --name tjsp2 cnbi-tjsp

解决高并发时添加

# docker run -itd -p 8087:8082 -v /home/tjsp/nginx/html/file/:/home/upload/ --name tjsp3 cnbi-tjsp

查看启动情况

注意:启动前需要运行redis,nginx配置,tomcat前端

# docker ps

[root@localhost nginx]# docker run -itd -p : -v /home/tjsp/nginx/html/file/:/home/upload/ --name tjsp1 cnbi-tjsp
ea2df7c4d1051978e67f04ea0d79b7e14081a60bf9c0adfd24b2884bdcefa213
[root@localhost nginx]#
[root@localhost nginx]# docker run -itd -p : -v /home/tjsp/nginx/html/file/:/home/upload/ --name tjsp2 cnbi-tjsp
f0ed2dd79b9fc4797e84c8f8523660cd38b88fdd5b4ebd971b02eeaa18ce8d1e
[root@localhost nginx]#
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0ed2dd79b9f cnbi-tjsp "java '-D java.secur…" minutes ago Up seconds 0.0.0.0:->/tcp tjsp2
ea2df7c4d105 cnbi-tjsp "java '-D java.secur…" minutes ago Up seconds 0.0.0.0:->/tcp tjsp1
7626b4b8f3c1 redis "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:->/tcp redis
39e65baa524a nginx:1.15. "nginx -g 'daemon of…" About an hour ago Up About a minute 0.0.0.0:->/tcp nginx_tjsp
78b5482a0a95 tomcat:8.5. "catalina.sh run" hours ago Up About a minute 0.0.0.0:->/tcp tomcat2
d41f7b69ebbf tomcat:8.5. "catalina.sh run" hours ago Up About a minute 0.0.0.0:->/tcp tomcat1

7、构建etl镜像

创建一个构建目录
# mkdir -p /home/tjsp/docker-etl
编写Dockerfile文件
# cd /home/tjsp/docker-etl/
# vi Dockerfile
FROM docker.io/huanwei/alpine-oraclejdk8
ADD app.jar /
ADD kettle5. /kettle5./
EXPOSE
ENTRYPOINT ["java","-D java.security.egd=file:/dev./urandom","-jar","/app.jar","--spring.profiles.active=dev207"]
VOLUME /tmp

构建镜像

# docker build -t tjsp-etl:latest .

[root@localhost docker-etl]# ls
Dockerfile app.jar kettle5. kettle5..zip
[root@localhost docker-etl]#
[root@localhost docker-etl]#
[root@localhost docker-etl]# docker build -t tjsp-etl:latest .
Sending build context to Docker daemon .444GB
Step / : FROM docker.io/huanwei/alpine-oraclejdk8
---> 28e66d63b8a4
Step / : ADD app.jar /
---> 39b216eea6a0
Step / : ADD kettle5. /kettle5./
---> dc9fd65a3fc6
Step / : EXPOSE
---> Running in 30a0948aea50
Removing intermediate container 30a0948aea50
---> 7bd690fb1d8e
Step / : ENTRYPOINT ["java","-D java.security.egd=file:/dev./urandom","-jar","/app.jar"]
---> Running in 94de1962e85f
Removing intermediate container 94de1962e85f
---> 54d952d6afb5
Step / : VOLUME /tmp
---> Running in 62b132e7c2ad
Removing intermediate container 62b132e7c2ad
---> 01892f2a0e9c
Successfully built 01892f2a0e9c
Successfully tagged tjsp-etl:latest
[root@localhost docker-etl]#

查看构建的镜像

# docker images

[root@localhost docker-etl]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tjsp-etl latest 01892f2a0e9c seconds ago 975MB
cnbi-tjsp latest 7161944b3e59 hours ago 280MB

8、创建etl镜像容器

创建容器

# docker run -itd --name tjsp-etl -p 8085:8085 tjsp-etl --network host

[root@localhost ~]# docker run -itd --name tjsp-etl -p : tjsp-etl --network host
e14d155e53192bd1027ee2ed4c0b8b145e41a964d6de824b91c23df3997a6548
[root@localhost ~]#
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e14d155e5319 tjsp-etl "java '-D java.secur…" seconds ago Up seconds 0.0.0.0:->/tcp tjsp-etl
b4ded4008023 cnbi-tjsp "java '-D java.secur…" hours ago Up minutes 0.0.0.0:->/tcp tjsp3
504c7fd1eec6 cnbi-tjsp "java '-D java.secur…" hours ago Up minutes 0.0.0.0:->/tcp tjsp2
6b3c6ddee4c6 cnbi-tjsp "java '-D java.secur…" hours ago Up minutes 0.0.0.0:->/tcp tjsp1
9fe494bf43bc tomcat:8.5. "catalina.sh run" hours ago Up About an hour 0.0.0.0:->/tcp tomcat3
7626b4b8f3c1 redis "docker-entrypoint.s…" hours ago Up hours 0.0.0.0:->/tcp redis
39e65baa524a nginx:1.15. "nginx -g 'daemon of…" hours ago Up hours 0.0.0.0:->/tcp nginx_tjsp
78b5482a0a95 tomcat:8.5. "catalina.sh run" hours ago Up hours 0.0.0.0:->/tcp tomcat2
d41f7b69ebbf tomcat:8.5. "catalina.sh run" hours ago Up hours 0.0.0.0:->/tcp tomcat1

9、进入etl镜像容器设置kettle并启动

添加kettle流程

# docker cp eas_to_brdb/ tjsp-etl:/root/

[root@localhost tjsp]# ll
total
drwxr-xr-x. root root Jul : docker-etl
drwxr-xr-x. root root Jul : docker-server
drwxr-xr-x. root root Jul : eas_to_brdb
drwxr-xr-x. root root Jul : etl_jar
drwxr-xr-x. root root Jul : nginx
drwxr-xr-x. root root Jul : tjsp_jar
drwxr-sr-x. root root May tomcat
drwxr-xr-x. root root Jul : tomcat1
drwxr-xr-x. root root Jul : tomcat2
drwxr-xr-x. root root Jul : tomcat3
[root@localhost tjsp]#
[root@localhost tjsp]#
[root@localhost tjsp]# docker cp eas_to_brdb/ tjsp-etl:/root/
[root@localhost tjsp]#

进入etl容器

# docker exec -it tjsp-etl /bin/sh

[root@localhost ~]# docker exec -it tjsp-etl /bin/sh
/ #
/ # ls
app.jar bin dev etc home kettle5. lib lib64 linuxrc logs media mnt proc root run sbin srv sys tmp usr var
/ #

设置kettle

/ # cd /root/
~ # ls -a
. .. .ash_history .kettle .oracle_jre_usage
~ #
~ # cd .kettle/
~/.kettle #
~/.kettle # ls
kettle.properties
~/.kettle #
# This file was generated by Pentaho Data Integration version 4.4..
#
# Here are a few examples of variables to set:
#
# PRODUCTION_SERVER = hercules
# TEST_SERVER = zeus
# DEVELOPMENT_SERVER = thor
#
# Note: lines like these with a # in front of it are comments
#
KETTLE_DEST_HOST=192.168.2.201
KETTLE_DEST_DATABASE=ORCL
KETTLE_DEST_PORT=
KETTLE_DEST_USER=BRDB_TJSP_1203
KETTLE_DEST_PASSWORD=cnbi2018 KETTLE_EAS_HOST=192.168.2.206
KETTLE_EAS_DATABASE=orcl
KETTLE_EAS_PORT=
KETTLE_EAS_USER=TJEAS
KETTLE_EAS_PASSWORD=
~/.kettle # pwd
/root/.kettle
~/.kettle #

启动kettle

授权

# chmod -R 777 /kettle5.4/

启动

# sh /kettle5.4/kitchen.sh -file /root/eas_to_brdb/eas_to_brdb.kjb

~/.kettle # chmod -R  /kettle5./
~/.kettle # cd ..
~ #
~ #
~ # ls -l
total
drwxr-xr-x root root Jul : eas_to_brdb
~ #
~ # sh /kettle5./kitchen.sh -file /root/eas_to_brdb/eas_to_brdb.kjb
Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
// :: - Kitchen - Start of run.
// :: - eas_to_brdb - Start of job execution
// :: - eas_to_brdb - Starting entry [load_dimension_data]
// :: - load_dimension_data - Starting entry [set_period_variable]
// :: - set_period_variable - Loading transformation from XML file [file:///root/eas_to_brdb/load_dimension_data/set_period_variable.ktr]
// :: - set_period_variable - Dispatching started for transformation [set_period_variable]
// :: - 获取传递期间. - Finished processing (I=, O=, R=, W=, U=, E=)
// :: - 设置期间变量. - Setting environment variables...
// :: - 设置期间变量. - Set variable ORGPERIOD to value []
// :: - 设置期间变量. - Set variable ENDPERIOD to value []

10、查看etl服务是否启动成功

监听端口

# lsof -i:8085

[root@localhost ~]# lsof -i:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr root 4u IPv6 0t0 TCP *: (LISTEN)

查看容器启动后10行日志

# docker logs --tail 10 -tf tjsp-etl

[root@localhost ~]# docker logs --tail  -tf tjsp-etl
--24T04::.092266671Z -- ::02.091 INFO --- [isson-netty--] o.r.c.pool.MasterPubSubConnectionPool : connections initialized for 192.168.2.207/192.168.2.207:
--24T04::.101305132Z -- ::02.100 DEBUG --- [ main] org.redisson.connection.DNSMonitor : DNS monitoring enabled; Current masters: {redis://192.168.2.207:6379=192.168.2.207/192.168.2.207:6379}, slaves: {}
--24T04::.727084940Z -- ::02.723 DEBUG --- [ main] o.mybatis.spring.SqlSessionFactoryBean : Scanned package: 'com.cnbi.cloud.etl.vo' for aliases
--24T04::.816255252Z -- ::02.811 INFO --- [ main] c.c.cloud.etl.config.FullSQLInterceptor : mybatis intercept dialect:oracle
--24T04::.816415640Z Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
--24T04::.820326603Z -- ::02.817 DEBUG --- [ main] o.mybatis.spring.SqlSessionFactoryBean : Parsed configuration file: 'class path resource [mybatis/mybatis.cfg.xml]'
--24T04::.936385155Z -- ::02.933 DEBUG --- [ main] o.mybatis.spring.SqlSessionFactoryBean : Parsed mapper file: 'class path resource [mybatis/mapper/formulaMapper.xml]'
--24T04::.948821805Z -- ::02.947 DEBUG --- [ main] o.mybatis.spring.SqlSessionFactoryBean : Parsed mapper file: 'class path resource [mybatis/mapper/synchronousDataMapper.xml]'
--24T04::.980705201Z -- ::02.979 DEBUG --- [ main] o.mybatis.spring.SqlSessionFactoryBean : Parsed mapper file: 'class path resource [mybatis/mapper/TableCensusMapper.xml]'
--24T04::.086914939Z -- ::07.086 INFO --- [ main] com.cnbi.cloud.ETLApplication : Started ETLApplication in 12.023 seconds (JVM running for 13.086)

11、后台添加openoffice服务

Dockerfile文件变动如下:

FROM centos
ADD app.jar /
ADD Apache_OpenOffice_4..6_Linux_x86-64_install-rpm_zh-CN.tar.gz /tmp/
ADD chinses.tar.gz /usr/share/fonts/
RUN cd /tmp && \
yum install -y zh-CN/RPMS/*.rpm && \
yum install -y java-1.8.0-openjdk.x86_64 && \
#yum install -y java-1.8.0-openjdk*
yum clean all && \
rm -rf zh-CN && \
cd /usr/share/fonts/ && \
#tar zxvf chinses.tar.gz && \
chmod -R 755 /usr/share/fonts && \
mkfontscale && \
mkfontdir && \
fc-cache -fv
EXPOSE 8082
ENV JAVA_HOME /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
ENTRYPOINT ["java","-D java.security.egd=file:/dev./urandom","-jar","/app.jar","--spring.profiles.active=dev207"]
VOLUME /tmp

重新构建镜像

# docker build -t cnbi-tjsp:v3 .

[root@localhost ~]# cd /home/tjsp/docker-server/
[root@localhost docker-server]#
[root@localhost docker-server]# ls
Apache_OpenOffice_4..6_Linux_x86-64_install-rpm_zh-CN.tar.gz Dockerfile Dockerfile.bak1 app.jar chinses.tar.gz
[root@localhost docker-server]#

查看镜像文件

[root@localhost docker-server]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cnbi-tjsp v3 74235ac7e25d hours ago .28GB
cnbi-tjsp v2 20537b2847fc hours ago 288MB

根据镜像创建容器

# docker run -itd -p 8083:8082 -v /home/tjsp/nginx/html/file/:/home/upload/ --name tjsp1 cnbi-tjsp

12、office服务添加openoffice服务

创建一个构建镜像目录

# mkdir -p /home/tjsp/docker-office

[root@docker-servers ~]# cd /home/tjsp/
[root@docker-servers tjsp]#
[root@docker-servers tjsp]# ls
docker-etl docker-office docker-server nginx nginx.tar.gz tomcat tomcat1 tomcat2 tomcat3 tomcat.tar.gz
[root@docker-servers tjsp]#
[root@docker-servers tjsp]# cd docker-office/
[root@docker-servers docker-office]#
[root@docker-servers docker-office]# ls
Apache_OpenOffice_4..6_Linux_x86-64_install-rpm_zh-CN.tar.gz apache-tomcat-8.0..tar.gz chinses.tar.gz Dockerfile

Dockerfile文件如下:

FROM centos:

MAINTAINER djl "[email protected]"

ADD Apache_OpenOffice_4..6_Linux_x86-64_install-rpm_zh-CN.tar.gz /tmp/
ADD chinses.tar.gz /usr/share/fonts/
ADD apache-tomcat-8.0..tar.gz /usr/local/ WORKDIR /tmp/
RUN yum install -y zh-CN/RPMS/*.rpm && \
yum install -y java-1.8.0-openjdk.x86_64 && \
yum clean all && \
rm -rf zh-CN WORKDIR /etc/
RUN mv /etc/localtime /etc/localtime.bak && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime WORKDIR /usr/share/fonts/
RUN chmod -R 755 /usr/share/fonts && \
mkfontscale && \
mkfontdir && \
fc-cache -fv
EXPOSE 8080
ENV JAVA_HOME /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
CMD sh /usr/local/tomcat/bin/catalina.sh run

构建镜像

# docker build -t tjsp-office:v1 .

查看镜像

# docker images

[root@docker-servers ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tjsp-office v1 045b278abebc About an hour ago 1.18 GB
tjsp-etl v1 910ec0ec9bb2 hours ago MB
cnbi-tjsp v1 138868acba1e hours ago 1.42 GB
nginx 1.15. 2bcb04bdb83f months ago MB
centos 9f38484d220f months ago MB
redis 5.0. 0f88f9be5839 months ago MB
tomcat 8.5. 38bdcf7a367c months ago MB
docker.io/huanwei/alpine-oraclejdk8 latest 28e66d63b8a4 years ago MB

根据镜像创建容器

# docker run -p 8086:8080 --name tjsp_office -h tjsp_office -v /home/tjsp/tomcat3:/usr/local/tomcat -d tjsp-office:v1

四、后期修改维护更新说明

1、查看项目运行的所有容器

# docker ps

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b4ded4008023 cnbi-tjsp "java '-D java.secur…" hours ago Up hours 0.0.0.0:->/tcp tjsp3
504c7fd1eec6 cnbi-tjsp "java '-D java.secur…" hours ago Up hours 0.0.0.0:->/tcp tjsp2
6b3c6ddee4c6 cnbi-tjsp "java '-D java.secur…" hours ago Up hours 0.0.0.0:->/tcp tjsp1
9fe494bf43bc tomcat:8.5. "catalina.sh run" hours ago Up hours 0.0.0.0:->/tcp tomcat3
7626b4b8f3c1 redis "docker-entrypoint.s…" hours ago Up hours 0.0.0.0:->/tcp redis
39e65baa524a nginx:1.15. "nginx -g 'daemon of…" hours ago Up hours 0.0.0.0:->/tcp nginx_tjsp
78b5482a0a95 tomcat:8.5. "catalina.sh run" hours ago Up hours 0.0.0.0:->/tcp tomcat2
d41f7b69ebbf tomcat:8.5. "catalina.sh run" hours ago Up hours 0.0.0.0:->/tcp tomcat1

2、查看项目所需要的镜像

# docker images

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tjsp-etl latest 01892f2a0e9c hours ago 975MB
cnbi-tjsp latest 7161944b3e59 hours ago 280MB
nginx 1.15. 2bcb04bdb83f months ago 109MB
redis latest 82629e941a38 months ago 95MB
tomcat 8.5. 38bdcf7a367c months ago 546MB
huanwei/alpine-oraclejdk8 latest 28e66d63b8a4 years ago 167MB

3、设置容器开机自启动

# docker update --restart=always xxx

[root@localhost ~]# docker update --restart=always tjsp1
tjsp1
[root@localhost ~]# docker update --restart=always tjsp2
tjsp2
[root@localhost ~]# docker update --restart=always tjsp3
tjsp3
[root@localhost ~]# docker update --restart=always tomcat1
tomcat1
[root@localhost ~]# docker update --restart=always tomcat2
tomcat2
[root@localhost ~]# docker update --restart=always tomcat3
tomcat3
[root@localhost ~]# docker update --restart=always redis
redis
[root@localhost ~]# docker update --restart=always nginx_tjsp
nginx_tjsp
[root@localhost ~]#

参考博客:

用 Docker 构建、运行、发布来一个 Spring Boot 应用

https://blog.csdn.net/kkkloveyou/article/details/50942275

end

05-02 06:50