zoukankan      html  css  js  c++  java
  • tomcat部分

    在安装tomcat之前,首先要安装jdk
    jdk安装步骤省略
    java环境变量配置
    vim /etc/profile
    export JAVA_HOME=/usr/local/jdk                                                 //在文件最后添加(jdk安装路径为/usr/local/jdk) export CLASS_PATH=.:$JAVA_HOME/lib export PATH=$PATH:$JAVA_HOME/bin
     
    tar zxf apache-tomcat-7.0.37.tar.gz
    mv apache-tomcat-7.0.37 /usr/local/apache-tomcat-7.0.37/
    cd /usr/local/
    ln -s  apache-tomcat-7.0.37/ tomcat
    cd tomcat/webapps/ROOT/                                                    //tomcat默认发布目录
    cd  ../bin/
    ./startup.sh                                                                                  //tomcat启动脚本
    tomcat与nginx 进行简单的整合
    vim /usr/local/lanmp/nginx/conf/nginx.conf                          //编辑nginx主配置文件
    68         location ~ .jsp$ {                                                           //在68行添加一下内容,注意 jsp$与 ‘{’中间要有空格 69                 proxy_pass      http://127.0.0.1:8080;
     70         }
    两台tomcat负载均衡
    scp -r ./apache-tomcat-7.0.37/ root@192.168.0.144:/usr/local/                          //为保证版本相同,直接拷贝至另一台机子
    [root@server44 usr]#   ./startup.sh                                             //在另一台机子上面启动服务
    返回server4
    cd /usr/local/lanmp/nginx/conf/ vim nginx.conf
    编辑nginx.conf
     upstream hello {                                                                                     //两台机子的8080端口 server 192.168.0.104:8080 ; server 192.168.0.144:8080; }
     
    location ~ .jsp$ {                                                                             //修改这里,做负载均衡 proxy_pass      http://hello; }
    在浏览器输入server4.example.com:8080/test.jsp进行测试
    现在出现一个问题,当同一个人访问网页时,只要一刷新,他的请求将跑到另一台机子上面,也就是说,当我们注册帐号的时候,如果我们在注册过程中刷新了一下页面,那么我们之前所填写的东西都将作废。
    所以,现在我们要做的就是,让nginx保持这一个链接,也就是说,当一个客户机链接上时,他就一直链接一台机子
    这里我们要对nginx进行源码编译,给nginx添加sticky模块
    tar zxf nginx-1.2.7.tar.gz
    tar zxf nginx-sticky-module-1.0.tar.gz
    cd nginx-1.2.7
    之前做的优化现在也要做
    cd src/core/
    vim  nginx.h                                 //去掉版本显示
    cd ../../auto/cc/
    vim gcc                                          //关闭debug调试
    ./configure --prefix=/usr/local/lanmp/nginx --with-http_ssl_module --with-http_stub_status_module --add-module=/mnt/nginx-sticky-module-1.0                         //后面这部分为新添加的模块,
    make && make install
    cd /usr/local/lanmp/nginx/conf/
    vim nginx.conf
    在其中添加sticky模块
    upstream hello { sticky;                                                                 //在这里添加 server 192.168.0.104:8080 ; server 192.168.0.144:8080; }
    之后重启nginx ,一切ok,当我们关闭掉一个tomcat时,网站依然可以访问,并且,我们同一台机子连接的总是一台服务器
     
  • 相关阅读:
    MVC模式-----struts2框架(2)
    MVC模式-----struts2框架
    html的<h>标签
    jsp脚本元素
    LeetCode "Paint House"
    LeetCode "Longest Substring with At Most Two Distinct Characters"
    LeetCode "Graph Valid Tree"
    LeetCode "Shortest Word Distance"
    LeetCode "Verify Preorder Sequence in Binary Search Tree"
    LeetCode "Binary Tree Upside Down"
  • 原文地址:https://www.cnblogs.com/Seven-Wang/p/4451578.html
Copyright © 2011-2022 走看看