keepalived+DR

keepalived+DR
准备四台服务器

2台LVS 2台web

1.做LVS主备,都要安装ipvsadm和keepalived

yum -y install keepalived ipvsadm

LVS的主操作:

  更改keepalived的配置文件 vim /etc/keepalived/keepalived.conf

  vrrp_instance VI_1 {
    state MASTER \\初始状态
    interface eth0 \\VIP的网卡
    virtual_router_id 51
    priority 100 \\优先级
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    192.168.189.181 \\VIP地址
    }
  }

  virtual_server 192.168.189.181 80 { \\虚拟服务器
    delay_loop 6
    lb_algo rr \\算法
    lb_kind DR \\模式
    nat_mask 255.255.255.0 \\子网掩码
    protocol TCP \\虚拟服务器协议

    real_server 192.168.189.163 80 { \\真实服务器web1的ip地址和端口
      weight 1 \\权重
      TCP_CHECK { \\健康检查模块
        connect_timeout 3
        connect_port 80
        nb_get_retry 3
        delay_before_retry 3
       }
    }
    real_server 192.168.189.164 80 { \\真实服务器web2的ip地址和端口
      weight 1 \\权重
      TCP_CHECK { \\健康检查模块
        connect_timeout 3
        connect_port 80
        nb_get_retry 3
        delay_before_retry 3
      }
    }
  }

从:vrrp_instance VI_1 {
    state BACKUP \\初始状态
    interface eth0 \\VIP的网卡
    virtual_router_id 51
    priority 99 \\优先级
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    192.168.189.181 \\VIP地址
    }
  }

配置完毕,关闭防火墙和selinux,启动keepalived

查看VIP是否生成 ip a 出现真实ip和vip则为成功

ip a
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fc:d6:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.189.161/24 brd 192.168.189.255 scope global eth0
inet 192.168.189.181/32 scope global eth0

web服务配置

1.安装httpd并创建测试页面

yum -y install httpd vim /var/www/html/index.html

2.增加lo:0,并绑定vip (配置文件中添加的vip是keepalived配置文件中的vip)

3.修改arp级别

 

 

 

 

4.增加静态路由

 

 

 

 

5.关闭防火墙 开启Apache服务

 

 

全部配置完毕后,在LVS主?

posted @ 2019-12-05 10:59  Armored-forces  阅读(90)  评论(0)    收藏  举报