zoukankan      html  css  js  c++  java
  • Nginx实现HTTP及TCP负载均衡

    这种通过一台apache的服务器把客户请求分别传递给两台tomcat叫负载均衡 

    ========================================= ========================

    材料:准备两台Tomcat主机

    第一台tomcat主机配置:IP为192.168.200.130

    [root@localhost ~]# mkdir -pv /web/webapp
    mkdir: 已创建目录 "/web"
    mkdir: 已创建目录 "/web/webapp"
    [root@localhost ~]# vim /web/webapp/index.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <html>
    <head>
    <title>JSP test page</title>
    </head>
    <body>
    <% out.println("Welcome to test site,http://www.test.com");%>
    </body>
    </html>

    [root@localhost ~]# cd /usr/local/tomcat8/conf/

    [root@localhost conf]# cp server.xml server.xml.bak                           //备份一份主配置文件
    [root@localhost conf]# vim server.xml

    在150行左右的Host下添加Context文件
     <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
            <Context docBase="/web/webapp" path="" reloadable="flase">
           </Context>

    [root@localhost conf]# /usr/local/tomcat8/bin/startup.sh
    Using CATALINA_BASE: /usr/local/tomcat8
    Using CATALINA_HOME: /usr/local/tomcat8
    Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
    Using JRE_HOME: /usr/local/java
    Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
    Tomcat started.
    [root@localhost conf]# netstat -anpt | grep :8080
    tcp6 0 0 :::8080 :::* LISTEN 61263/java
    [root@localhost conf]# systemctl stop firewalld
    [root@localhost conf]# iptables -F
    [root@localhost conf]# setenforce 0

    测试:

    第二台Tomcat主机配置:IP为192.168.200.122

    [root@localhost ~]# mkdir -pv /web/webapp1
    mkdir: 已创建目录 "/web"
    mkdir: 已创建目录 "/web/webapp1"
    [root@localhost ~]# vim /web/webapp1/index.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <html>
    <head>
    <title>JSP test page</title>
    </head>
    <body>
    <% out.println("Welcome to test site,http://www.test1.com");%>
    </body>
    </html>

    [root@localhost ~]# cd /usr/local/tomcat8/conf/

    [root@localhost conf]# cp server.xml server.xml.bak                           //备份一份主配置文件
    [root@localhost conf]# vim server.xml

    在150行左右的Host下添加Context文件
     <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
            <Context docBase="/web/webapp1" path="" reloadable="flase">
           </Context>

    [root@localhost conf]# /usr/local/tomcat8/bin/startup.sh 
    Using CATALINA_BASE: /usr/local/tomcat8
    Using CATALINA_HOME: /usr/local/tomcat8
    Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
    Using JRE_HOME: /usr/local/java
    Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
    Tomcat started.
    [root@localhost conf]# netstat -anpt | grep :8080
    tcp6 0 0 :::8080 :::* LISTEN 61263/java 
    [root@localhost conf]# systemctl stop firewalld
    [root@localhost conf]# iptables -F
    [root@localhost conf]# setenforce 0

    测试:

  • 相关阅读:
    (转)jQuery.extend 函数详解
    (转)跟我一起学JQuery插件开发教程
    (转)jQuery插件开发全解析
    (转)弹出窗口lhgDialog API文档
    (转)反射发送实战(-)InvokeMember
    (转)JQuery处理json与ajax返回JSON实例
    linux下添加用户并赋予root权限
    Linux 下配置,安装Hadoop
    Linux 下安装 jdk-7u79-linux-x64.gz,jdk1.7.0_79,jdk1.7步骤:
    linux下导入、导出mysql数据库命令
  • 原文地址:https://www.cnblogs.com/CMX_Shmily/p/11587302.html
Copyright © 2011-2022 走看看