Tomcat deployment and load balancing

1.tomcat Server is a free open source Web application server, are lightweight application server, it is not widely used in many occasions small and medium systems and concurrent user access is the preferred development and debugging JSP program. Although the general Tomcat and Apache or Nginx web server to write this, as has the function to handle HTML pages, but because of its ability to handle much more than static HTML and Apache or Nginx, it is usually as a Tomcat Servlet container and JPS, running alone rear end.

2. JDK must be installed before installing Tomcat. JDK stands for java Development Kit, Sun's Java language provides free software development kit, which includes java virtual machine (JVM). Good java source code can be compiled java byte code form, just install JDK, you can use JVM bytecode interpretation of these files, thus ensuring cross-platform java to write.

(1) View JDK is installed
to run java -version command to see if java is installed, if not installed need to download and install on their own.
Tomcat deployment and load balancing

(2) Installation and Configuration Tomcat
decompressed packet apachen-tomcat-8.5.16.tar.gz
Tomcat deployment and load balancing

(2) after decompression generating aoache-tomcat-8.5.16 folder, the folder to the / usr / local /.
Tomcat deployment and load balancing

(3) Start tomcat
Tomcat deployment and load balancing
Tomcat deployment and load balancing

(4) Open a browser to access the test: http: //192.168.1.10: 8080, if the interface appears as shown, then start tomcat nearly successful.
Tomcat deployment and load balancing

3.Tomcat instructions on configuring
the home directory is tomcat / usr / local / tomcat8 /
Tomcat deployment and load balancing

(1) The main catalog description
Tomcat deployment and load balancing

(2) Configuration file Description
Tomcat deployment and load balancing
Tomcat deployment and load balancing

4.tomcat main configuration file description
Tomcat deployment and load balancing

5. Establish java web site
(1) establish a web directory in the root directory, and create a directory in which webapp1 for storing website files.
Tomcat deployment and load balancing

(2)在webapp1目录下建立一个index.jsp测试页面
Tomcat deployment and load balancing
Tomcat deployment and load balancing

(3)修改tomcat的server.xml
定义一个虚拟机,并将网站文件路径指向已近建立的/web/webapp1,在host段增加context段。
Tomcat deployment and load balancing
Tomcat deployment and load balancing

(4)关闭tomcat,再重新启动
Tomcat deployment and load balancing
Tomcat deployment and load balancing

(5)通过浏览器访问http://192.168.1.10:8080/。出现如图页面,说明该tomcat站点已经配置成功,并且已近能够运行JSP了。
Tomcat deployment and load balancing

                            案例:Nginx+Tomcat负载均衡群集

1.通常情况下,一台tomcat站点由于可能出现单点故障无法应付过多客户复杂多样的请求等问题,不能单独应用于生产环境下,所以我们需要一套更可靠的解决方案来完善web站点架构。
Nginx是一款非常优秀的http服务器软件,它能够支持高达50000个并发连接数的响应,拥有强大的静态资源处理能力,运行稳定,并且内存,cpu等系统消耗非常低。,目前很多大型网站都应用Nginx服务器作为后端网站程序的反向代理及负载均衡,来提升整个站点的负载并发能力。
(1)网站拓扑架构如图所示
Tomcat deployment and load balancing

2.案例实施
(1)tomcat2 server配置
tomcat server 配置方法基本同tomcat1,其中包括:
(1)关闭防火墙
(2)确认是否安装JDK,java版本于tomcat1server保持一致
(3)安装配置tomcat,版本于tomcat1 server保持一致
(4)创建/web/webapp1 目录,修改tomcat配置文件server.xml,将网站文件目录更改到/web/webapp1/路径下。
(5)在/web/webapp1/路径下建立index.jsp,为了区别测试页面index.jsp的内容更改如下。
Tomcat deployment and load balancing
Tomcat deployment and load balancing
Tomcat deployment and load balancing
Tomcat deployment and load balancing

3.Nginx server configuration
installed on nginx server 192.168.1.30 nginx, reverse proxy tomcat two sites, and load balancing.
(1) turn off the firewall
(2) related to the installation package
Tomcat deployment and load balancing
(3) Unpack and install the Nginx
Tomcat deployment and load balancing
(. 4) arranged nginx.conf
at http {..} add the following code to set a list of server load balancing, weight represents the weight parameter, the larger the higher the probability weights are assigned. To make the test more obvious effects, we pack weight is set to the same.
Tomcat deployment and load balancing
Tomcat deployment and load balancing
Tomcat deployment and load balancing
(5) test Nginx configuration file is correct.
Tomcat deployment and load balancing
(6) start nginx Services
Tomcat deployment and load balancing
(7) View Nginx server process.

Tomcat deployment and load balancing

 最后打开浏览器访问http://192.168.1.30即可

Constantly refresh the browser test, it can be seen due to the heavy weight the same page repeatedly switching back and forth in the following two pages. The first visit, there was test1 test page, refresh the second visit, there is test2 test page. As shown below, indicating successful load balancing cluster structures.
Tomcat deployment and load balancing

Guess you like

Origin blog.51cto.com/14306186/2436576