Dubbo 는 Keepalived + Nginx 로 높 은 웹 부하 균형 을 실현 할 수 있 습 니 다.

6838 단어 dubbo
 、    
VIP IP     Nginx        
192.168.229.220 192.168.229.210 edu-proxy-01 88 MASTER
                192.168.229.211 edu-proxy-02 88 BACKUP

   Nginx
     
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
firewall-cmd --state
 、   Nginx
1、     Nginx       
# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel
openssl openssl-devel

2、   Nginx(nginx-1.6.2.tar.gz)  /usr/local/src   

3、     Nginx
# cd /usr/local/src/
# tar -zxvf nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ./configure --prefix=/usr/local/nginx
# make && make install

4、   Nginx
# vi /usr/local/nginx/conf/nginx.conf
user  root;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       88;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

   Nginx       (      ,          Nginx) :
# vi /usr/local/nginx/html/index.html
192.168.229.210       1

Welcome to nginx! 1

192.168.229.211 2

Welcome to nginx! 2

5、 88 # vi /etc/sysconfig/iptables ## Nginx -A INPUT -m state --state NEW -m tcp -p tcp --dport 88 -j ACCEPT # service iptables restart 6、 Nginx # /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 7、 Nginx # /usr/local/nginx/sbin/nginx Nginx # /usr/local/nginx/sbin/nginx -s reload 8、 Nginx # vi /etc/rc.local : /usr/local/nginx/sbin/nginx 192.168.229.210:88 192.168.229.211:88 、 Keepalived ( http://www.keepalived.org/download.html ) 1、 keepalived(keepalived-1.2.18.tar.gz) /usr/local/src 2、 # cd /usr/local/src # tar -zxvf keepalived-1.2.18.tar.gz # cd keepalived-1.2.18 # ./configure --prefix=/usr/local/keepalived # make && make install 3、 keepalived Linux : keepalived ( /usr/local), , # mkdir /etc/keepalived # cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ keepalived ------------------------------------------------------------------------ # cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ # cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ # ln -s /usr/local/sbin/keepalived /usr/sbin/ # ln -s /usr/local/keepalived/sbin/keepalived /sbin/ keepalived , cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ [root@edu-proxy-02 ~]# cp /usr/local/keepalived/sbin/keepalived /sbin/ ------------------------------------------------------------------------- keepalived # chkconfig keepalived on 4、 Keepalived (1) MASTER (192.168.229.210) # vi /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { ## keepalived sendmail 。 SMTP router_id edu-proxy-01 ## , hostname } ## keepalived , vrrp_instance 。 0, weight 0, 。 0, weight 0, 。 , , priority 。 vrrp_script chk_nginx { script "/etc/keepalived/nginx_check.sh" ## nginx interval 2 ## weight -20 ## , -20 } ## ,VI_1 , vrrp_instance VI_1 { state MASTER ## MASTER, BACKUP interface eth1 ## IP , IP , eth1 virtual_router_id 51 ## ID , , IP , VRID , MAC mcast_src_ip 192.168.229.210 ## IP priority 100 ## , 0-254,MASTER BACKUP nopreempt ## nopreempt advert_int 1 ## , , 1s ## , authentication { auth_type PASS auth_pass 1111 ## , } ## track_script instance track_script { chk_nginx ## Nginx } ## IP , virtual_ipaddress { 192.168.229.200 ## ip, } } (2)BACKUP (192.168.229.211): # vi /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id edu-proxy-02 } vrrp_script chk_nginx { script "/etc/keepalived/nginx_check.sh" interval 2 weight -20 } vrrp_instance VI_1 { state BACKUP interface eth1 virtual_router_id 51 mcast_src_ip 192.168.229.211 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } track_script { chk_nginx } virtual_ipaddress { 192.168.229.200 } } 5、 Nginx /etc/keepalived/nginx_check.sh ( keepalived.conf ) : nginx , , keepalived ,keepalied ip BACKUP 。 : # vi /etc/keepalived/nginx_check.sh #!/bin/bash A=`ps -C nginx –no-header |wc -l` if [ $A -eq 0 ];then /usr/local/nginx/sbin/nginx sleep 2 if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then killall keepalived fi fi , : # chmod +x /etc/keepalived/nginx_check.sh 6、 Keepalived # service keepalived start Starting keepalived: [ OK ] 7、Keepalived+Nginx (1) 192.168.229.210 Nginx,Keepalived # /usr/local/nginx/sbin/nginx -s stop (2) 192.168.229.210 Keepalived,VIP 192.168.229.211 # service keepalived stop Keepalived , VIP VIP MAC,Windows CMD VIP 192.168.229.211 VIP Nginx , 192.168.229.211 (3) 192.168.229.210 Keepalived,VIP 192.168.229.210 # service keepalived start IP windows arp -a 192.168.229.200 arp -a 192.168.229.210 Keepalived : :service keepalived stop :service keepalived start :service keepalived restart :service keepalived status

좋은 웹페이지 즐겨찾기