docker實戰部署Javaweb項目

1、部署環境說明

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-oraclejdk8html

2、安裝docker服務

配置阿里yum源並安裝docker前端

# yum install docker -yjava

3、項目部署

一、準備工做

拉取以下鏡像linux

# docker imagesnginx

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

拉取命令以下:web

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

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

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

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

鏡像重命名

# 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.10 redis version: redis/5.0.3 tomcat version: tomcat/8.5.30 alpine-oraclejdk8

二、建立兩個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.30 /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 8081:8080 --name tomcat1 -h Front-end1 -v /home/tjsp/tomcat1:/usr/local/tomcat -d tomcat:8.5.30 d41f7b69ebbf9717629b220907fc7c88e8d106f2b99a805c6b0465b4bc49f484 [root@localhost tjsp]# [root@localhost tjsp]# docker run -p 8082:8080 --name tomcat2 -h Front-end2 -v /home/tjsp/tomcat2:/usr/local/tomcat -d tomcat:8.5.30 78b5482a0a9546f5355fccb8f28bf4e08751f58e74b8a3b66af36a775ae31788 [root@localhost tjsp]#

查看運行狀態

# docker ps

[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 78b5482a0a95 tomcat:8.5.30                                          "catalina.sh run"        About an hour ago   Up About an hour    0.0.0.0:8082->8080/tcp tomcat2 d41f7b69ebbf tomcat:8.5.30                                          "catalina.sh run"        About an hour ago   Up About an hour    0.0.0.0:8081->8080/tcp tomcat1 1287b583d3b7 tomcat:8.5.30                                          "/bin/bash"              About an hour ago   Up About an hour    8080/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 8086:8080 --name tomcat3 -h tjsp_office -v /home/tjsp/tomcat3:/usr/local/tomcat -d tomcat:8.5.30 9fe494bf43bc446f9f021d19e25ec5e030e6031c8fc65dcc8f08609f3b4bc946 [root@localhost tjsp]# [root@localhost tjsp]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9fe494bf43bc tomcat:8.5.30                                          "catalina.sh run"        6 seconds ago       Up 5 seconds        0.0.0.0:8086->8080/tcp   tomcat3

三、建立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.10 0b02f6f222ef38aa2f39fa7ac5d5a588b5df24bb6d7e28fba90aa55b0a4bf82e [root@localhost tjsp]# [root@localhost tjsp]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0b02f6f222ef nginx:1.15.10                                          "nginx -g 'daemon of…"   4 seconds ago       Up 3 seconds        80/tcp nginx_test 78b5482a0a95 tomcat:8.5.30                                          "catalina.sh run"        About an hour ago   Up About an hour    0.0.0.0:8082->8080/tcp tomcat2 d41f7b69ebbf tomcat:8.5.30                                          "catalina.sh run"        About an hour ago   Up About an hour    0.0.0.0:8081->8080/tcp tomcat1 1287b583d3b7 tomcat:8.5.30                                          "/bin/bash"              About an hour ago   Up About an hour    8080/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 7080:80 -v /home/tjsp/nginx:/etc/nginx/ -d nginx:1.15.10 39e65baa524a62e2a07ad0ccc035baf829f3f9736148529b79d18452011bf390 [root@localhost nginx]# [root@localhost nginx]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 39e65baa524a nginx:1.15.10                                          "nginx -g 'daemon of…"   4 seconds ago       Up 3 seconds        0.0.0.0:7080->80/tcp nginx_tjsp 0b02f6f222ef nginx:1.15.10                                          "nginx -g 'daemon of…"   3 minutes ago       Up 3 minutes        80/tcp nginx_test 78b5482a0a95 tomcat:8.5.30                                          "catalina.sh run"        About an hour ago   Up About an hour    0.0.0.0:8082->8080/tcp tomcat2 d41f7b69ebbf tomcat:8.5.30                                          "catalina.sh run"        About an hour ago   Up About an hour    0.0.0.0:8081->8080/tcp tomcat1 1287b583d3b7 tomcat:8.5.30                                          "/bin/bash"              About an hour ago   Up About an hour    8080/tcp                 test

修改nginx配置文件

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

配置文件以下:

user root; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; ## Proxy upstream tjsp_client_proxy { server 192.168.2.207:8081 weight=1 max_fails=2 fail_timeout=30s; server 192.168.2.207:8082 weight=1 max_fails=2 fail_timeout=30s; } upstream tjsp_server_proxy { server 192.168.2.207:8083 weight=1 max_fails=2 fail_timeout=30s; server 192.168.2.207:8084 weight=1 max_fails=2 fail_timeout=30s; server 192.168.2.207:8087 weight=1 max_fails=2 fail_timeout=30s; } upstream etl_server_proxy { server 192.168.2.207:8085 weight=1 max_fails=2 fail_timeout=30s; #server 172.17.8.20:8086 weight=1 max_fails=2 fail_timeout=30s; } upstream exp_server_proxy { server 192.168.2.207:8086 weight=1 max_fails=2 fail_timeout=30s; } server { listen 80; server_name localhost; error_page 500 502 503 504  /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"; } } } 
View Code

四、建立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 6379:6379 -d redis redis-server --requirepass "123456" --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]#

 五、構建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 8082 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 1/5 : FROM docker.io/huanwei/alpine-oraclejdk8 ---> 28e66d63b8a4 Step 2/5 : ADD /app.jar //  ---> 063e68f2e01a Step 3/5 : EXPOSE 8082
 ---> Running in 9ab4a3c0fc63 Removing intermediate container 9ab4a3c0fc63 ---> 7522d6d8ea7f Step 4/5 : ENTRYPOINT ["java","-D java.security.egd=file:/dev./urandom","-jar","/app.jar"] ---> Running in 3726768330c0 Removing intermediate container 3726768330c0 ---> d6ddeff92429 Step 5/5 : 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        3 minutes ago       280MB

六、建立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 8083:8082 -v /home/tjsp/nginx/html/file/:/home/upload/ --name tjsp1 cnbi-tjsp ea2df7c4d1051978e67f04ea0d79b7e14081a60bf9c0adfd24b2884bdcefa213 [root@localhost nginx]# [root@localhost nginx]# docker run -itd -p 8084:8082 -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…"   16 minutes ago      Up 5 seconds                0.0.0.0:8084->8082/tcp tjsp2 ea2df7c4d105 cnbi-tjsp                                              "java '-D java.secur…"   17 minutes ago      Up 8 seconds                0.0.0.0:8083->8082/tcp tjsp1 7626b4b8f3c1 redis "docker-entrypoint.s…"   About an hour ago   Up About an hour            0.0.0.0:6379->6379/tcp redis 39e65baa524a nginx:1.15.10                                          "nginx -g 'daemon of…"   About an hour ago   Up About a minute           0.0.0.0:7080->80/tcp nginx_tjsp 78b5482a0a95 tomcat:8.5.30                                          "catalina.sh run"        2 hours ago         Up About a minute           0.0.0.0:8082->8080/tcp tomcat2 d41f7b69ebbf tomcat:8.5.30                                          "catalina.sh run"        2 hours ago         Up About a minute           0.0.0.0:8081->8080/tcp   tomcat1

 七、構建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.4 /kettle5.4/ EXPOSE 8085 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.4  kettle5.4.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 1.444GB Step 1/6 : FROM docker.io/huanwei/alpine-oraclejdk8 ---> 28e66d63b8a4 Step 2/6 : ADD app.jar /
 ---> 39b216eea6a0 Step 3/6 : ADD kettle5.4 /kettle5.4/
 ---> dc9fd65a3fc6 Step 4/6 : EXPOSE 8085
 ---> Running in 30a0948aea50 Removing intermediate container 30a0948aea50 ---> 7bd690fb1d8e Step 5/6 : ENTRYPOINT ["java","-D java.security.egd=file:/dev./urandom","-jar","/app.jar"] ---> Running in 94de1962e85f Removing intermediate container 94de1962e85f ---> 54d952d6afb5 Step 6/6 : 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        47 seconds ago 975MB cnbi-tjsp                                              latest              7161944b3e59        23 hours ago        280MB

八、建立etl鏡像容器

建立容器

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

[root@localhost ~]# docker run -itd --name tjsp-etl -p 8085:8085 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…"   11 seconds ago      Up 10 seconds       0.0.0.0:8085->8085/tcp   tjsp-etl b4ded4008023 cnbi-tjsp                                              "java '-D java.secur…"   21 hours ago        Up 44 minutes       0.0.0.0:8087->8082/tcp tjsp3 504c7fd1eec6 cnbi-tjsp                                              "java '-D java.secur…"   21 hours ago        Up 44 minutes       0.0.0.0:8084->8082/tcp tjsp2 6b3c6ddee4c6 cnbi-tjsp                                              "java '-D java.secur…"   21 hours ago        Up 44 minutes       0.0.0.0:8083->8082/tcp tjsp1 9fe494bf43bc tomcat:8.5.30                                          "catalina.sh run"        25 hours ago        Up About an hour    0.0.0.0:8086->8080/tcp tomcat3 7626b4b8f3c1 redis "docker-entrypoint.s…"   26 hours ago        Up 26 hours         0.0.0.0:6379->6379/tcp redis 39e65baa524a nginx:1.15.10                                          "nginx -g 'daemon of…"   26 hours ago        Up 25 hours         0.0.0.0:7080->80/tcp nginx_tjsp 78b5482a0a95 tomcat:8.5.30                                          "catalina.sh run"        27 hours ago        Up 25 hours         0.0.0.0:8082->8080/tcp tomcat2 d41f7b69ebbf tomcat:8.5.30                                          "catalina.sh run"        27 hours ago        Up 25 hours         0.0.0.0:8081->8080/tcp   tomcat1

九、進入etl鏡像容器設置kettle並啓動

添加kettle流程

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

[root@localhost tjsp]# ll total 0 drwxr-xr-x.  3 root root  77 Jul 24 14:28 docker-etl drwxr-xr-x.  2 root root  39 Jul 23 15:46 docker-server drwxr-xr-x.  4 root root  83 Jul 23 17:10 eas_to_brdb drwxr-xr-x.  2 root root   6 Jul 24 09:38 etl_jar drwxr-xr-x.  4 root root 211 Jul 23 18:40 nginx drwxr-xr-x.  2 root root  21 Jul 24 11:45 tjsp_jar drwxr-sr-x. 11 root root 197 May  5  2018 tomcat drwxr-xr-x. 11 root root 197 Jul 23 09:11 tomcat1 drwxr-xr-x. 11 root root 197 Jul 23 09:20 tomcat2 drwxr-xr-x. 11 root root 197 Jul 23 11:46 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.4 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.0. # # 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=1521 KETTLE_DEST_USER=BRDB_TJSP_1203 KETTLE_DEST_PASSWORD=cnbi2018 KETTLE_EAS_HOST=192.168.2.206 KETTLE_EAS_DATABASE=orcl KETTLE_EAS_PORT=1521 KETTLE_EAS_USER=TJEAS KETTLE_EAS_PASSWORD=123456
~/.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 777 /kettle5.4/
~/.kettle # cd .. ~ # ~ # ~ # ls -l total 0 drwxr-xr-x    4 root     root            83 Jul 23 09:10 eas_to_brdb ~ # ~ # sh /kettle5.4/kitchen.sh -file /root/eas_to_brdb/eas_to_brdb.kjb Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
2019/07/24 06:39:26 - Kitchen - Start of run. 2019/07/24 06:39:27 - eas_to_brdb - Start of job execution 2019/07/24 06:39:27 - eas_to_brdb - Starting entry [load_dimension_data] 2019/07/24 06:39:27 - load_dimension_data - Starting entry [set_period_variable] 2019/07/24 06:39:27 - set_period_variable - Loading transformation from XML file [file:///root/eas_to_brdb/load_dimension_data/set_period_variable.ktr]
2019/07/24 06:39:27 - set_period_variable - Dispatching started for transformation [set_period_variable] 2019/07/24 06:39:27 - 獲取傳遞期間.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0) 2019/07/24 06:39:28 - 設置期間變量.0 - Setting environment variables... 2019/07/24 06:39:28 - 設置期間變量.0 - Set variable ORGPERIOD to value [201808] 2019/07/24 06:39:28 - 設置期間變量.0 - Set variable ENDPERIOD to value [201808]

十、查看etl服務是否啓動成功

監聽端口

# lsof -i:8085

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

查看容器啓動後10行日誌

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

[root@localhost ~]# docker logs --tail 10 -tf tjsp-etl 2019-07-24T04:30:02.092266671Z 2019-07-24 04:30:02.091  INFO 1 --- [isson-netty-1-2] o.r.c.pool.MasterPubSubConnectionPool    : 1 connections initialized for 192.168.2.207/192.168.2.207:6379
2019-07-24T04:30:02.101305132Z 2019-07-24 04:30:02.100 DEBUG 1 --- [           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: {}
2019-07-24T04:30:02.727084940Z 2019-07-24 04:30:02.723 DEBUG 1 --- [           main] o.mybatis.spring.SqlSessionFactoryBean   : Scanned package: 'com.cnbi.cloud.etl.vo' for aliases 2019-07-24T04:30:02.816255252Z 2019-07-24 04:30:02.811  INFO 1 --- [ main] c.c.cloud.etl.config.FullSQLInterceptor : mybatis intercept dialect:oracle 2019-07-24T04:30:02.816415640Z Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter. 2019-07-24T04:30:02.820326603Z 2019-07-24 04:30:02.817 DEBUG 1 --- [           main] o.mybatis.spring.SqlSessionFactoryBean   : Parsed configuration file: 'class path resource [mybatis/mybatis.cfg.xml]'
2019-07-24T04:30:02.936385155Z 2019-07-24 04:30:02.933 DEBUG 1 --- [           main] o.mybatis.spring.SqlSessionFactoryBean   : Parsed mapper file: 'class path resource [mybatis/mapper/formulaMapper.xml]'
2019-07-24T04:30:02.948821805Z 2019-07-24 04:30:02.947 DEBUG 1 --- [           main] o.mybatis.spring.SqlSessionFactoryBean   : Parsed mapper file: 'class path resource [mybatis/mapper/synchronousDataMapper.xml]'
2019-07-24T04:30:02.980705201Z 2019-07-24 04:30:02.979 DEBUG 1 --- [           main] o.mybatis.spring.SqlSessionFactoryBean   : Parsed mapper file: 'class path resource [mybatis/mapper/TableCensusMapper.xml]'
2019-07-24T04:30:07.086914939Z 2019-07-24 04:30:07.086  INFO 1 --- [           main] com.cnbi.cloud.ETLApplication            : Started ETLApplication in 12.023 seconds (JVM running for 13.086)

十一、後臺添加openoffice服務

Dockerfile文件變更以下:

FROM centos ADD app.jar / ADD Apache_OpenOffice_4.1.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.1.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        2 hours ago         1.28GB cnbi-tjsp                                              v2                  20537b2847fc        4 hours ago         288MB

根據鏡像建立容器

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

十二、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.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz  apache-tomcat-8.0.30.tar.gz  chinses.tar.gz  Dockerfile

Dockerfile文件以下:

FROM centos:7 MAINTAINER djl "djl@cnbisoft.com" ADD Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz /tmp/ ADD chinses.tar.gz /usr/share/fonts/ ADD apache-tomcat-8.0.30.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        15 hours ago        975 MB cnbi-tjsp                             v1                  138868acba1e        20 hours ago        1.42 GB nginx 1.15.10             2bcb04bdb83f        4 months ago        109 MB centos 7                   9f38484d220f        4 months ago        202 MB redis 5.0.3               0f88f9be5839        5 months ago        95 MB tomcat 8.5.30              38bdcf7a367c        15 months ago       546 MB docker.io/huanwei/alpine-oraclejdk8   latest              28e66d63b8a4        2 years ago         167 MB

根據鏡像建立容器

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

4、後期修改維護更新說明

一、查看項目運行的全部容器

# docker ps

[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b4ded4008023 cnbi-tjsp                                              "java '-D java.secur…"   26 hours ago        Up 6 hours          0.0.0.0:8087->8082/tcp tjsp3 504c7fd1eec6 cnbi-tjsp                                              "java '-D java.secur…"   26 hours ago        Up 6 hours          0.0.0.0:8084->8082/tcp tjsp2 6b3c6ddee4c6 cnbi-tjsp                                              "java '-D java.secur…"   26 hours ago        Up 6 hours          0.0.0.0:8083->8082/tcp tjsp1 9fe494bf43bc tomcat:8.5.30                                          "catalina.sh run"        30 hours ago        Up 6 hours          0.0.0.0:8086->8080/tcp tomcat3 7626b4b8f3c1 redis "docker-entrypoint.s…"   32 hours ago        Up 32 hours         0.0.0.0:6379->6379/tcp redis 39e65baa524a nginx:1.15.10                                          "nginx -g 'daemon of…"   32 hours ago        Up 31 hours         0.0.0.0:7080->80/tcp nginx_tjsp 78b5482a0a95 tomcat:8.5.30                                          "catalina.sh run"        33 hours ago        Up 2 hours          0.0.0.0:8082->8080/tcp tomcat2 d41f7b69ebbf tomcat:8.5.30                                          "catalina.sh run"        33 hours ago        Up 2 hours          0.0.0.0:8081->8080/tcp   tomcat1

二、查看項目所須要的鏡像

# docker images

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

三、設置容器開機自啓動

# 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

相關文章
相關標籤/搜索