生产环境模拟实现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 08:41
下一篇 2016-11-11 08:41

相关推荐

  • 1. 什么是Linux

        如果以前从没有接触过linux, 你可能会对为什么会存在这么多不同的linux发行版有些困惑. 在看linux软件包时, 你肯定听过发行版, LiveCD和GNU之类的等等术语, 也肯定摸不着头脑. 第一次接触linux,想理解会有些困难.  我们就先了解下linux系统内部结构的一些信息. &nbs…

    Linux干货 2016-10-26
  • shell编程之循环及函数

    for 循环 for 变量名 in 列表;do    循环体 done   执行机制: 依次将列表中的元素赋值给“变量名”; 每次赋值后即执行一次循环体; 直到列表中 的元素耗尽,循环结束   列表生成方式: (1)直接给出列表 (2)整数列表: (a) {start..end} (b) $(seq [start [s…

    Linux干货 2016-08-24
  • 8.9作业

    删除/etc/grub2.conf文件中所有以空白开头的行,行首的空白字符 [root@English6 ~]# sed "s@^[[:space:]]\+@@" /etc/grub.conf  # grub.conf generated by an…

    Linux干货 2016-08-11
  • 加密的应用

    加密的应用 一、实现对称加密 1、openssl enc man enc 算法:3des, aes, blowfish, twofish 加密操作:openssl enc -e -des3 -a -salt -in testfile -out testfile.cipher 解密操作:openssl enc  -d -des3 -a  -…

    Linux干货 2016-09-26
  • N25第六周作业

    vim编辑器 基本模式: 编辑模式,命令模式 输入模式 末行模式: 内置的命令行接口;   打开文件: # vim [options] [file ..] +#:打开文件后,直接让光标处于第#行的行首; +/PATTERN:打开文件后,直接让光标处于第一个被PATTERN匹配到的行的行首;   模式转换: 编辑模式:默认模式 编辑模式 &…

    Linux干货 2017-02-15
  • Linux进程查看与管理命令总结

    Linux进程查看与管理命令总结 内核的功能: 进程管理 文件系统 网络功能 内存管理 驱动程序 安全功能 Process:运行中程序的一个副本。(存在生命周期) Linux内核存储进程信息的固定格式:task struct 多个任务的task struct组件的链表:task list 进程创建: init 父子关系 进程:都有其父进程创建 fork(),…

    Linux干货 2016-09-07