zoukankan      html  css  js  c++  java
  • tengine负载均衡高可用配置

    环境

    Tengine-master:192.168.109.100

    Tengine-slave:192.168.109.101

    tomcat01:192.168.109.102

    tomcat02:192.168.109.104

    [Tengine部署]

    # yum install -y gcc gcc-c++ make

    #mkdir /opt/tengine-packages

    #cd /opt/tengine-packages

    # for tar in *.tar.gz;do tar xvf $tar;done

    # cd /opt/tengine-packages/tengine-2.2.3
    # ./configure --prefix=/opt/tengine --with-http_ssl_module --with-openssl=../openssl-1.1.1 --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --sbin-path=/opt/tengine/sbin/nginx --conf-path=/opt/tengine/conf/nginx.conf --pid-path=/opt/tengine/logs/nginx.pid

    # make    #编译的时候出现这个错误不要慌张,

    # vim ./objs/Makefile    #进入makefile编译makefile文件中将-lpthread修改为-pthread重新编译即可,如下图所示

    root@hostname-109102 tengine-2.2.3]#make

    root@hostname-109102 tengine-2.2.3]#make install 

    [root@hostname-109101 conf]# ln -s /opt/tengine/sbin/nginx /usr/local/sbin/

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        upstream tomcat_web {
        server 192.168.109.102:8080 weight=1 max_fails=2 fail_timeout=30s;
        server 192.168.109.104:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
           proxy_next_upstream http_502 http_504 error timeout invalid_header;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_pass http://tomcat_web;
           expires 3d;
                  }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }

    [root@hostname-109101 conf]# nginx -t
    nginx: the configuration file /opt/tengine/conf/nginx.conf syntax is ok
    nginx: configuration file /opt/tengine/conf/nginx.conf test is successful

    [tomcat后端]

    [root@tomcat-109103 ~]# mv /usr/src/jdk1.7.0_75/ /usr/local/java
    [root@tomcat-109103 ~]# ln -s /usr/local/java/bin/* /usr/bin/
    [root@tomcat-109103 ~]# vim /etc/profile.d/java.sh
    export JAVA_HOME=/usr/local/java
    export PATH=$PATH:$JAVA_HOME/bin
    [root@tomcat-109103 ~]# source  /etc/profile.d/java.sh
    [root@tomcat-109103 ~]# java -version
    java version "1.7.0_75"
    Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)
    [root@tomcat-109103 ~]# cp -r apache-tomcat-7.0.65/ /usr/local/tomcat01
    [root@tomcat-109103 ~]# cp -r apache-tomcat-7.0.65/ /usr/local/tomcat02
    [root@hostname-109103 ~]# mkdir /www/{web01,web02}
    [root@hostname-109103 ~]# vim /usr/local/tomcat01/conf/server.xml
    <Context path="/" docBase="/www/web01"  reloadable="true"/>
    [root@hostname-109103 ~]# vim /usr/local/tomcat02/conf/server.xml
         <Context path="/" docBase="/www/web02"  reloadable="true"/>

    [root@hostname-109102 ~]# cat /www/web01/index.jsp      #ps:这里是109.102机器的tomcat访问测试页面
    <html>
    <body>
    <h1>JSP Test Page 11111</h1>
    <%=new java.util.Date()%>
    </body>
    </html>

    [root@hostname-109104 ~]# cat /www/web02/index.jsp       #ps:这里是109.104访问测试页面
    <html>
    <body>
    <h1>JSP Test Page 22222</h1>
    <%=new java.util.Date()%>
    </body>
    </html>

    
    

    [keepalived]

    yum install -y ipvsadm keepalived

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
         acassen@firewall.loc
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server 127.0.0.1
       smtp_connect_timeout 30
       router_id LVS_HOST
    }
    
    vrrp_instance VI_1 {
        state MASTER/BACKUP
        interface eth0
        virtual_router_id 51
        priority 100/50
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.109.188
        }
    }
    
    virtual_server 192.168.109.188 8080 {
        delay_loop 6
        lb_algo rr
        lb_kind DR
        persistence_timeout 50
        protocol TCP
    
          real_server 192.168.109.102 8080 {
            weight 1
            TCP_CHECK {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
                connect_port 8080
            }
        }
    
          real_server 192.168.109.104 8080 {
            weight 1
            TCP_CHECK {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
                connect_port 8080
            }
        }
    }
    

      

     

  • 相关阅读:
    Ant
    责任链模式
    日志logback
    知识点
    三个实例演示 Java Thread Dump 日志分析
    IDEA运行编译后配置文件无法找到,或配置文件修改后无效的问题
    IDEA创建MAVEN WEB工程
    多线程源码分析ThreadPoolExecutor
    解决
    微博关系服务与Redis的故事
  • 原文地址:https://www.cnblogs.com/bixiaoyu/p/11158517.html
Copyright © 2011-2022 走看看