Tomcat Web services, combined cluster and Nginx

Tomcat Web Services

Tomcat, for open environments JAVA language, and Nginx and apache environment for PHP development environment ,
Tomcat is not applicable to traffic at large production environment

Experimental Materials

A centos7 ip 192.168.100.102 Xshell connection
Tomcat package will provide Baidu cloud behind me, you can download

1. Turn off the firewall firewalld

[root@CentOS7-02 ~]# systemctl stop firewalld

2. Check whether the installation JDK

[CentOS7-02 the root @ ~] # Java -version
-bash: java: 未找到命令 : No Installation
Installation: loading the optical disc, arranged yum source
[CentOS7-02 the root @ ~] # yum the install Java -Y *
[CentOS7-02 the root @ ~] # Java - version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)

3. Install Tomcat

Link packet following
links : https://pan.baidu.com/s/1zqmIXbFqaUV2EPVEm_rezQ
extraction code: b6qm
packet drag Xshell
. 1) is mounted the Tomcat
[CentOS7-02 the root @ ~] # the tar-zxf Apache Tomcat-8.5.16.tar .gz
[root @ CentOS7-02 ~] # mv the Apache-Tomcat-8.5.16 / usr / local / tomcat8 (behind the tomcat8 hand default is no)
2) open the Tomcat service
[root @ CentOS7-02 ~] # / usr / local / tomcat8 / bin / startup.sh ( open Tomcat service)
[root @ CentOS7-02 ~] # netstat -anpt | grep 8080 (default port work in 8080) 3) IP browser to access the test if you want to shut down Tomcat service , the following command may allow [the root CentOS7-02 @ ~] # /usr/local/tomcat8/bin/shutdown.sh
tcp6 0 0 :::8080 :::* LISTEN 1251/java

http://192.168.100.102:8080/
Here Insert Picture Description

4. Establish JAVA Web site

1) Create a directory site for storing website files
[root @ CentOS7-02 ~] # mkdir -p / Web / Tomcat
2) create a test page
[root @ CentOS7-02 ~] # vim / Web / Tomcat / index .jsp
fill in the following, I have explained the figure
Here Insert Picture Description
to save and exit
3) modify the server.xml file for Tomcat (that is the main configuration file)
[root @ CentOS7-02 ~] # vim /usr/local/tomcat8/conf/server.xml
add below two, the position of the added I have FIG
<Context docBase="/web/tomcat" path="" reloadable="false">
</Context>
Here Insert Picture Description
4) off Tomcat, restart
[CentOS7-02 the root @ ~] # /usr/local/tomcat8/bin/shutdown.sh
[CentOS7-02 the root @ ~] # /usr/local/tomcat8/bin/startup.sh
5) accessed through a browser test
http://192.168.100.102:8080/
Here Insert Picture Description

Case: Nginx + Tomcat load balancing cluster

Experimental Materials

Nginx package, and I will provide Baidu cloud behind
Nginx server 192.168.100.103 IP
Tomcat server 1 IP 192.168.100.102 (you can continue to use the experiment above)
Tomcat server 2 IP 192.168.100.104

1.Tomcat Server Configuration

Tomcat1 server directly using the above experiment, do not perform any operation
Tomcat2 server 104 and Tomcat1 (that is, the experiment above), exactly the same operation, installation and start Tomcat, or else just a test page as follows
Here Insert Picture Description
and then continue to follow my steps to the above experiment, other operations are exactly the same
access to test
Here Insert Picture Description
if your computer is turned off, and then open the virtual machine, and sometimes direct start Tomcat will not start, turn off the Tomcat restart it ok, which is above the close-on command

2.Nginx Server Configuration

Entering IP192.168.100.103 Nginx server
1) Close firewall
[centos7-03 the root @ ~] # systemctl STOP firewalld

2) related to the installation package
to mount the discs, arranged yum source
[centos7-03 the root @ ~] # yum the install PCRE -Y-devel zlib-devel OpenSSL-devel

3)解压并安装Nginx
[root@centos7-03 ~]# groupadd www
[root@centos7-03 ~]# useradd -g www www -s /bin/false
包拖入Xshell
链接:https://pan.baidu.com/s/1Vlj4bzX6Um_MVfELwrTwKg

提取码:yy1q
[root@centos7-03 ~]# tar zxf nginx-1.12.0.tar.gz
[root@centos7-03 ~]# cd nginx-1.12.0
[root@centos7-03 nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module
[root@centos7-03 nginx-1.12.0]# make && make install

4) arranged nginx.conf
1. In the configuration file http {add the following code to set the load balancing server list
[@ centos7-03 the root ~] # Vim /usr/local/nginx/conf/nginx.conf
inserted location, I have the following figure
upstream tomcat_server{
server 192.168.100.102:8080 weight=1;
server 192.168.100.104:8080 weight=1;
}
Here Insert Picture Description
2. continue adding the code
or in the configuration file,
Here Insert Picture Description
save and exit

5) Test Nginx configuration file is correct
[root @ centos7-03 ~] # / usr / local / nginx / sbin / nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

6) Start Nginx service
[root @ centos7-03 ~] # / usr / local / nginx / sbin / nginx -c /usr/local/nginx/conf/nginx.conf

7) Check Nginx server process
[root @ centos7-03 ~] # PS the AUX | grep nginx (there should be something on the right)

8) Check the port number and PID process ID
[root @ centos7-03 ~] # netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1165/nginx: master

3. Load balancing test

Open a browser to access http://192.168.100.103/ ( nginx server IP )
constantly refresh because the same weight, the page will switch back and forth in the following two pages
the following page is 192.168.100.102 server,
Here Insert Picture Description
refresh the page
is below 192.168 .100.104 server pages
Here Insert Picture Description

If it is a real environment, certainly it must be set to the same page, and it should be here to see the effect is not the same page

Experiment completed

Published 54 original articles · won praise 57 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_45308292/article/details/101440201