hive+haproxy+keepalived高可用配置

来源:互联网 发布:linux sed命令 编辑:程序博客网 时间:2024/06/05 08:05

1、haproxy主

[root@csslave03 ~]# cat/etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------

# Example configuration for a possible webapplication.  See the

# full configuration options online.

#

#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt

#

#---------------------------------------------------------------------

 

#---------------------------------------------------------------------

# Global settings

#---------------------------------------------------------------------

global

   log         127.0.0.1 local2

   chroot      /var/lib/haproxy

   pidfile     /var/run/haproxy.pid

   maxconn     5000

   user        haproxy

   group       haproxy

   daemon

    #turn on stats unix socket

   stats socket /var/lib/haproxy/stats

 

#---------------------------------------------------------------------

# common defaults that all the 'listen' and'backend' sections will

# use if not designated in their block

#---------------------------------------------------------------------

defaults

       mode tcp                       

       retries 2                      

       option redispatch              

       option abortonclose         

       maxconn 1024                 

       timeout connect 1d          

       timeout client 1d              

       timeout server 1d             

       timeout check 2000          

       log 127.0.0.1 local0 err #[err warning info debug]

#---------------------------------------------------------------------

# listen

#---------------------------------------------------------------------

listen admin_stats               

       bind 0.0.0.0:1090         

       mode http                 

       maxconn 20                            

       stats refresh 30s         

       stats uri /               

       stats realm Hive\ Haproxy 

       stats auth admin:bigdata  

 

#---------------------------------------------------------------------

# static backend for serving up images,stylesheets and such

#---------------------------------------------------------------------

listen hive                                                                               

       bind 0.0.0.0:80                                                 

       mode tcp                                                          

       balance leastconn                                                 

       maxconn 1024                                                      

       server hive_1 192.168.*.*:10000 check inter 180000 rise 1 fall 2

       server hive_2 192.168.*.*:10000 check inter 180000 rise 1 fall 2

[root@csslave03 ~]# cat/etc/keepalived/keepalived.conf

! Configuration File for keepalived

 

global_defs {

  notification_email {

    yujinga@qq.com

   }

  notification_email_from Alexandre.Cassen@firewall.loc

  smtp_server smtp.qq.com

  smtp_connect_timeout 30

  router_id LVS_DEVEL

}

 

vrrp_script chk_haproxy {

       script "/root/haproxy.sh"

       weight -20

       interval 2                                    

}

 

vrrp_instance VI_1 {

   state MASTER

   interface eth0

   virtual_router_id 51

   priority 110

   advert_int 1

   track_script {

       chk_haproxy

    }

   authentication {

       auth_type PASS

       auth_pass 1111

    }

   virtual_ipaddress {

       192.168.*.*

    }

   notify_master /root/haproxy_master.sh

}

[root@csslave03 ~]# cat haproxy.sh

#!/bin/bash

A=`ps -C haproxy --no-header |wc -l`

#a=`ps -ef | grep haproxy| grep -v grep |wc-l`

if [ $A == 0 ]

   then

       /etc/init.d/keepalived stop

       echo "haproxy is down,stoping keepalive..."

   exit

fi

[root@csslave03 ~]# cat haproxy_master.sh

#!/bin/bash

sleep 3

/etc/init.d/haproxy reload && echo"haproxy is reload........"

2、haproxy从

haproxy主配置文件

[root@csslave04 ~]# cat/etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------

# Example configuration for a possible webapplication.  See the

# full configuration options online.

#

#  http://haproxy.1wt.eu/download/1.4/doc/configuration.txt

#

#---------------------------------------------------------------------

 

#---------------------------------------------------------------------

# Global settings

#---------------------------------------------------------------------

global

   log         127.0.0.1 local2

   chroot      /var/lib/haproxy

   pidfile     /var/run/haproxy.pid

   maxconn     5000

   user        haproxy

   group       haproxy

    daemon

    #turn on stats unix socket

   stats socket /var/lib/haproxy/stats

 

#---------------------------------------------------------------------

# common defaults that all the 'listen' and'backend' sections will

# use if not designated in their block

#---------------------------------------------------------------------

defaults

       mode tcp                       

       retries 2                      

       option redispatch              

       option abortonclose         

       maxconn 1024                 

       timeout connect 1d          

       timeout client 1d              

       timeout server 1d             

       timeout check 2000          

       log 127.0.0.1 local0 err #[err warning info debug]

#---------------------------------------------------------------------

# listen

#---------------------------------------------------------------------

listen admin_stats               

       bind 0.0.0.0:1090         

       mode http                 

       maxconn 20                            

       stats refresh 30s         

       stats uri /               

       stats realm Hive\ Haproxy 

       stats auth admin:bigdata  

 

#---------------------------------------------------------------------

# static backend for serving up images,stylesheets and such

#---------------------------------------------------------------------

listen hive                                                                               

       bind 0.0.0.0:80                                                 

       mode tcp                                                          

       balance leastconn                                                 

       maxconn 1024                                                       

       server hive_1 192.168.*.34:10000 check inter 180000 rise 1 fall 2

       server hive_2 192.168.*.42:10000 check inter 180000 rise 1 fall 2

                  

haproxy主keepalived配置文件

[root@csslave04 ~]# cat/etc/keepalived/keepalived.conf

! Configuration File for keepalived

 

global_defs {

  notification_email {

    yujinga@qq.com

   }

  notification_email_from Alexandre.Cassen@firewall.loc

  smtp_server smtp.qq.com

  smtp_connect_timeout 30

  router_id LVS_DEVEL

}

 

vrrp_instance VI_1 {

   state BACKUP

   interface eth0

   virtual_router_id 51

   priority 100

   advert_int 1

   authentication {

       auth_type PASS

       auth_pass 1111

    }

   virtual_ipaddress {

       192.168.*.*

    }

   notify_master /root/haproxy_master.sh

}

检查脚本      

[root@csslave04 ~]# cat haproxy_master.sh

#!/bin/bash

sleep 3

/etc/init.d/haproxy reload && echo"haproxy is reload........"

[root@csslave04 ~]#

3、cloudera管理页面配置


原创粉丝点击