利用Keepalived实现LVS的高可用和web服务的高可用(4)

三、利用keepalived实现LVS的高可用

1、下载keepalived并安装

HA1:

下载keepalived-1.2.7-5.el5.i386.rpm包

[root@node1 ~]# lftp 172.16.0.1/pub/Sources

cd ok, cwd=/pub/Sources

lftp 172.16.0.1:/pub/Sources> cd keepalived/

cd ok, cwd=/pub/Sources/keepalived

lftp 172.16.0.1:/pub/Sources/keepalived> ls

-rwxr--r-- 1 500 500 203237 May 12 14:07 keepalived-1.2.7-5.el5.i386.rpm

-rwxr--r-- 1 500 500 318031 May 12 14:07 keepalived-1.2.7-5.el5.src.rpm

-rwxr--r-- 1 500 500 289380 May 11 09:47 keepalived-1.2.7.tar.gz

-rwxr--r-- 1 500 500 501864 May 12 14:07 keepalived-debuginfo-1.2.7-5.el5.i386.rpm

lftp 172.16.0.1:/pub/Sources/keepalived> get keepalived-1.2.7-5.el5.i386.rpm

203237 bytes transferred

lftp 172.16.0.1:/pub/Sources/keepalived> bye:

# yum -y --nogpgcheck localinstall keepalived-1.2.7-5.el5.i386.rpm 安装keepalived包

# scp keepalived-1.2.7-5.el5.i386.rpm node2:/root/ 复制软件包到node2上

# yum -y install ipvsadm 装上工具方便监测

HA2:

# wget ftp://172.16.0.1/pub/gls/server.repo -O /etc/yum.repos.d/server.repo 下载yum源

# yum -y --nogpgcheck localinstall keepalived-1.2.7-5.el5.i386.rpm 安装keepalived包

# yum -y install ipvsadm 装上工具方便监测

2、我们服务的转移情况

HA1:在主节点上

[root@node1 ~]# cd /etc/keepalived/

[root@node1 keepalived]# ls 查看配置文件

keepalived.conf keepalived.conf.haproxy_example notify.sh

[root@node1 keepalived]# cp keepalived.conf keepalived.conf.bak 备份主配置文件

[root@node1 keepalived]# vim keepalived.conf 修改内容如下:

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from keepavlied@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 79

priority 101

advert_int 1

authentication {

auth_type PASS

auth_pass keepalivedpass pass表示简单进行认证

}

virtual_ipaddress {

172.16.66.1 /16 dev eth0 lable eth0:0 这是我们的虚拟地址,要配置在网卡接口上的

}

virtual_server 172.16.66.1 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.0.0

# persistence_timeout 50 不需要持久连接的

protocol TCP

real_server 172.16.66.4 80 {

weight 1

HTTP_GET {

url {

path /

status_code 200

}

connect_timeout 2

nb_get_retry 3

delay_before_retry 1

}

}

real_server 172.16.66.5 80 {

weight 1

HTTP_GET {

url {

path /

status_code 200

}

connect_timeout 2

nb_get_retry 3

delay_before_retry 1

}

}

}

(vrrp_instance VI_1定义vrrp的虚拟路由,对于虚拟路由而言我们两端的特色初始状态一端为master,一端为backup,为master的一端要比backup的一端大点,当我们的服务遇到故障时要进行监测,并降低优先级,降低的优先级要比我们的备节点要小,减去降低的优先级后要比backup定义的优先级要小。)

[root@node1 keepalived]# scp keepalived.conf node2:/etc/keepalived/ 把配置文件复制到另一个节点一份

HA2:

[root@node1 keepalived]# vim keepalived.conf 修改如下内容:

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 79

priority 100 要比master的小

advert_int 1

authentication {

auth_type PASS

auth_pass keepalivedpass

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/5e3846fe684bdd8b7eb85277fdbb4ea5.html