设为首页 收藏本站
查看: 1303|回复: 0

[经验分享] 第10天 LVS及双机KEEPALIVED

[复制链接]

尚未签到

发表于 2018-12-29 11:47:50 | 显示全部楼层 |阅读模式
  1.yum install ipvsadm或www.linuxvirtualserver.org下载
  2.工作模式:NAT|TUN|DR;调度算法:rr,wrr,lc,wlc
  

  3.
  DR
  ipvsadm -A -t 192.168.8.100:80 -s rr
  ipvsadm -A -t 192.168.8.200:80 -s rr -p 60
  

  ipvsadm -a  -t 192.168.8.200:80   -r 192.168.8.11:80  -g -w 100
  ipvsadm -a  -t 192.168.8.200:80   -r 192.168.8.12:80  -g -w 100
  ipvsadm -a  -t 192.168.8.200:80   -r 192.168.8.13:80  -g -w 100
  

  ipvsadm -d -t 192.168.8.200:80   -r 192.168.8.14:80
  

  写入配置文件 cat /etc/sysconfig/ipvsadm
  -A -t 192.168.8.100:80 -s rr
  -A -t 192.168.8.200:80 -s rr -p 60
  -a -t 192.168.8.200:80 -r 192.168.8.11:80 -g -w 100
  -a -t 192.168.8.200:80 -r 192.168.8.12:80 -g -w 100
  -a -t 192.168.8.200:80 -r 192.168.8.13:80 -g -w 100
  

  NAT
  ip_forward=1
  iptables -t nat -A POSTROUTING -s 1.1.1.0/24 -o eth0 -j SNAT --to-source 2.2.2.2
  

  ipvsadm -A -t 192.168.8.150:80 -s rr
  ipvsadm -a -t 192.168.8.150:80 -r 172.20.20.20:80 -m -w 20
  ipvsadm -a -t 192.168.8.150:80 -r 172.20.20.21:80 -m -w 20
  ipvsadm -a -t 192.168.8.150:80 -r 172.20.20.22:80 -m -w 20
  

  

  4.DR模式,都要关闭VIP共用问题,避免arp解析异常,关闭重定向参数响应
  sysctl -w net.ipv4.conf.all.send_redirects=0
  sysctl -w net.ipv4.conf.default.send_redirects=0
  sysctl -w net.ipv4.conf.em1.send_redirects=0
  

  5.WEB节点REALSERVER服务器
  ifconfig lo:0 192.168.8.200 netmask 255.255.255.255
  route add -host 192.168.8.200 dev lo:0
  

  sysctl -w net.ipv4.conf.all.arp_ignore=1
  sysctl -w net.ipv4.conf.all.arp_announce=2
  sysctl -w net.ipv4.conf.default.arp_ignore=1
  sysctl -w net.ipv4.conf.default.arp_announce=2
  sysctl -w net.ipv4.conf.lo.arp_ignore=1
  sysctl -w net.ipv4.conf.lo.arp_announce=2
  

  

  

  6. KEEPALVED及LVS双机配置
  yum install kernel-devel openssl-devel popt-devel
  yum install keepalived或www.keepalived.org
  

  

  7.
  ! Configuration File for keepalived
  

  global_defs {
  notification_email {
  acassen@firewall.loc
  failover@firewall.loc
  sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id webrb1
  }
  

  vrrp_instance VI_rb1 {
  state MASTER
  interface em1
  virtual_router_id 51
  priority 100
  advert_int 1
  authentication {
  auth_type PASS
  auth_pass 11112222
  }
  virtual_ipaddress {
  192.168.8.100
  192.168.8.200
  }
  }
  

  

  8.
  ! Configuration File for keepalived
  

  global_defs {
  notification_email {
  acassen@firewall.loc
  failover@firewall.loc
  sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id webrb2
  }
  

  vrrp_instance VI_rb1 {
  state BACKUP
  interface em1
  virtual_router_id 51
  priority 90
  advert_int 1
  authentication {
  auth_type PASS
  auth_pass 11112222
  }
  virtual_ipaddress {
  192.168.8.100
  192.168.8.200
  }
  }
  

  

  9.
  分别启动服务
  service keepalived restart
  10.查看IP效果
  第1台: em1:  mtu 1500 qdisc mq state UP qlen 1000
  link/ether 90:b1:1c:11:98:ef brd ff:ff:ff:ff:ff:ff
  inet 172.22.2.180/24 brd 172.22.2.255 scope global em1
  inet 192.168.8.100/32 scope global em1
  inet 192.168.8.200/32 scope global em1
  inet6 fe80::92b1:1cff:fe11:98ef/64 scope link
  valid_lft forever preferred_lft forever
  

  第2台:
  em1:  mtu 1500 qdisc mq state UP qlen 1000
  link/ether 90:b1:1c:0e:97:1a brd ff:ff:ff:ff:ff:ff
  inet 172.22.2.181/24 brd 172.22.2.255 scope global em1
  inet6 fe80::92b1:1cff:fe0e:971a/64 scope link
  valid_lft forever preferred_lft forever
  

  Aug 27 13:11:22 cecgw-zs-cdb01 Keepalived[641]: Stopping Keepalived v1.2.7 (02/21,2013)
  Aug 27 13:11:22 cecgw-zs-cdb01 Keepalived_vrrp[643]: VRRP_Instance(VI_rb1) sending 0 priority
  Aug 27 13:11:22 cecgw-zs-cdb01 Keepalived_vrrp[643]: VRRP_Instance(VI_rb1) removing protocol VIPs.
  Aug 27 13:11:22 cecgw-zs-cdb01 avahi-daemon[9028]: Withdrawing address record for 192.168.8.100 on em1.
  Aug 27 13:11:22 cecgw-zs-cdb01 avahi-daemon[9028]: Withdrawing address record for 192.168.8.200 on em1.
  

  Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Entering MASTER STATE
  Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) setting protocol VIPs.
  Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.100
  Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.200
  Aug 27 13:11:24 cecgw-zs-cdb02 avahi-daemon[1806]: Registering new address record for 192.168.8.100 on em1.IPv4.
  Aug 27 13:11:24 cecgw-zs-cdb02 avahi-daemon[1806]: Registering new address record for 192.168.8.200 on em1.IPv4.
  Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_healthcheckers[30333]: Netlink reflector reports IP 192.168.8.100 added
  Aug 27 13:11:24 cecgw-zs-cdb02 Keepalived_healthcheckers[30333]: Netlink reflector reports IP 192.168.8.200 added
  Aug 27 13:11:29 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.100
  Aug 27 13:11:29 cecgw-zs-cdb02 Keepalived_vrrp[30334]: VRRP_Instance(VI_rb1) Sending gratuitous ARPs on em1 for 192.168.8.200
  

  

  

  11.KEEPALIVED配置LVS
  去除/etc/sysconfig/ipvsadm
  vi /etc/keepalived/keepalived.conf
  

  主
  ! Configuration File for keepalived
  

  global_defs {
  notification_email {
  acassen@firewall.loc
  failover@firewall.loc
  sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id webrb1
  }
  

  vrrp_instance VI_rb1 {
  state MASTER
  interface em1
  virtual_router_id 51
  priority 100
  advert_int 10
  authentication {
  auth_type PASS
  auth_pass 11112222
  }
  virtual_ipaddress {
  192.168.8.100
  192.168.8.200/24
  }
  

  virtual_server 192.168.8.200 80 {
  delay_loop 2
  lb_algo wrr
  lb_kind DR
  persistence_timeout 60
  protocol TCP
  real_server 192.168.8.11 80 {
  weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  }
  }
  

  real_server 192.168.8.12 80 {
  weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  }
  }
  

  real_server 192.168.8.13 80 {
  weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  }
  }
  

  }
  

  备
  ! Configuration File for keepalived
  

  global_defs {
  notification_email {
  acassen@firewall.loc
  failover@firewall.loc
  sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id webrb2
  }
  

  vrrp_instance VI_rb1 {
  state BACKUP
  interface em1
  virtual_router_id 51
  priority 90
  advert_int 10
  authentication {
  auth_type PASS
  auth_pass 11112222
  }
  virtual_ipaddress {
  192.168.8.100
  192.168.8.200
  }
  }
  

  virtual_server 192.168.8.200 80 {
  delay_loop 2
  lb_algo wrr
  lb_kind DR
  persistence_timeout 60
  protocol TCP
  real_server 192.168.8.11 80 {
  weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  }
  }
  

  real_server 192.168.8.12 80 {
  weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  }
  }
  

  real_server 192.168.8.13 80 {
  weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  }
  }
  

  }
  

  下面下载完整KEEPALIED+LVS操作步骤资料




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-657214-1-1.html 上篇帖子: KeepAlived1.1.17安装及配置说明 下篇帖子: keepalived配置lvs使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表