httpd或Nginx負載平衡tomcat

來源:互聯網
上載者:User

標籤:負載   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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.