Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ Docker + Nginx + Tomcat7 simple load balancing configuration     - Ubuntu System Log Configuration / var / log / messages (Linux)

- top command causes the system load increases (Linux)

- Linux regex awk Comments (Linux)

- Hibernate4 The Hello World (basic environmental structures) (Programming)

- Use exp exported EXP-00091 error (Database)

- Ubuntu 14.04 Nvidia proprietary drivers for install two graphic cards (Linux)

- Use NTFS-3G to mount NTFS partitions under Linux U disk and removable hard disk (Linux)

- Ubuntu under VirtualBox virtual machine serial port settings (Linux)

- Hadoop 1 and 2.x installation notes (Server)

- Qt signals and slots mechanism (Programming)

- iOS developers - a simple factory pattern and OC reflection (Programming)

- Linux security configuration (Linux)

- Linux common network tools: traceroute routing of scanned (Linux)

- Linux tar compressed exclude a folder (Linux)

- Linux vi command list (Linux)

- Linux (CentOS) SSH login without password authentication (Linux)

- New experience Budgie (Budgerigar) desktop environment (Linux)

- MySQL 5.7 can not log in problem (Database)

- Oracle 11g dataguard main library backup and recovery to the test environment in one database error (Database)

- SUSE Firewall Configuration (Linux)

  Docker + Nginx + Tomcat7 simple load balancing configuration
  Add Date : 2018-11-21      
  This article describes how to configure simple load balancing on Docker, host of Ubuntu 14.04.2 LTS, two CentOS container, host install Nginx, two container mounting tomcat7.

Principle of this program is to port and host port docker container to make a map (ie, a port mapped access to the host corresponding docker container port), then the host can configure Nginx, to achieve access to the host a port, according to the rules assigned to the specified service address, complete load balancing.

Configuration Steps

1. Prepare the host, the host is Ubuntu 14.04.2 LTS, installed in Vmware, the specific installation methods, not repeat them.

2. Install Nginx on the host, you can directly use the following command.

sudo apt-get install nginx

After installation is complete, you can view Nginx whether the installation is complete, you can use the following command to view the version, print out the Nginx version, then the installation was successful.

$ Nginx -v

nginx version: nginx / 1.4.6 (Ubuntu)

After that, you can use the following command to start Nginx services:

# Start Service

$ Sudo service nginx start

# Check the service status

$ Sudo service nginx status

* Nginx is running # Description Services is a start-up state

In your browser to http: // localhost

3. Download Docker image, can be ordered with a docker pull specific mirroring can be found in this article

4. Start a container and set port mapping, one of the following commands:

sudo docker run -t -i -p 3222: 22 -p 3280: 80 87e5b6b3ccc1 / bin / bash

The above command is the standard way to start a bash output container port mapping settings, use the -p parameter, the host -p port: docker container port, the above command is mapped to the container port 3222 of the host port 22, set the host port 3280 is mapped to the container port 80.

5. Install jre and tomcat7.0 in the container, install jre

wget -O jre-7u6-linux-x64.rpm http://javadl.sun.com/webapps/download/AutoDL?BundleId=67387

yum install jre-7u6-linux-x64.rpm

Check whether the installation is successful jre

java -version

java version "1.7.0_06"

Java (TM) SE Runtime Environment (build 1.7.0_06-b24)

Java HotSpot (TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

Installation tomcat7.0

wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.65/bin/apache-tomcat-7.0.65.tar.gz

tar -zxvf apache-tomcat-7.0.65.tar.gz

Start tomcat, unzip into the directory, cd to the bin directory, execute the command and enter the following information, indicating a successful start tomcat

bash startup.sh

Using CATALINA_BASE: /home/apache-tomcat-7.0.65

Using CATALINA_HOME: /home/apache-tomcat-7.0.65

Using CATALINA_TMPDIR: /home/apache-tomcat-7.0.65/temp

Using JRE_HOME: / usr

Using CLASSPATH: /home/apache-tomcat-7.0.65/bin/bootstrap.jar:/home/apache-tomcat-7.0.65/bin/tomcat-juli.jar

Tomcat started.

Since tomcat default port is 8080, set here is the port 80, so you need to modify the default port 80 to enter the conf directory of tomcat installation directory, open the server.xml file in vi, the following configuration

< Connector port = "8080" protocol = "HTTP / 1.1"

              connectionTimeout = "20000"

              redirectPort = "8443" />

change into

< Connector port = "80" protocol = "HTTP / 1.1"

              connectionTimeout = "20000"

              redirectPort = "8443" />

Thereafter, this docker container, visit http: // localhost, access to the tomcat home page description tomcat installed and configured.

6. Go to the tomcat webapps / ROOT directory, since this container is ip, create a hello.html file in the file write the following "hello this is", and then visit http host : //

7. consistent with the above steps to configure other one container, but the container is set to start mapping port differ with the following command:

sudo docker run -t -i -p 3322: 22 -p 3380: 80 87e5b6b3ccc1 / bin / bash

Finally, in this container tomcat installation directory webapps / ROOT directory is created by hello.html files because this container is ip, so filled hello.html file contents "hello this is" after the host access

8. After the container configuration, the remaining work is to configure the host of Nginx, to complete the work load balancing.

Enter / etc / nginx directory with vim editor nginx.conf, add the following node in http:

server {

                listen 80;


                location / {

                        proxy_pass http: // blance;



        upstream blance {

                server localhost: 3280 weight = 5;

                server localhost: 3380 weight = 5;


First, define an upstream, the web server's port mapping and weights After you define a server, listening on port 80, server_name is, which is the host ip address (can be configured as domain names), "location /" means listening All requests under port 80, and use the upstream set above as a proxy.

9. The configuration is complete and saved, access the browser, and refresh the page, you will find page sometimes shows "hello this is", sometimes display "hello this is ", the configuration was successful, thus completing a simple load balancing environment configuration.
- To build Spring RestTemplate use HttpClient4 (Programming)
- Migu online music player for Linux (Linux)
- Docker build their own private warehouses (Linux)
- exp / imp Export Import version of the problem and the ORA-6550 error (Database)
- Getting the Linux shell flow control statements (Programming)
- Linux (RHEL6 CENTOS6 OLE6) VNC-SERVER Installation and Configuration (Server)
- SSH security note (Linux)
- 17 How to install the Ubuntu 14.04 and Linux Mint Kodi14 (XBMC) (Linux)
- CKEditor + SWFUpload achieve a more powerful editor (Linux)
- HAProxy performance under high concurrency (Server)
- Linux Shell Understanding and Learning (Linux)
- Linux user status query, and to unlock locked user (Linux)
- Automatic and Manual Proxy Settings Switch GNOME Shell Extension Proxy Switcher Recommend (Linux)
- Ubuntu system cp: omitting directory problem (Linux)
- Seven kinds of DDoS attack methods and techniques Defensive (Linux)
- The Linux kernel and AVL tree in red-black tree (Programming)
- The correct way to open Xcode - Debugging (Programming)
- tar decompression problems gzip: stdin: not in gzip format (Linux)
- VSFTPD Security (Linux)
- Linux dd command applies amplification SWAP partition (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.