【乐虎国际电子游戏网址】利用keepalived实现lvs的高可用性

乐虎国际电子游戏网址 7

乐虎国际电子游戏网址 1

后三个落到实处基于前一个的底子上订正来的

配置keepalive

高可用的ipvs集群示例:更改keepalived配置文件

[root@234c27 keepalived]# vim /etc/keepalived/keepalived.conf
global_defs {
  notification_email {
   root@localhost
  }
  notification_email_from keepalived@localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id kpone
  vrrp _mcast_group4 234.10.10.10
}
vrrp_instance VI_1 {
  state MASTER
  interface ens37
  virtual_router_id 50
  priority 100
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 1111
  }
  virtual_ipaddress {
    10.0.0.100/24
  }
}
vrrp_instance VI_2 {
  state BACKUP
  interface ens37
  virtual_router_id 51
  priority 80
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 2222
  }
  virtual_ipaddress {
    10.0.0.200/24
  }
}
virtual_server 10.0.0.100 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.47 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}
virtual_server 10.0.0.200 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.57 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}

单主模型IPVS示例

lvs+keepalived是什么?

后端real_server准备

修改192.168.234.57的vip为10.0.0.200/32

  1 [root@234c27 keepalived]# ipvsadm -Ln
  2 IP Virtual Server version 1.2.1 (size=4096)
  3 Prot LocalAddress:Port Scheduler Flags
  4   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
  5 TCP  10.0.0.100:80 wrr
  6   -> 192.168.234.47:80            Route   1      0          0
  7 TCP  10.0.0.200:80 wrr
  8   -> 192.168.234.57:80            Route   1      0          0

乐虎国际电子游戏网址 2

后日宕掉多个lvs

  1 [root@234c27 keepalived]# systemctl stop keepalived.service
  2 [root@234c27 keepalived]# ipvsadm -Ln
  3 IP Virtual Server version 1.2.1 (size=4096)
  4 Prot LocalAddress:Port Scheduler Flags
  5   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
  6 

乐虎国际电子游戏网址 3

照例提供劳务

  1 [root@234c37 ~]# ipvsadm -Ln
  2 IP Virtual Server version 1.2.1 (size=4096)
  3 Prot LocalAddress:Port Scheduler Flags
  4   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
  5 TCP  10.0.0.100:80 wrr
  6   -> 192.168.234.47:80            Route   1      0          21
  7 TCP  10.0.0.200:80 wrr
  8   -> 192.168.234.57:80            Route   1      0          39

后叁个兑现基于前三个的功底上修改良改来的

让10.0.0.100的ip优分至192.168.234.47 192.168.234.57备用

查看keepalived

[root@234c37 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
…………
[root@234c37 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
//暂无ipvsadm

高可用的ipvs集群示例:修改keepalived配置文件

起步服务

[root@234c27 keepalived]# systemctl start keepalived.service
[root@234c27 keepalived]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-08-31 20:30:02 CST; 12s ago
  Process: 9657 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 9658 (keepalived)
………………
[root@234c27 keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.0.0.100:80 wrr
  -> 192.168.234.47:80            Route   1      0          0
  -> 192.168.234.57:80            Route   2      0          0
//启动服务lvs vs已配置好
virtual_server 10.0.0.200 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80 //这一行来修改 写出服务出错之后的页面
  real_server 192.168.234.57 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}

改良主机:192.168.234.27的keepalived配置文件

  1 [root@234c27 ~]# vim /etc/keepalived/keepalived.conf
  2 ! Configuration File for keepalived
  3 
  4 global_defs {
  5 notification_email {
  6 root@localhost  //接受邮件地址
  7 }
  8 notification_email_from keepalived@localhost  //发送邮件地址
  9 smtp_server 127.0.0.1  //发送邮件服务器IP
 10 smtp_connect_timeout 30  //邮件连接超时时长
 11 router_id kptwo  //路由id
 12 vrrp _mcast_group4 234.10.10.10  //指定vrrp协议的多播地址
 13 }
 14 
 15 vrrp_instance VI_1 {  //vrrp协议的
 16 state MASTER  //lvs的MASTER服务器
 17 interface ens37  //
 18 virtual_router_id 50  //虚拟路由
 19 priority 100  //权重为100.越大越先
 20 advert_int 1  //发送组博包的间隔
 21 authentication {  //验证
 22 auth_type PASS  //方式为pass( 明文)
 23 auth_pass 1111  //密码
 24 }
 25 virtual_ipaddress { //keepalived虚拟ip
 26 10.0.0.100/24
 27 }
 28 }
 29 virtual_server 10.0.0.100 80 {
 30     delay_loop 6  //检查后端服务器的时间间隔
 31     lb_algo wrr  //定义调度方法
 32     lb_kind DR  //集群的类型
 33     #persistence_timeout 50  //持久连接时长
 34     protocol TCP  //服务协议,仅支持TCP
 35     real_server 192.168.234.47 80 {  //后端real_server服务器地址
 36         weight 1 //权重
 37         HTTP_GET {  //应用层检测
 38             url {
 39               path /  //定义要监控的URL
 40               status_code 200  //判断上述检测机制为健康状态的响应码
 41             }
 42             connect_timeout 3  //连接请求的超时时长
 43             nb_get_retry 3  //重试次数
 44             delay_before_retry 3  //重试之前的延迟时长
 45         }
 46     }
 47     real_server 192.168.234.57 80 {
 48         weight 2
 49         HTTP_GET {
 50             url {
 51                 path /
 52                 status_code 200
 53             }
 54             connect_timeout 3
 55             nb_get_retry 3
 56             delay_before_retry 3
 57         }
 58     }
 59 }
 [root@234c37 ~]# ipvsadm -Ln
 IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port      Forward Weight ActiveConn InActConn
  TCP 10.0.0.100:80 wrr
   -> 192.168.234.47:80      Route  1   0     21
  TCP 10.0.0.200:80 wrr
   -> 192.168.234.57:80      Route  1   0     39

修正主机:192.168.234.27的keepalived配置文件

[root@234c27 keepalived]# vim /etc/keepalived/keepalived.conf
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id kpone
   vrrp _mcast_group4 234.10.10.10
}

vrrp_instance VI_1 {
    state MASTER
    interface ens37
    virtual_router_id 50
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       10.0.0.100/24
    }
}
vrrp_instance VI_2 {
    state BACKUP
    interface ens37
    virtual_router_id 51
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        10.0.0.200/24
    }
}
virtual_server 10.0.0.100 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP
    #sorry_server 127.0.0.1:80
    real_server 192.168.234.47 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
virtual_server 10.0.0.200 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP
    #sorry_server 127.0.0.1:80
    real_server 192.168.234.57 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

乐虎国际电子游戏网址 4

借使要促成sorry_server

1.把rs服务都停掉。然后在lvs上设置apache或许nginx服务

2.将keepalived配置文件中的

  1 virtual_server 10.0.0.200 80 {
  2     delay_loop 6
  3     lb_algo wrr
  4     lb_kind DR
  5     #persistence_timeout 50
  6     protocol TCP
  7     #sorry_server 127.0.0.1:80  //这一行来修改 写出服务出错之后的页面
  8     real_server 192.168.234.57 80 {
  9         weight 1
 10         HTTP_GET {
 11             url {
 12               path /
 13               status_code 200
 14             }
 15             connect_timeout 3
 16             nb_get_retry 3
 17             delay_before_retry 3
 18         }
 19     }
 20 }
  [root@234c27 keepalived]# ipvsadm -Ln
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
   -> RemoteAddress:Port      Forward Weight ActiveConn InActConn
  TCP 10.0.0.100:80 wrr
   -> 192.168.234.47:80      Route  1   0     0
  TCP 10.0.0.200:80 wrr
  -> 192.168.234.57:80      Route  1   0     0

配置keepalive

高可用的ipvs集群示例:修正keepalived配置文件

订正主机:192.168.234.37的keepalived配置文件

后端real_server准备

乐虎国际电子游戏网址 5

多主模型IPVS示例

乐虎国际电子游戏网址 6

[root@234c27 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost //接受邮件地址
}
notification_email_from keepalived@localhost //发送邮件地址
smtp_server 127.0.0.1 //发送邮件服务器IP
smtp_connect_timeout 30 //邮件连接超时时长
router_id kptwo //路由id
vrrp _mcast_group4 234.10.10.10 //指定vrrp协议的多播地址
}
vrrp_instance VI_1 { //vrrp协议的
state MASTER //lvs的MASTER服务器
interface ens37 //
virtual_router_id 50 //虚拟路由
priority 100 //权重为100.越大越先
advert_int 1 //发送组博包的间隔
authentication { //验证
auth_type PASS //方式为pass( 明文)
auth_pass 1111 //密码
}
virtual_ipaddress { //keepalived虚拟ip
10.0.0.100/24
}
}
virtual_server 10.0.0.100 80 {
 delay_loop 6 //检查后端服务器的时间间隔
 lb_algo wrr //定义调度方法
 lb_kind DR //集群的类型
 #persistence_timeout 50 //持久连接时长
 protocol TCP //服务协议,仅支持TCP
 real_server 192.168.234.47 80 { //后端real_server服务器地址
  weight 1 //权重
  HTTP_GET { //应用层检测
   url {
    path / //定义要监控的URL
    status_code 200 //判断上述检测机制为健康状态的响应码
   }
   connect_timeout 3 //连接请求的超时时长
   nb_get_retry 3 //重试次数
   delay_before_retry 3 //重试之前的延迟时长
  }
 }
 real_server 192.168.234.57 80 {
  weight 2
  HTTP_GET {
   url {
    path /
    status_code 200
   }
   connect_timeout 3
   nb_get_retry 3
   delay_before_retry 3
  }
 }
}

启航服务

乐虎国际电子游戏网址 7

照例提供劳务

改良主机:192.168.234.37的keepalived配置文件

[root@234c37 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id kptwo
   vrrp _mcast_group4 234.10.10.10
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens37
    virtual_router_id 50
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       10.0.0.100/24
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface ens37
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        10.0.0.200/24
    }
}
virtual_server 10.0.0.100 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP
    #sorry_server 127.0.0.1:80
    real_server 192.168.234.47 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
virtual_server 10.0.0.200 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP
    #sorry_server 127.0.0.1:80
    real_server 192.168.234.57 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

让10.0.0.100的ip优分至192.168.234.47 192.168.234.57备用

让10.0.0.200的ip优分至192.168.234.57 192.168.234.47备用

早先服务

扩充ip在网卡上 改善节制arp文告及应答等第 rs1 rs2都做,网关并指向路由

ip a a 10.0.0.100/32 dev ens37

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

route add default gw 192.168.234.17

设置httpd服务 写好网页文件

后端real_server准备

校正主机:192.168.234.37的keepalived配置文件

[root@234c37 ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id kptwo
   vrrp _mcast_group4 234.10.10.10
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens37
    virtual_router_id 50
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       10.0.0.100/24
    }
}
virtual_server 10.0.0.100 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP
    sorry_server 127.0.0.1:80
    real_server 192.168.234.47 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.234.57 80 {
        weight 2
        HTTP_GET {
            url {
              path /
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

单主模型IPVS示例

扩张ip在网卡上 匡正限定arp文告及应答品级rs1 rs2都做,网关并指向路由

高可用的ipvs集群示例:修正keepalived配置文件

设若要落到实处sorry_server

[root@234c37 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
  notification_email {
   root@localhost
  }
  notification_email_from keepalived@localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id kptwo
  vrrp _mcast_group4 234.10.10.10
}
vrrp_instance VI_1 {
  state BACKUP
  interface ens37
  virtual_router_id 50
  priority 80
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 1111
  }
  virtual_ipaddress {
    10.0.0.100/24
  }
}
vrrp_instance VI_2 {
  state MASTER
  interface ens37
  virtual_router_id 51
  priority 100
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 2222
  }
  virtual_ipaddress {
    10.0.0.200/24
  }
}
virtual_server 10.0.0.100 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.47 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}
virtual_server 10.0.0.200 80 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  #persistence_timeout 50
  protocol TCP
  #sorry_server 127.0.0.1:80
  real_server 192.168.234.57 80 {
    weight 1
    HTTP_GET {
      url {
       path /
       status_code 200
      }
      connect_timeout 3
      nb_get_retry 3
      delay_before_retry 3
    }
  }
}

校订主机:192.168.234.27的keepalived配置文件

乐虎国际电子游戏网址 8

ip a a 10.0.0.100/32 dev ens37
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
route add default gw 192.168.234.17
  [root@234c27 keepalived]# systemctl stop keepalived.service
  [root@234c27 keepalived]# ipvsadm -Ln
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port      Forward Weight ActiveConn InActConn

乐虎国际电子游戏网址 9

Leave a Comment.