分类: 系统运维
2014-05-15 17:30:58
网络环境::
系统版本:
软件资料:
ipvsadm-1.24.tar.gz 、keepalived-1.2.2.tar.gz
在LVS-Master、LVS-Salve操作
步骤一:建立内核软连接
//首先确定/usr/src/kernels中已存在内核目录,并与运行中的内核版本一致(重要!!!)
//反之,已上图为例,执行以下命令:
[root@master src]# yum -y install kernel-devel-2.6.32-431.1.2.0.1.el6.x86_64
[root@master src]# ln -s /usr/src/kernels/2.6.32-431.1.2.0.1.el6.x86_64/ /usr/src/linux
[root@master src]#reboot
步骤二:安装Ipvsadm
[root@master ~]# tar zxvf ipvsadm-1.24.tar.gz
[root@master ~]# cd ipvsadm-1.24
[root@master ~]# make
[root@master ~]# make install
//注意编译过程中是否有报错提示,解决之
//例: 报错提示:error: Popt libraries is required
// 解决办法:yum -y install popt* libraries*
分别执行ipvsadm
-v 、lsmod | grep ip_vs
//出现以上结果,说明ipvsadm已正确安装!
步骤三:安装keepalived
[root@master ~]# tar zxvf keepalived-1.2.2.tar.gz
[root@master keepalived-1.2.2]#
./configure
--prefix=/usr/local/keepalived/
--with-kernel-dir=/usr/src/kernels/2.6.32-431.1.2.0.1.el6.x86_64
//在配置中出现上图,方可!
[root@master keepalived-1.2.2]#make
[root@master keepalived-1.2.2]#make install
[root@master keepalived-1.2.2]# mkdir /etc/keepalived
[root@master keepalived-1.2.2]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@master keepalived-1.2.2]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@master keepalived-1.2.2]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@master keepalived-1.2.2]# cp /usr/local/keepalived/sbin/keepalived /sbin/
Keepalived服务启动方式:
service keepalived start|stop|restart
设置keepalived服务开机自启动:
chkconfig –level 3 keepalived on
步骤四:编辑LVS-Master keepalived.conf配置文件
[root@master ~]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
\\指定keepalived主备角色切换时发送email到收件人
}
notification_email_from \\指定keepalived主备角色切换时发出email的发件人
smtp_server **** \\指定Smtp服务器的地址
smtp_connect_timeout 30 \\指定smtp连接超时时间
router_id LVS_Master \\运行keepalived机器的一个标识
}
vrrp_instance VI_1 {
state MASTER \\指定身份标示,其主要有priority决定
interface eth0 \\实例绑定的网卡
virtual_router_id 51 \\ VPID标记
priority 100 \\优先权值
advert_int 1 \\检查间隔,默认1秒
authentication { \\设置认证
auth_type PASS \\认证机制
auth_pass 1111 \\认证密码
}
virtual_ipaddress { \\设置VIP
192.168.10.147 ip地址
}
}
virtual_server 192.168.10.147 80 {
delay_loop 6 \\指定健康检查间隔
lb_algo wlc rr|wrr|lc|wlc|lblc|sh|dh
lb_kind DR NAT|DR|RUN
nat_mask 255.255.255.0
persistence_timeout 50 \\会话保持时间
protocol TCP \\使用的时间
real_server 192.168.10.141 80 { \\指定真实服务器地址
weight 1 \\默认为1,0为失效
TCP_CHECK {
connect_timeout 3 \\连接超时时间
nb_get_retry 3 \\连接次数
delay_before_retry 3 \\重连间隔时间
connect_port 80 \\健康检查端口
}
}
real_server 192.168.10.142 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
步骤五:编辑vi /etc/rc.local,添加如下内容
步骤六: 开启路由转发模式:
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
执行sysctl -p /etc/sysctl.conf
在Server1、Server2上面操作
步骤一:建立脚本realserver.sh
步骤二:编辑vi /etc/rc.local 添加如下内容
########至此,LVS+Keepalived已搭建完毕,下面即可进行测试!!!