LVS负载均衡集群前端分发负载director节点的Keepa(2)

2、  将keepalived做成服务启动

#cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/       注释:拷贝服务启动文件

#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/      

#mkdir /etc/keepalived/                       注释:创建配置文件目录

#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/    注释:拷贝配置文件

#cp /usr/local/sbin/keepalived /usr/sbin/             注释:拷贝可执行文件

#service keepalived start                     注释:测试服务启动与关闭

#service keepalived stop

3、配置keepalived

在配置keepalived时发现这个软件用着比heartbeat要简单很多

主节点的配置

#vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

reaaa@163.com

}

notification_email_from Alexandre.Cassen@firewall.loc

smtp_server 127.0.0.1

router_id LVS_DEVEL

}

vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.2.120

}

}

virtual_server 192.168.2.120 8080 {

delay_loop 6

lb_algo wlc

lb_kind DR

persistence_timeout 1

protocol TCP

real_server 192.168.5.54 8080 {

weight 1

TCP_CHECK {

connect_timeout 1

nb_get_retry 3

delay_before_retry 3

connect_port 8080

}

}

real_server 192.168.5.57 8080 {

weight 1

TCP_CHECK {

connect_timeout 1

nb_get_retry 3

delay_before_retry 3

connect_port 8080

}

}

}

BACKUP节点配置:

#vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

renxiaotian@ninetowns.com

}

notification_email_from Alexandre.Cassen@firewall.loc

smtp_server 127.0.0.1

router_id LVS_DEVEL

}

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 51

priority 99

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.2.120

}

}

virtual_server 192.168.2.120 8080 {

delay_loop 6

lb_algo wlc

lb_kind DR

persistence_timeout 1

protocol TCP

real_server 192.168.5.54 8080 {

weight 1

TCP_CHECK {

connect_timeout 1

nb_get_retry 3

delay_before_retry 3

connect_port 8080

}

}

real_server 192.168.5.57 8080 {

weight 1

TCP_CHECK {

connect_timeout 1

nb_get_retry 3

delay_before_retry 3

connect_port 8080

}

}

}

注释:因为我用的tomcat后端8080端口没有修改为80,这个请读者自己按照自己的情况配置,包括各种IP与持久连接,realserver的数量,如果keepalived启动后查看后端的realserver没有达到自己配置的数量,那么就是端口没有指对。

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

转载注明出处:http://www.heiqu.com/4e0859c1f57c4a24fc4725baa9add96b.html