In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
profile
Based on docker container and docker-compose, so you need to teach yourself the basic use of docker in Linux environment.
Use two tomcats as servers for Load Balancer
1. Use docker to pull tomcat and nginx images
Pull nginx reference
Pull tomcat reference
2. Create two tomcat services using docker-compose
Create a new tomcat directory, create a docker-compose.yml file in this directory, and enter the following:
version: '3'services: tomcat1: image: tomcat container_name: tomcat1 ports: - 9090:8080 tomcat2: image: tomcat container_name: tomcat2 ports: - 9091:8080
Run the following command in the same directory as docker-compose.yml to start the container (-d means background running)
docker-compose up -d
View docker container list after success
command
docker ps
The resulting example has two containers tomcat1 and tomcat2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES271dd3610d1d tomcat "catalina.sh run" 58 minutes ago Up 58 minutes 0.0.0.0:9091->8080/tcp tomcat2fa19d20f0022 tomcat "catalina.sh run" 58 minutes ago Up 58 minutes 0.0.0.0:9090->8080/tcp tomcat1
Enter the container interactively and modify the home page content to distinguish between two tomcats (tomcat is an example below)
command
docker exec -it fa19d20f0022 bash
Add content to homepage
echo "9090" >> webapps/ROOT/index.jsp
3. Create nginx services
Create a new nginx directory, create a docker-compose.yml file in this directory, and enter the following:
version: '3.1'services: nginx: restart: always image: nginx container_name: nginx ports: - 81:80 volumes: - ./ conf/nginx.conf:/etc/nginx/nginx.conf
Since docker-compose automatically treats/conf/nginx.conf as a folder, you need to create a conf directory under the nginx directory before creating the container, create an nginx.conf file under the conf directory, and enter the following:
user nginx; worker_processes 1; events { worker_connections 1024;}http { upstream myapp1 { server [server ip]:9090 weight=10; server [server ip]:9091 weight=10; } server { listen 80; server_name [server ip]; location / { proxy_pass http://myapp1; } }}
Run in the same directory as docker-compose.yml
docker-compose up -d
4. Visit [server ip]:81 URL, refresh several times, observe the switch between the two tomcat services
The above is all the content of this article, I hope to help everyone's study, but also hope that everyone a lot of support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.