• Nginx+tomcat负载均衡


    实验环境

    [root@Java-JDK ~]# tar zxvf jdk-7u65-linux-x64.gz

    [root@Java-JDK ~]# mkdir /usr/java
    [root@Java-JDK ~]# mv jdk1.7.0_65/ /usr/java/

    [root@Java-JDK ~]# /usr/java/jdk1.7.0_65/bin/java -verssion
    Unrecognized option: -verssion
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    [root@Java-JDK ~]# /usr/java/jdk1.7.0_65/bin/java -version
    java version "1.7.0_65"
    Java(TM) SE Runtime Environment (build 1.7.0_65-b17)    #Java运行的环境即JRE
    Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

    设置环境变量

    [root@Java-JDK ~]# vim /etc/profile 

    export JAVA_HOME=/usr/java/jdk1.7.0_65
    export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
    export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin

    [root@Java-JDK ~]# java -version
    java version "1.7.0_65"
    Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
    Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

    安装tomcat

    wget -c https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz

    [root@Java-JDK ~]# tar zxvf apache-tomcat-7.0.81.tar.gz

    [root@Java-JDK ~]# mv apache-tomcat-7.0.81 /usr/local/tomcat

    root@localhost local]# cp -a tomcat/ tomcat_1 && cp -a tomcat/ tomcat_2   #创建两个tomcat

    [root@Java-JDK ~]# /usr/local/tomcat/bin/startup.sh

    <Server port="8005" shutdown="SHUTDOWN">    #管理关闭Tomcat的端口

    <Connector port="8080" protocol="HTTP/1.1"    #管理tomcat协议浏览访问 

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />    #管理AJP代理协议  (PS:apache与tomcat连接需要借助8009/nginx与tomcat连接直接借助8080即可)

    [root@localhost local]# vim tomcat_1/webapps/ROOT/index.jsp 

    <html>
    <body>
    <h1>Tomcat Server Nmae hexun JSP Test Page </h1>
    <%=new java.util.Date()%>
    <hr color="red">
    <h1>www.hexun.net</h1>
    </body>
    </html>

    [root@localhost local]#vim tomcat_2/conf/server.xml

    <Server port="8006" shutdown="SHUTDOWN">

    <Connector port="8081" protocol="HTTP/1.1"

     <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

    [root@localhost local]# vim tomcat_2/webapps/ROOT/index.jsp

    <html>
    <body>
    <h1>Tomcat Server Name jfedu JSP Test Page </h1>
    <%=new java.util.Date()%>
    <hr color="red">
    <h1>www.jfedu.net</h1>
    </body>
    </html>

    [root@localhost local]# /usr/local/tomcat_1/bin/startup.sh 

    [root@localhost local]# /usr/local/tomcat_1/bin/startup.sh 

    [root@localhost html]# vim  /usr/local/nginx/conf/nginx.conf    #在Nginx配置文件中配置方向代理负载均衡后端两个Tomcat虚拟主机

     ip_hash;   #保证会话只转发到后台一台web服务器(ps:如果该机器宕机,便会自动转发到下一台机器)

    客户端浏览器访问NginxServerIP进行 刷新浏览访问

  • 相关阅读:
    Scramble String
    Burst Balloons
    Coins in a Line III
    maven初识
    Java类加载器初识
    HTTP协议
    Map和Set的联系
    Thread类与Runnable接口
    Throwable和Exception的区别
    SpringMVC的@ResponseBody注解简介
  • 原文地址:https://www.cnblogs.com/bixiaoyu/p/7510760.html
Copyright © 2020-2023  润新知