標籤:負載 curl als thread name dev color prot port
實驗環境:CentOS7
#兩台tomcat的基本配置如下:[[email protected] localhost]#setenforce 0[[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="200" 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.*" %><html> <head><title>tomcat1 mini</title></head> <body> <% out.println("tomcat1 mini"); %> </body></htmL>[[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 {#定義:叢集tomcatsrupstream tomcatsr { server 172.16.252.142:8081; server 172.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:8081 BalancerMember http://172.16.254.47:8081 ProxySet 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]#for i in {1..10};do curl http://172.16.253.177/test/;done<html> <head><title>tomcat2 mini1</title></head> <body> tomcat2 mini1 </body></htmL><html> <head><title>tomcat1 mini</title></head> <body> tomcat1 mini </body></htmL><html> <head><title>tomcat2 mini1</title></head> <body> tomcat2 mini1 </body></htmL><html> <head><title>tomcat1 mini</title></head> <body> tomcat1 mini </body></htmL><html> <head><title>tomcat2 mini1</title></head> <body> tomcat2 mini1 </body></htmL><html> <head><title>tomcat1 mini</title></head> <body> tomcat1 mini </body></htmL><html> <head><title>tomcat2 mini1</title></head> <body> tomcat2 mini1 </body></htmL><html> <head><title>tomcat1 mini</title></head> <body> tomcat1 mini </body></htmL><html> <head><title>tomcat2 mini1</title></head> <body> tomcat2 mini1 </body></htmL><html> <head><title>tomcat1 mini</title></head> <body> tomcat1 mini </body></htmL>
httpd或Nginx負載平衡tomcat