Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy Tomcat cluster and Nginx load balance based on Docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to deploy Tomcat cluster and Nginx load balance based on Docker, which has certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article. Let's take a look at it.

Structure diagram:

Here only as a kind of learning, generally this kind of load, Nginx is put on the host side, JavaWeb (Tomcat) application is put in the container.

Effect.

Create a new folder.

Ngixn Ngixn image to make cd uag_nginx/# to store the configuration file mkdir nginxvim Dockerfile

Dockerfile file content

FROM nginxLABEL maintainer= "uag" ENV REFRESHED_AT 2021-08-27EXPOSE 8099

Build the contents of the nginx profile

The configuration file for this is shared with the container internally through the-v parameter while the container is running. It is convenient to change parameters later.

Cd. / nginxvim nginx.conf

Nginx.conf profile content

User nginx;worker_processes auto;error_log / var/log/nginx/error.log notice;pid / var/run/nginx.pid;daemon off;events {worker_connections 1024;} http {include / etc/nginx/mime.types; default_type application/octet-stream Log_format main'$upstream_addr-$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"; access_log / var/log/nginx/access.log main; sendfile on; # tcp_nopush on; keepalive_timeout 65 # gzip on; include / etc/nginx/conf.d/*.conf; server {listen 8099; server_name localhost; root / var/www/html/; index index.html index.htm; access_log / var/log/nginx/default_access.log main; error_log / var/log/nginx/default_error.log Location / {proxy_pass http://backend;} location ~. * {proxy_pass http://backend; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} # load upstream backend {server 172.23.231.190 upstream backend 8069; server 172.23.231.190 upstream backend 8079; server 172.23.231.190 upstream backend 8089;}}

Configure the load: 172.23.231.190 is the host IP,8069,8079,8089 as the corresponding Java Web exposed application port.

# here configure load upstream backend {server 172.23.231.190 server 8069; server 172.23.231.190 server 8079; server 172.23.231.190 server 8089;}

Build a Nginx image

Docker build-t uag/uag_nginx.

Second, java Web (Tomcat) uses images to build cd uag_tomcat8/vim Dockerfile

Dockerfile file content

FROM dordoka/tomcatMAINTAINER LIRUILONGCOPY UAWeb.war / opt/tomcat/webapps/UAWeb.warEXPOSE 8080ENTRYPOINT ["/ opt/tomcat/bin/catalina.sh", "run"]

Upload the corresponding War package

LsDockerfile UAWeb.war

Build an image

Docker build-t uag/uag_tomcat.

Third, run the container Nginx image docker run-d-p 8099-- name uag_nginx-v $PWD/nginx/nginx.conf:/etc/nginx/nginx.conf uag/uag_nginx nginx

Java Web (Tomcat) Mirror

Docker run-it-d-p 8089 it 8080-- name uag_app_1 uag/uag_tomcat docker run-it-d-p 8079 name uag_app_1 uag/uag_tomcat docker run-- name uag_app_2 uag/uag_tomcat docker run-it-d-p 8069 name uag_app_1 uag/uag_tomcat docker run-- name uag_app_3 uag/uag_tomcat

View the running container

Browser access

View the load mode: the way the new process

View load mode:-volumes-from mode

Dockerfile file

FROM nginxLABEL maintainer= "uag" ENV REFRESHED_AT 2021-08-27VOLUME / var/log/nginx/EXPOSE 80 ┌── (liruilong ㉿ Liruilong)-[/ mnt/e/docker/uag/uag_nginx] └─ $docker run-it-rm-- volumes-from nginx_log centos cat / var/log/nginx/default_access.log172.23.231.190:8069-172.17.0.1-- [30/Aug/2021:12:55:02 + 0000] "GET / UAWeb / services/listServices HTTP/1.1 "12660" http://127.0.0.1:8099/UAWeb/"Mozilla/5.0 (Windows NT 10.0 Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 "-" 172.23.231.190 KHTML 8079-172.17.0.1-- [30/Aug/2021:12:55:02 + 0000] "GET / UAWeb/axis2-web/css/axis-style.css HTTP/1.1" 200 1587 "http://127.0.0.1:8099/UAWeb/services/listServices"" Mozilla/5.0 (Windows NT 10.0; Win64 X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 "-" 172.23.231.190 KHTML 8069-172.17.0.1-- [30/Aug/2021:12:55:02 + 0000] "GET / UAWeb/axis2-web/images/asf-logo.gif HTTP/1.1" 200 5866 "http://127.0.0.1:8099/UAWeb/services/listServices"" Mozilla/5.0 (Windows NT 10.0; Win64 X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 "-" 172.23.231.190 KHTML 8079-172.17.0.1-- [30/Aug/2021:12:55:02 + 0000] "GET / UAWeb/axis2-web/images/axis_l.jpg HTTP/1.1" 200 12340 "http://127.0.0.1:8099/UAWeb/services/listServices"" Mozilla/5.0 (Windows NT 10.0; Win64 X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 "-" 172.23.231.190 KHTML 8089-172.17.0.1-- [30/Aug/2021:12:55:03 + 0000] "GET / UAWeb/services/listServices HTTP/1.1" 200 12660 "http://127.0.0.1:8099/UAWeb/"" Mozilla/5.0 (Windows NT 10.0; Win64 X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 "-" 172.23.231.190 KHTML 8069-172.17.0.1-- [30/Aug/2021:12:55:03 + 0000] "GET / UAWeb/axis2-web/images/asf-logo.gif HTTP/1.1" 200 5866 "http://127.0.0.1:8099/UAWeb/services/listServices"" Mozilla/5.0 (Windows NT 10.0; Win64 X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92

Build an image upload repository:

Well, you need to sign up for a Docker Hub account, and then log in. You need to add the account name / before the image.

┌── (liruilong ㉿ Liruilong)-[/ mnt/e/docker/uag/uag_nginx] └─ $docker push liruilong/nginx_logThe push refers to repository [docker.io/liruilong/nginx_log] An image does not exist locally with the tag: liruilong/nginx_log ┌── (liruilong ㉿ Liruilong)-[/ mnt/e/docker/uag/uag_nginx] └─ $docker tag 9c9af0362eb9 liruilong/nginx_log ┌── (liruilong ㉿ Liruilong)-[/ mnt/e/docker/uag/uag_nginx] └─ $docker push liruilong/nginx_logThe push refers to repository [docker.io/liruilong/nginx_log] fb04ab8effa8: Pushed8f736d52032f: Pushed009f1d338b57: Pushed678bbd796838: Pushedd1279c519351: Pushedf68ef921efae: Pushedlatest: digest: sha256:2af7e8aeab84e8a816caf6b0342e1a45f95c7089ff52578040ea3a4c28a943c7 size: 1570 ┌── (liruilong ㉿ Liruilong)-[/ mnt/e/docker/uag/uag_nginx] └─ $docker push liruilong/nginx_log:tagname # pull the image

Thank you for reading this article carefully. I hope the article "how to deploy Tomcat clusters and Nginx load balancing based on Docker" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report