Docker deploy Nginx, Tomcat cluster

Tomcat cluster composed of a plurality of tomcat, the benefits of using Nginx can achieve load balancing and static and dynamic separation.
The advantage of using Docker is ~ ~ ~ we do not need complex configuration, only need to perform simple commands can pull existing official docker mirror, then we will be able to run an instance of a single command. For multiple Tomcat, we use the same image, then use simple commands, you can create a different container instance tomcat.

Docker deploy Nginx, Tomcat cluster
1. pull to mirroring

$ docker pull tomcat:8-jre8-alpine
$ docker pull nginx:latest
$ docker images

Docker deploy Nginx, Tomcat cluster
2. Create a tomcat webapps folder and exchange folders, and create a container

$ docker run --name tomcat1 -p 18080:8080 -v $PWD/webapps:/usr/local/tomcat/webapps  -d tomcat:8-jre8-alpine
# cc8d9b8bc8a90d0768df15f94ae2cb37694021cf637d0610d10eaee669b0d5bad
$ docker run --name tomcat2 -p 28080:8080 -v $PWD/webapps:/usr/local/tomcat/webapps  -d tomcat:8-jre8-alpine
# 711e6a6fd1a3f6d088b8b6f527b9c558114bdd5e1592b03a18cb3abaaaf08815

Create a folder nginx.

$ docker run --name tmp-nginx-container -d nginx
$ docker cp tmp-nginx-container:/etc/nginx/nginx $PWD/conf
$ docker cp mynginx:/usr/share/nginx/html $PWD/html
$ docker cp mynginx:/var/log/nginx  $PWD/logs
$ docker rm -f tmp-nginx-container

Running nginx

$ docker run -p 80:80 -p 8080:8080 --name mynginx -v $PWD/html:/usr/share/nginx/html -v $PWD/conf:/etc/nginx -v $PWD/logs:/var/log/nginx -d nginx

-p 18080: 8080: 8080 to map the host to a port of the container port 18080
-v mount directory
specific parameter commands self google, are simple common commands.

$ docker container ls

Docker deploy Nginx, Tomcat cluster

  1. Their projects into local webapps directory
    in order to facilitate the distinction engineering, my project home page for the local IP and port, 18080 and 28080, respectively, using the access test project, you can get the information as shown below.
    Docker deploy Nginx, Tomcat cluster
    Docker deploy Nginx, Tomcat cluster
    4. Set Nginx profile
    80 chrome access server port, shown below:
    Docker deploy Nginx, Tomcat cluster
    Nginx configuration file is nginx.conf, open the folder, the configuration information is not found inside the ports, but there is a:
    include /etc/nginx/conf.d/*.conf;

    This is all the configuration files in the directory conf.d all join. The welcome page which is a set of files in its directory named default.conf the set.
    Imitate this document, we have to create your own tomcat.conf.
    Then their own configuration information.
    Docker deploy Nginx, Tomcat cluster

  2. Test
    input nginx address and tomcat server 8080 port
    Docker deploy Nginx, Tomcat cluster
    entered more than once, we can find our tomcat corresponding address will change, this is the access to the different tomcat.
    Docker deploy Nginx, Tomcat cluster
    6. Late extension
    we can modify different equilibrium strategies, such as modifying the weight values, and set up backup servers and other ways to achieve different functions.
    In addition to load balancing, we can also carry out static and dynamic files were separated, and this is one of the important features of Nginx.

Guess you like

Origin blog.51cto.com/13981400/2401249