生产环境模拟实现keepalived+Nginx调度器+httpd的高可用集群

blob.png

具体过程是用Nginx做负载均衡,可以将Nginx和主机放在同一台机子上,也可以分开放置,只不过分开的话要指明RS是Nginx的主机地址。至于直接将虚拟地址配置在Nginx主机上我暂时还未成功

blob.png

blob.png

blob.png

blob.png

blob.png

blob.png

blob.png

生产环境模拟实现keepalived+Nginx调度器+httpd的高可用集群

blob.png

blob.png

下面附上我的双主模型的主keepalived服务器的配置

! Configuration File for keepalived

global_defs {
   notification_email {
    root@localhost
    vrrp_mcast_group4  224.0.11.100
   }
   notification_email_from kaadmin@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id sjf1
}

vrrp_script  chk_mantaince  {
    script "[[  -e /etc/keepalived/down  ]]  && exit 1 || exit 0"
    interval 1
    weight  -4        }

vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 15
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 11111234
    }
    virtual_ipaddress {        11.1.0.11/16 dev eth1    
    }

    track_script {
    chk_mantaince 
    }

   notify_master   "/etc/keepalived/inotify.sh  master"
   notify_backup   "/etc/keepalived/inotify.sh  backup"
   notify_fault    "/etc/keepalived/inotify.sh  fault"}
virtual_server 11.1.0.11 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR  #  persistence_timeout 50
    protocol TCP

    sorry_server 11.1.0.201  80

    real_server 11.1.0.203  80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 11.1.0.204  80 {
         weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth1
    virtual_router_id 16
    priority 97
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {        11.1.0.22/16 dev eth1    
    }

    track_script {
    chk_mantaince 
    }

   notify_master   "/etc/keepalived/inotify.sh  master"
   notify_backup   "/etc/keepalived/inotify.sh  backup"
   notify_fault    "/etc/keepalived/inotify.sh  fault"}
virtual_server 11.1.0.22 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR  #  persistence_timeout 50
    protocol TCP

    sorry_server 11.1.0.201  80

    real_server 11.1.0.205  80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 11.1.0.206  80 {
         weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

下面附上我的从keepalived的配置

! Configuration File for keepalived

global_defs {
   notification_email {
    root@localhost
    vrrp_mcast_group4  224.0.11.100
   }
   notification_email_from kaadmin@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id sjf2
}

vrrp_script  chk_mantaince  {
    script "[[  -e /etc/keepalived/down  ]]  && exit 1 || exit 0"
    interval 1
    weight  -4        }

vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 15
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 11111234
    }
    virtual_ipaddress {        11.1.0.11/16 dev eth1    
    }

    track_script {
    chk_mantaince 
    }

   notify_master   "/etc/keepalived/inotify.sh  master"
   notify_backup   "/etc/keepalived/inotify.sh  backup"
   notify_fault    "/etc/keepalived/inotify.sh  fault"}
virtual_server 11.1.0.11 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR  #  persistence_timeout 50
    protocol TCP

    sorry_server 11.1.0.201  80

    real_server 11.1.0.203  80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 11.1.0.204  80 {
         weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface eth1
    virtual_router_id 16
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {        11.1.0.22/16 dev eth1    
    }

    track_script {
    chk_mantaince 
    }

   notify_master   "/etc/keepalived/inotify.sh  master"
   notify_backup   "/etc/keepalived/inotify.sh  backup"
   notify_fault    "/etc/keepalived/inotify.sh  fault"}
virtual_server 11.1.0.22 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR  #  persistence_timeout 50
    protocol TCP

    sorry_server 11.1.0.201  80

    real_server 11.1.0.205  80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 11.1.0.206  80 {
         weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

下面在附上我的设置虚拟网络的脚本

#!/bin/bash
vip='11.1.0.11
'vport='80'
netmask='255.255.255.255'
iface='lo:0'case $1 instart)       
 echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore        
 echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore       
 echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce        
 echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
        ifconfig $iface  $vip  netmask $netmask  broadcast $vip up
        route add -host $vip dev $iface
        ;;
stop)
        ifconfig $iface down        
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore 
        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore 
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce 
        echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce 
esac

下面附上我的跟踪脚本

#!/bin/bash
#auth sjf
#date 2016.11.1
vip=192.16.11.99contact='root@localhost'notify() {
        mailsubject="`hostname` to be $1 ;@vip floating "
        mailbody="`date   +'%F %H:%M%S'`  ;vrrp transited , `hostname ` changed to be $1    "
        echo $mailbody | mail -s "$mailsubject"  $contact}case "$1" inmaster)
        notify master        exit 0
        ;;
backup)
        notify  backup        exit 0
        ;;
fault)
        notify fault        exit 0
        ;;
*)        echo 'Usage: `basename $0` {maser|backup|fault} '
        exit 1esac

原创文章,作者:sjfbjs,如若转载,请注明出处:http://www.178linux.com/56626

(0)
sjfbjssjfbjs
上一篇 2016-11-11
下一篇 2016-11-11

相关推荐

  • 系统时间与硬件时间

    1. “系统时间”与“硬件时间”    系统时间: 一般说来就是我们执行 date 命令看到的时间,linux系统下所有的时间调用(除了直接访问硬件时间的命令)都是使用的这个时间。    硬件时间: 主板上BIOS中的时间,由主板电池供电来维持运行,系统开机时要读取这个时间,并根…

    Linux干货 2016-08-05
  • Centos下实现多网卡绑定

    实现多网卡绑定在Centos6和Centos7可采用bonding方式,Centos7上team网络组也可实现,并且功能更强大。 Linux bonding 模块提供一种将多个网卡聚合成一块逻辑捆绑网卡的实现方法。 捆绑的网卡拥有多种模式,根据模式的特性,可实现网络负载均衡,网络冗余切换,提高网络吞吐量等功能。 大多流行Linux发行版都已装载bonding…

    Linux干货 2016-09-13
  • sed命令初识

           sed是一种流编辑器,它是文本处理中非常常用的工具,能够配合正则表达式使用。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。Sed主要用来自…

    Linux干货 2017-12-03
  • 文本处理

    cat,tac,rev,more,less,head,tail,cut,wc,sort,uniq,grep,
    正则表达式,扩展正则表达式

    2018-03-13
  • 第一次发微博

    第一次申请微博,第一次发微博,觉得很难

    Linux干货 2017-01-06
  • 关于touch/>/>>创建同名文件的总结

    一、简介 1、touch     即创建文件或修改文件时间     语法:touch [options] file-list 2、>     创建文件,可直接把内容生成到指定文件,会覆盖源文件中的内容;也可以直接生成一个空白文件。     语法:> file…

    2017-02-18