650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/B3/wKiom1WC-dzTJ1AvAAC2EP4IqPY563.jpg "/>
[[Email protected] tomcat]# vim/usr/local/tomcat/webapps/testapp/index.jsp<%@ page language= "Java" %>Set complete access results as follows
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/B0/wKioL1WC-46xpyRNAADKotPdXz0025.jpg "/>
Nginx Reverse proxy + load balancer TomcatInstalling Nginx
[[email protected] ~]# yum-y install Nginx
Start the service
[[Email protected] ~]# service Nginx start
access to Nginx can be accessed normally
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/B0/wKioL1WC-5CgtiyEAAJh8Fsoze4138.jpg "/>
in the http field definition upstream, set the back-end Tomcat host and Port, and set the health state check
[Email protected] ~]# vim/etc/nginx/nginx.conf upstreamupservers {server172.16.4.101:8080 max_fails=2 fail_time Out=1; server172.16.4.102:8080 max_fails=2 fail_timeout=1;}
forwarding Settings forward requests to Nginx to upstream
[Email protected] ~]# vim/etc/nginx/conf.d/default.conf location/{#root/usr/share/nginx/html; Proxy_pass http://upservers/; Index index.jsp index.htmlindex.htm; }
once set, the address of the Nginx server is accessed and the request is forwarded to the back-end Tomcat server for load Balancing
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/B3/wKiom1WC-d6BZEy-AADFpq0d9zc858.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/B3/wKiom1WC-d-zRyPuAAC8J7RPmJ0999.jpg "/>
Static and dynamic separation Setup method: Simply forward the JSP and do end files to the back-end Tomcat server
Location ~* \. (Jsp|do) $ {proxy_passhttp://tomcat_host:port;}
Set Nginx After the setup is complete, remember to close nginx Services, so as not to affect the following httpd Test
based onhttpdImplementing a reverse proxy+Load Balancingbased onMod_proxyImplementing a reverse proxy+Load BalancingModify httpd Master Profile Logoff Center host
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf#documentroot "/var/www/html"
Set up load balancing related information
[[email protected] ~]# vim /etc/httpd/conf.d/mod_proxy.conf<proxy balancer:// tcsrvs> balancermember http://172.16.4.101:8080 loadfactor=1 balancermember http ://172.16.4.102:8080 loadfactor=1</proxy> namevirtualhost *:80 <virtualhost *:80> servernamewww.a.com proxyvia on proxyrequests off proxypreservehost on <proxy*> orderdeny,allow allowfrom all </proxy> proxypass/status ! proxypass / balancer://tcsrvs/ proxypassreverse / balancer://tcsrvs/ <location /> Orderdeny,allow Allowfrom all </Location> </VirtualHost>
The service is started after the setting is complete, and the load balancing effect occurs when the httpd address is accessed
based onAjpprotocol for load Balancingas long as you modify the protocol for accessing the backend server to AJP , the port is 8009
[[email protected]~]# vim /etc/httpd/conf.d/mod_ proxy.conf<proxy balancer://tcsrvs> balancermember ajp://172.16.4.101:8009 loadfactor=1 balancermember ajp://172.16.4.102:8009 loadfactor=1</proxy> namevirtualhost *:80 <virtualhost *:80> servernamewww.a.com proxyvia on proxyrequests off proxypreservehost on <proxy*> Orderdeny,allow Allowfrom all </Proxy> proxypass/status ! proxypass /balancer://tcsrvs/ proxypassreverse / balancer://tcsrvs/ <location /> orderdeny,allow allowfrom all </location></virtualhost>
set to complete restart httpdto achieve load balancing effect
Set Status page
[[email protected]~]# vim /etc/httpd/conf.d/mod_proxy.conf<proxy balancer:// tcsrvs> balancermember ajp://172.16.4.101:8009 loadfactor=1 balancermember ajp:// 172.16.4.102:8009 loadfactor=1</proxy> namevirtualhost *:80 <virtualhost * :80> servernamewww.a.com proxyvia on proxyrequests off proxypreservehost on <proxy*> orderdeny,allow allowfrom all </proxy> proxypass/status ! proxypass/ balancer-manager ! proxypass /balancer://tcsrvs/ proxypassreverse / balancer://tcsrvs/ <location /> orderdeny,allow Allowfrom all </Location> <Location /balancer-manager> sethandler balancer-manager&Nbsp; proxypass! orderdeny,allow allowfrom all </Location></VirtualHost>
Access Status page can be accessed normally
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/B0/wKioL1WC-5KhCcnNAANJg2d6Hr8331.jpg "/>
based onMod_jkthe Load Balancercompiling mod_jk- dependent httpd Development Packages
[Email protected] ~]# yum-y install Httpd-devel
compiling and installing MOD_JK
Tar XF tomcat-connectors-1.2.40-src.tar.gzcd tomcat-connectors-1.2.40-src/native/whereis apxs./configure-- With-apxs=/usr/sbin/apxsmake && make Install
Description: If you do not know the path to the Apxs file, you can use Whereis to find
[Email protected] native]# Whereis APXSAPXS:/usr/sbin/apxs/usr/share/man/man8/apxs.8.gz
The following tips are available when compiling
chmod 755/usr/lib64/httpd/modules/mod_jk.so
Configure load Balancingset up tomcat routing information
[Email protected] ~]# vim/usr/local/tomcat/conf/server.xml <engine name= "Catalina" defaulthost= "localhost" Jvmroute= "Tomcata" >[[email protected] ~]# vim/usr/local/tomcat/conf/server.xml <engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCATB" >
Modify the front-end httpd configuration file, set mod_jk related configuration
[email protected] conf.d]# cat Mod_jk.confloadmodule jk_modulemodules/mod_jk.so jkworkersfile/etc/httpd/conf.d/ Workers.propertiesjklogfilelogs/mod_jk.logjkloglevelinfojkmount/status! Jkmount/*tcsrvs #表示将请求转发到tcsrvs列表JkMount/status StatA
set up workers.propertiesto define load balancing related information
[email protected] conf.d]# cat Workers.propertiesworker.list=tcsrvs,stata #定义tcsrvs列表worker. Tomcatb.host=172.16.4.101worker. Tomcatb.port=8009worker. Tomcatb.type=ajp13worker. Tomcatb.lbfactor=1 #设置权重worker. Tomcata.host=172.16.4.102worker. Tomcata.port=8009worker. Tomcata.type=ajp13worker. Tomcata.lbfactor=1worker. STATA.TYPE=STATUSWORKER.TCSRVS.TYPE=LB #代理方式为lb, i.e. load Balancer WORKER.TCSRVS.BALANCE_WORKERS=TOMCATA,TOMCATB # Description The Tcsrvs list contains, Tomcata, and tomcatbworker.tcsrvs.sticky_session=0 #关闭基于session的绑定, otherwise it will remain anchored to a server if the value is set to 1, or if it is not set to open the bind
Load balancing capability with access testing
Access Status page is also normal
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/B3/wKiom1WC-eHSs7BLAATEVQhhibc354.jpg "/>
This article from "Plum blossom fragrance from bitter cold" blog, please be sure to keep this source http://ximenfeibing.blog.51cto.com/8809812/1663390
Four ways to configure Tomcat reverse proxy + load Balancer