httpd or Nginx load balancing tomcat

Source: Internet
Author: User
Tags nginx load balancing

Lab Environment: CentOS7

#两台tomcat的基本配置如下: [[email protected] localhost] #setenforce0[email protected] localhost] #iptables-f[[email protected] localhost] #yum-y install java-1.8.0-openjdk-devel tomcat Tomcat-webapps tomcat-admin-webapps[[email protected] localhost] #chown tomcat.tomcat/usr/share/tomcat/webapps/test/*[email protected] localhost] #chown tomcat.tomcat test[[email protected] localhost] #vim/etc/tomcat/server.xml <connector port= "8081" protocol= "http/1.1" maxthreads= "$" enablelookups= "False"ConnectionTimeout= "60000" address= "172.16.252.142"Redirectport= "8443"/>[email protected] localhost] #vim/usr/share/tomcat/webapps/test/index.jsp<%@ page language= "Java"%><%@ page import= "java.util.*"%>Out.println ("Tomcat1 Mini"); %> </body>[email protected] localhost] #vim/usr/share/tomcat/conf/tomcat-users.xml<role rolename= "Manager-gui"/><user username= "Tomcat" password= " 123456 "roles=" Manager-gui "/>

#第三台主机安装Nginx: 172.16.253.177

#ngixn做负载均衡:

[email protected]~ localhost] #setenforce 0[[Email protected]~ localhost] #iptables-F[[email protected]~ localhost] #yum-y install nginx-1.10.2-1. el7.ngx.x86_64.rpm [[email protected]~ localhost] #vim/etc/nginx/nginx.confhttp {#定义: Cluster tomcatsrupstream TOMCATSR {server172.16.252.142:8081; Server172.16.254.47:8081;} Include/etc/nginx/conf.d/*. conf;} #引用 [[Email protected]~ localhost] #vim/etc/nginx/conf.d/default. confserver { location/{proxy_pass http://TOMCATSR;root/usr/share/nginx/html;    Index index.html index.htm; }

#httpd做负载均衡:

[email protected]~ localhost] #yum-y install httpd

[email protected]~ localhost] #httpd-m

Proxy_balancer_module (shared) #负载均衡模块

[email protected]~ localhost] #vi/etc/httpd/conf.d/tomcat-httpd.conf<proxy Balancer://tomcatsr>Balancermember http://172.16.252.142:8081Balancermember http://172.16.254.47:8081Proxyset lbmethod=byrequests</proxy><virtualhost *:80>ServerName Linux.io Proxyvia on proxyrequests Off proxypreservehost on<proxy *>Require All granted</Proxy> Proxypass/balancer://tomcatsr/Proxypassreverse/balancer://tomcatsr/<location/>Require All granted</Location></VirtualHost>

#测试:

[[Email protected]~ localhost]# forIinch{1..10}; DoCurl http://172.16.253.177/test/;d OneTOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>TOMCAT2 Mini1</body>TOMCAT1 Mini</body>

httpd or Nginx load balancing tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.