若本机没有yum库,最好配置安装yum库,方便软件的安装
yum库创建基本步骤
①安装createrepo
②yum -y installl createrepo
③用createrepo创建
createrepo命令用于生成yum仓库所需要的一些基本配置信息。
具体请参考“yum库的安装于配置”
在Vmare虚拟机中虚拟四个Linux主机
LvsMaster:192.168.10.101
LvsBak: 192.168.10.102
RealServer1: 192.168.10.121
RealServer2: 192.168.10.122
主机之间的拓扑关系图
yum -y install *ipvsadm*
下载地址:wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar
安装依赖库:yum install -y openssl openssl-devel
下载keepalived:wget http://www.keepalived.org/software/keepalived-1.2.6.tar.gz
tar zxvf keepalived-1.2.6.tar.gz
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived /etc/keepalived.conf
LvsMaster配置
global_defs {
notification_email {
[email protected] #emial通知
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_sync_group test { #设置vrrp组
group {
loadbalance
}
}
vrrp_instance loadbalance {
state MASTER #设置主机类型,MASTER和BACKUP两种,必须大写 ,即太主机一台备用机
interface eth0 #设置对外服务网卡
virtual_router_id 51
priority 100 #设置优先级,备用主机的优先级要比主机低即可
advert_int 1#设置同步时间间隔
authentication {#设置验证类型和密码
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {#设置虚拟ip,即浮动ip
192.168.10.115
}
virtual_server 192.168.10.115 80 {
delay_loop 6 #健康检查时间间隔
lb_algo rr#负载调度算法,默认为轮训算法
lb_kind DR#负载均衡转发规则,也就是IP转发规则,DR转发方式最快,但是所有机器必须在一个网段内,还有NAT和TUNEL两种转发方式
protocol TCP
real_server 192.168.10.121 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.10.122 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
LvsBakr配置
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_sync_group test {
group {
loadbalance
}
}
vrrp_instance loadbalance {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.10.115
}
}
virtual_server 192.168.10.115 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.10.121 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.10.122 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
LvsMastrer: /etc/init.d/keepalived start
LvsBak : /etc/init.d/keepalived start
查看启动状态
LvsMaster: tail -f /var/log/messages
LvsBak: tail -f /var/log/messages
用ip addr和ipvsadm查看路由情况LvsMaster: ip addr
LvsMaster: ipvsadm
LvsBak:ip addr
LvsBak:ipvsadm