本文主要介绍了如何在redhat6.2环境下部署ipvsadm及keepalived实现基于socket高可用集群负载均衡的功能的方法、操作步骤以及需要注意的事项,希望对正在尝试使用基于lvs实现socket负载方式的博友提供一些参考和指导。
一、环境准备工作
1、关闭selinux:
vi /etc/selinux/config
把SELINUX=enforce 改成disabled
2、关闭防火墙(NAT负载模式需要根据业务需求配置iptables,DR模式请直接关掉)
chkconfig --level 2345 iptables off
chkconfig --level 2345 ip6tables off
iptables -F
service iptables stop
3、配置yum源
#配置本地yum源
1)挂载光盘
mount -o loop /dev/cdrom /mnt/media
2)新建本地yun源的配置文件
vi /etc/yum.repos.d/local.repo
加入以下信息:
[Local]
name=Local
baseurl=file:///mnt/media
enable=1
gpgcheck=0
3)yum clean all
二、高可用集群规划(DR负载模式,RR轮询调度)
浮动地址VIP:36.0.0.70
压测主机IP: 36.0.0.158
调度主机LBServer1:36.0.0.156
调度主机LBServer2: 36.0.0.157
应用主机realServer1:36.0.0.71
应用主机realServer2:36.0.0.72
应用主机realServer3:36.0.0.73
--------------------------------------------------------------
三、安装部署ipvs管理工具ipvsadm
#调度管理工具介质安装
1、确保Linux的kernel支持ipvs算法,检查内核是否支持
#modprobe -l|grep ipvs
2、使用rpm包安装
#rpm -ivh ipvsadm-1.24-13.el5.x86_64.rpm
3、检查ipvsadm是否完整安装
#lsmod|grep ip_vs
四、高可用介质keepalived安装
1、安装先决条件
#安装编译工具
#yum install make -y
#安装编译环境
#yum install gcc* -y
#安装依赖程序
#yum install openssl* -y
#yum install popt-devel -y
2、安装HA软件
解压程序包
#tar -zxvf keepalived1.2.2.tar.gz
#cd keepalived-1.2.2
#配置编译环境
#./configure
#编译安装
#make && make install
3、配置HA为系统服务
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#cp /usr/local/sbin/keepalived /usr/sbin/
#chkconfig --add keepalived
#chkconfig --level 2345 keepalived on #配置随机启动后 有时会导致ipvsadm无法启动 需要先停止keepalived 启动ipvsadm后 再重启keepalived
#chkconfig --level 2345 ipvsadm on
4、配置HA的配置文件
#mkdir /etc/keepalived
#编辑vi keepalived.conf
#其信息如下所示,备机需修改state和 priority,具体可参考LB服务器配置
-
! Configuration File for keepalived
-
-
global_defs {
-
router_id LVS_ESB
-
}
-
-
vrrp_instance VI_1 {
-
state MASTER
-
interface eth1
-
virtual_router_id 125
-
priority 100
-
advert_int 1
-
authentication {
-
auth_type PASS
-
auth_pass inzone
-
}
-
virtual_ipaddress {
-
36.0.0.70
-
}
-
}
-
-
virtual_server 36.0.0.70 9051{
-
delay_loop 6
-
lb_algo rr
-
lb_kind DR
-
protocol TCP
-
-
real_server 36.0.0.71 9051{
-
weight 1
-
TCP_CHECK {
-
connect_timeout 10
-
nb_get_retry 3
-
delay_before_retry 3
-
connect_port 9051
-
}
-
}
-
-
real_server 36.0.0.72 9051{
-
weight 1
-
TCP_CHECK {
-
connect_timeout 10
-
nb_get_retry 3
-
delay_before_retry 3
-
connect_port 9051
-
}
-
}
-
-
real_server 36.0.0.73 9051{
-
weight 1
-
TCP_CHECK {
-
connect_timeout 10
-
nb_get_retry 3
-
delay_before_retry 3
-
connect_port 9051
-
}
-
}
-
-
}
五、配置realServer
1、抑制ARP
# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
2、配置路由
#ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
#/sbin/route add -host $VIP dev lo:0
#sysctl -p > /dev/null 2>&1
六、HA服务的管理
停止主: service keepalived stop
启动主: service keepalived start
停止备: service keepalived stop
启动备: servive keepalived start
七、验证服务
telnet $vip port
阅读(1627) | 评论(0) | 转发(0) |