cfsky 发表于 2018-12-29 12:25:10

ipvsadm与keepalived整合

1.准备两台虚拟服务器(DR),分别安装ipvsadm和keepalived
yum -y install ipvsadm
yum -y install keepalived  

2.配置keepalived.conf
      #修改IP为192.168.2.137的DR
vi /etc/keepalived/keepalived.conf
#修改内容如下
! Configuration File for keepalived
global_defs {
   notification_email {
root@localhost
   }
   notification_email_from lvs@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.2.150/24 dev eth0 label eth0:1
    }
}
virtual_server 192.168.2.150 8080 {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 192.168.2.137 8080 {
      weight 1
      HTTP_GET {
            url {
            path /
      status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
      }
    }
    real_server 192.168.2.138 8080 {
      weight 1
      HTTP_GET {
            url {
            path /
      status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
      }
    }
}
#修改IP为192.168.2.138的DR
vi /etc/keepalived/keepalived.conf
#修改内容如下
! Configuration File for keepalived
global_defs {
   notification_email {
root@localhost
   }
   notification_email_from lvs@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 110
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.2.150/24 dev eth0 label eth0:1
    }
}
virtual_server 192.168.2.150 8080 {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 192.168.2.137 8080 {
      weight 1
      HTTP_GET {
            url {
            path /
      status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
      }
    }
    real_server 192.168.2.138 8080 {
      weight 1
      HTTP_GET {
            url {
            path /
      status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
      }
    }
}  

3.准备两台RealServer(RS)
IP为:
192.168.2.137
192.168.2.138  

4.分别为RealServer安装httpd服务
yum -y install httpd  

5.启动httpd
service httpd start  

6.启动keepalived
service keepalived start
#可以查看一个是主,一个是从
ifconfig  

7.请求192.168.2.150:8080可以看到访问结果
  




页: [1]
查看完整版本: ipvsadm与keepalived整合