Keepalived的主從架構(gòu)及主主架構(gòu)實(shí)例

前言

Keepalived的部署架構(gòu)

在上述拓?fù)浼軜?gòu)中在虛擬機(jī)DR1集晚,DR2中部署keepalived和Lvs作主從或主主架構(gòu),在后端虛擬機(jī)RS1换怖,RS2部署nginx搭建web站點(diǎn)甩恼。

注意:在部署keepalived之前先確保各節(jié)點(diǎn)之間的時(shí)間必須同步;然后確認(rèn)firewalld和selinux的狀態(tài)(關(guān)閉firewalld和設(shè)置selinux為permissive)沉颂;各節(jié)點(diǎn)之間可通過(guò)主機(jī)名進(jìn)行通信(可在/etc/hosts添加解析)条摸;確保對(duì)應(yīng)的物理接口支持使用MULTICAST通信。

Keepalived的主從架構(gòu)

- 搭建RS1和RS2
首先安裝nginx程序:

[root@RS1 ~]# yum install -y epel-release
[root@RS1 ~]# yum install -y nginx

然后編輯/etc/hosts文件:

[root@RS1 ~]# vim /etc/hosts
192.168.0.81 DR1.ilinux.io DR1
192.168.0.87 DR2.ilinux.io DR2
192.168.0.83 RS1.ilinux.io RS1
192.168.0.84 RS2.ilinux.io RS2

隨后修改/usr/share/nginx/html/index.html 內(nèi)容為如下:

[root@RS1 ~]# vim /usr/share/nginx/html/index.html
<h1>This is RS1 192.168.0.83</h1>

啟動(dòng)nginx:

[root@RS1 ~]# systemctl start nginx

關(guān)閉firewalld和修改selinux的狀態(tài)為permissive:

[root@RS1 ~]# systemctl stop firewalld
[root@RS1 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS1 ~]# setenforce 0

接著在RS1上配置lvs-dr的配置铸屉,首先創(chuàng)建rs腳本:

[root@RS1 ~]# vim RS.sh
#/bin/bash
vip=192.168.0.99
mask='255.255.255.255'

case $1 in
start)
        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 lo:0 $vip netmask $mask broadcast $vip up
        route add -host $vip dev lo:0
        ;;
stop)
        ifconfig lo:0 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
        ;;

*)
        echo "Usage $(basename $0) start|stop "
        exit 1
        ;;
esac

隨后執(zhí)行RS腳本:

[root@RS1 ~]# bash -x RS.sh start
+ vip=192.168.0.99
+ mask=255.255.255.255
+ case $1 in
+ echo 1
+ echo 1
+ echo 2
+ echo 2
+ ifconfig lo:0 192.168.0.99 netmask 255.255.255.255 broadcast 192.168.0.99 up
+ route add -host 192.168.0.99 dev lo:0

重復(fù)以上步驟并結(jié)合相應(yīng)的信息搭建RS2钉蒲。

- 搭建DR1
首先yum安裝keepalived和ipvsadm程序包:

[root@DR1 ~]# yum install -y ipvsadm keepalived

然后編輯/etc/hosts文件:

[root@DR1 ~]# vim /etc/hosts
192.168.0.81 DR1.ilinux.io DR1
192.168.0.87 DR2.ilinux.io DR2
192.168.0.83 RS1.ilinux.io RS1
192.168.0.84 RS2.ilinux.io RS2

隨后編輯/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 DR1 
   vrrp_mcast_group4 224.0.0.0.20
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface eno16777736
    virtual_router_id 1
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass ^&IUYH*&
    }
    virtual_ipaddress { 
        192.168.0.99/24 dev eno16777736 label eno16777736:0
    }
}

virtual_server 192.168.0.99 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
    
    real_server 192.168.0.83 80 {
        weight 1 
        HTTP_GET {
            url {
              path /index.html
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }   
        real_server 192.168.0.84 80 {
                weight 1 
                HTTP_GET {
                        url {
                                path /index.html
                                status_code 200
                        }
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
        }
}

啟動(dòng)keepalived,查看ipvsadm和接口的狀態(tài):

[root@DR1 ~]# systemctl start keepalived
[root@DR1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.0.99:http rr
  -> 192.168.0.83:http            Route   1      1          4         
  -> 192.168.0.84:http            Route   1      1          80        
[root@DR1 ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.81  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe21:59b9  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:21:59:b9  txqueuelen 1000  (Ethernet)
        RX packets 62277  bytes 72099132 (68.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 21742  bytes 2744670 (2.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno16777736:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.99  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 00:0c:29:21:59:b9  txqueuelen 1000  (Ethernet)

關(guān)閉firewalld和修改selinux的狀態(tài)為permissive:

[root@DR1 ~]# systemctl stop firewalld
[root@DR1 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@DR1 ~]# setenforce 0

- 搭建DR2
首先yum安裝keepalived和ipvsadm程序包:

[root@DR2 ~]# yum install -y ipvsadm keepalived

然后編輯/etc/hosts文件:

[root@DR2 ~]# vim /etc/hosts
192.168.0.81 DR1.ilinux.io DR1
192.168.0.87 DR2.ilinux.io DR2
192.168.0.83 RS1.ilinux.io RS1
192.168.0.84 RS2.ilinux.io RS2

隨后編輯/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 DR2
   vrrp_mcast_group4 224.0.0.0.20
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 1
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass ^&IUYH*&
    }
    virtual_ipaddress {
        192.168.0.99/24 dev ens33 label ens33:0
    }
}

virtual_server 192.168.0.99 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP

    real_server 192.168.0.83 80 {
        weight 1
        HTTP_GET {
            url {
              path /index.html
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
        real_server 192.168.0.84 80 {
                weight 1
                HTTP_GET {
                        url {
                                path /index.html
                                status_code 200
                        }
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
        }
}

最后啟動(dòng)keepalived并查看ipvsadm的狀態(tài):

[root@DR2 ~]# systemctl start keepalived
[root@DR2 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.0.99:80 rr
  -> 192.168.0.83:80              Route   1      0          0         
  -> 192.168.0.84:80              Route   1      0          0         
[root@DR2 ~]# ifconfig    #因?yàn)镈R2的角色為BACKUP彻坛,因此不會(huì)創(chuàng)建Ip為192.168.0.99的子接口
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.87  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::5e4b:719d:3781:43a0  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::4c6e:8b7e:2dcd:665d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:26:a3:20  txqueuelen 1000  (Ethernet)
        RX packets 34041  bytes 27376635 (26.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14131  bytes 2169836 (2.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 101  bytes 8902 (8.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 101  bytes 8902 (8.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

關(guān)閉firewalld和修改selinux的狀態(tài)為permissive:

[root@DR2 ~]# systemctl stop firewalld
[root@DR2 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@DR2 ~]# setenforce 0

- 測(cè)試訪問(wèn)
在客戶端上測(cè)試訪問(wèn)vip所提供的服務(wù):

[root@client ~]# for i in {1..10} ; do curl http://192.168.0.99; done
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>

此時(shí)DR1為主機(jī)顷啼,DR2為備機(jī),兩者都工作正常昌屉,因此請(qǐng)求連接是由DR1來(lái)處理钙蒙。

那么我們模擬DR1宕機(jī),把DR1的服務(wù)停用后间驮,再來(lái)觀察DR2的狀態(tài)和客戶端的訪問(wèn)情況躬厌。
DR2的keepalived狀態(tài):

[root@DR2 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-05-29 14:34:08 CST; 1h 29min ago
  Process: 11808 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 11809 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─11809 /usr/sbin/keepalived -D
           ├─11810 /usr/sbin/keepalived -D
           └─11811 /usr/sbin/keepalived -D

May 29 16:03:06 DR2 Keepalived_vrrp[11811]: VRRP_Instance(VI_1) removing protocol VIPs.
May 29 16:03:47 DR2 Keepalived_vrrp[11811]: VRRP_Instance(VI_1) Transition to MASTER STATE
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: VRRP_Instance(VI_1) Entering MASTER STATE
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: VRRP_Instance(VI_1) setting protocol VIPs.
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: Sending gratuitous ARP on ens33 for 192.168.0.99
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.0.99
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: Sending gratuitous ARP on ens33 for 192.168.0.99
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: Sending gratuitous ARP on ens33 for 192.168.0.99
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: Sending gratuitous ARP on ens33 for 192.168.0.99
May 29 16:03:48 DR2 Keepalived_vrrp[11811]: Sending gratuitous ARP on ens33 for 192.168.0.99

DR2檢測(cè)到DR1的宕機(jī),主動(dòng)變成了MASTER狀態(tài)竞帽。

在客戶端的訪問(wèn)情況:

[root@client ~]# for i in {1..10} ; do curl http://192.168.0.99; done
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>

此時(shí)DR1模擬為宕機(jī)狀態(tài)扛施,DR2為MASTER,客戶端的訪問(wèn)不受影響屹篓。

Keepalived的主主架構(gòu)

此處以上面主從架構(gòu)的拓?fù)錇槔碓瑢⒅鲝募軜?gòu)更改為主主架構(gòu),首先我們需更改DR1和DR2的keepalived的配置堆巧,然后要在RS1和RS2上添加lvs-dr中與192.168.0.98虛擬IP相關(guān)的配置妄荔。
- 修改DR1
編輯/etc/keepalived/keepalived.conf文件

[root@DR1 ~]# vim /etc/keepalived/keepalived.conf
#添加如下配置
vrrp_instance VI_2 {
    state BACKUP
    interface eno16777736
    virtual_router_id 2
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass POM123(*
    }
    virtual_ipaddress {
        192.168.0.98/24 dev eno16777736 label eno16777736:1
    }
}
#添加虛擬服務(wù)器組backend
virtual_server_group backend {
        192.168.0.99 80
        192.168.0.98 80
}

#修改虛擬服務(wù)器調(diào)用虛擬服務(wù)器組
virtual_server group backend {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP

    real_server 192.168.0.83 80 {
        weight 1
        HTTP_GET {
            url {
              path /index.html
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
        real_server 192.168.0.84 80 {
                weight 1
                HTTP_GET {
                        url {
                                path /index.html
                                status_code 200
                        }
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
        }
}

停用再啟動(dòng)keepalived:

[root@DR1 ~]# systemctl stop keepalived
[root@DR1 ~]# systemctl start keepalived

此時(shí)ipvsadm和接口的狀態(tài)為:

[root@DR2 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.0.98:80 rr
  -> 192.168.0.83:80              Route   1      0          0         
  -> 192.168.0.84:80              Route   1      0          0         
TCP  192.168.0.99:80 rr
  -> 192.168.0.83:80              Route   1      0          0         
  -> 192.168.0.84:80              Route   1      0          0           
[root@DR1 ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.81  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe21:59b9  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:21:59:b9  txqueuelen 1000  (Ethernet)
        RX packets 63844  bytes 72282542 (68.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 23654  bytes 2934901 (2.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno16777736:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.99  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 00:0c:29:21:59:b9  txqueuelen 1000  (Ethernet)

- 修改DR2
編輯/etc/keepalived/keepalived.conf文件:

[root@DR2 ~]# vim /etc/keepalived/keepalived.conf
#添加如下配置
vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 2
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass POM123(*
    }   
    virtual_ipaddress {
        192.168.0.98/24 dev ens33 label ens33:1
    }           
}
#添加虛擬服務(wù)器組backend
virtual_server_group backend {
        192.168.0.99 80
        192.168.0.98 80
}
#修改虛擬服務(wù)器調(diào)用虛擬服務(wù)器組
virtual_server group backend {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP

    real_server 192.168.0.83 80 {
        weight 1
        HTTP_GET {
            url {
              path /index.html
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
        real_server 192.168.0.84 80 {
                weight 1
                HTTP_GET {
                        url {
                                path /index.html
                                status_code 200
                        }
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
        }
}

停用再啟動(dòng)keepalived:

[root@DR2 ~]# systemctl stop keepalived
[root@DR2 ~]# systemctl start keepalived

此時(shí)ipvsadm和接口的狀態(tài)為:

[root@DR2 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.0.98:80 rr
  -> 192.168.0.83:80              Route   1      0          0         
  -> 192.168.0.84:80              Route   1      0          0         
TCP  192.168.0.99:80 rr
  -> 192.168.0.83:80              Route   1      0          0         
  -> 192.168.0.84:80              Route   1      0          0         
[root@DR2 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.87  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::5e4b:719d:3781:43a0  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::4c6e:8b7e:2dcd:665d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:26:a3:20  txqueuelen 1000  (Ethernet)
        RX packets 39989  bytes 28047325 (26.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20816  bytes 2894556 (2.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.98  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 00:0c:29:26:a3:20  txqueuelen 1000  (Ethernet)

- 配置RS1和RS2
復(fù)制編輯RS腳本:

[root@RS1 ~]# cp RS.sh RS_new.sh
#/bin/bash

#修改vip為192.168.0.98
vip=192.168.0.98  
mask='255.255.255.255'

case $1 in
start)
        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 lo:1 $vip netmask $mask broadcast $vip up    #修改接口為lo:1
        route add -host $vip dev lo:1  #修改接口為lo:1
        ;;
stop)
        ifconfig lo:1 down    #修改接口為lo:1
        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
        ;;

*)
        echo "Usage $(basename $0) start|stop "
        exit 1
        ;;
esac

運(yùn)行腳本:

[root@RS1 ~]# bash -x RS_new.sh start
+ vip=192.168.0.98
+ mask=255.255.255.255
+ case $1 in
+ echo 1
+ echo 1
+ echo 2
+ echo 2
+ ifconfig lo:1 192.168.0.98 netmask 255.255.255.255 broadcast 192.168.0.98 up
+ route add -host 192.168.0.98 dev lo:1

在RS2 上也按照如上步驟執(zhí)行操作即可泼菌。

- 測(cè)試訪問(wèn)
此時(shí)在客戶端通過(guò)192.168.0.99和192.168.0.98均能訪問(wèn)到后端RS所提供的web服務(wù):

[root@client ~]# for i in {1..10} ; do curl http://192.168.0.98; done
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
[root@client ~]# for i in {1..10} ; do curl http://192.168.0.99; done
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>

在客戶端上編輯/etc/hosts,添加域名解析到99和98:

[root@client ~]# vim /etc/hosts
192.168.0.99 www.ilinux.io
192.168.0.98 www.ilinux.io

此時(shí)通過(guò)域名解析能使得只要有99和98有一個(gè)正常工作懦冰,客戶端均能正常訪問(wèn)服務(wù)灶轰。

[root@client ~]# for i in {1..10} ; do curl http://www.ilinux.io; done
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
<h1>This is RS2 192.168.0.84</h1>
<h1>This is RS1 192.168.0.83</h1>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市刷钢,隨后出現(xiàn)的幾起案子笋颤,更是在濱河造成了極大的恐慌,老刑警劉巖内地,帶你破解...
    沈念sama閱讀 211,743評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件伴澄,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡阱缓,警方通過(guò)查閱死者的電腦和手機(jī)非凌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,296評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)荆针,“玉大人敞嗡,你說(shuō)我怎么就攤上這事『奖常” “怎么了喉悴?”我有些...
    開(kāi)封第一講書(shū)人閱讀 157,285評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)玖媚。 經(jīng)常有香客問(wèn)我箕肃,道長(zhǎng),這世上最難降的妖魔是什么今魔? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,485評(píng)論 1 283
  • 正文 為了忘掉前任勺像,我火速辦了婚禮,結(jié)果婚禮上错森,老公的妹妹穿的比我還像新娘吟宦。我一直安慰自己,他們只是感情好涩维,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,581評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布殃姓。 她就那樣靜靜地躺著,像睡著了一般激挪。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上锋叨,一...
    開(kāi)封第一講書(shū)人閱讀 49,821評(píng)論 1 290
  • 那天垄分,我揣著相機(jī)與錄音,去河邊找鬼娃磺。 笑死薄湿,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播豺瘤,決...
    沈念sama閱讀 38,960評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼吆倦,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了坐求?” 一聲冷哼從身側(cè)響起蚕泽,我...
    開(kāi)封第一講書(shū)人閱讀 37,719評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎桥嗤,沒(méi)想到半個(gè)月后须妻,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,186評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡泛领,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,516評(píng)論 2 327
  • 正文 我和宋清朗相戀三年荒吏,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片渊鞋。...
    茶點(diǎn)故事閱讀 38,650評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡绰更,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出锡宋,到底是詐尸還是另有隱情儡湾,我是刑警寧澤,帶...
    沈念sama閱讀 34,329評(píng)論 4 330
  • 正文 年R本政府宣布员辩,位于F島的核電站盒粮,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏奠滑。R本人自食惡果不足惜丹皱,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,936評(píng)論 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望宋税。 院中可真熱鬧摊崭,春花似錦、人聲如沸杰赛。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,757評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)乏屯。三九已至根时,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間辰晕,已是汗流浹背蛤迎。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,991評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留含友,地道東北人替裆。 一個(gè)月前我還...
    沈念sama閱讀 46,370評(píng)論 2 360
  • 正文 我出身青樓校辩,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親辆童。 傳聞我的和親對(duì)象是個(gè)殘疾皇子宜咒,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,527評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容