安装keepalived

安装keepalived

在主D(主负载服务器)上,安装keepalived

$ mkdir /mnt/iso1
# 挂载iso镜像文件到系统目录/mnt/iso1上
$ mount -o loop Keepalived.iso /mnt/iso1
$ cp -a /mnt/iso1/* .
# 由于需要C语言编译,安装gcc编译环境
$ yum -y install gcc gcc-c++
$ tar -zxvf keepalived-1.2.2.tar.gz
$ cd keepalived-1.2.2
# 安装keepalived相关依赖
$ yum -y install kernel-devel openssl-devel popt-devel
$ ./configure –prefix=/ –with-kernel-dir=/usr/src/kernels…
$ make && make install
# 设置开机自启
$ ls -l /etc/init.d/keepalived
$ chkconfig –add keepalived
$ chkconfig keepalived on
# 修改keepalived配置文件
$ vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
router_id LVS # 配置唯一组
}

vrrp_instance VI_1 {
state MASTER # 定义为主服务器
interface eth0 # 定义监控eth0网卡
virtual_router_id 66 # 定义组id
priority 80 # 定义权重id,最大150,和从相差50
advert_int 1 # 定义检测间隔1秒
authentication { # 认证
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { # 集群ip
10.10.10.100
}
}

virtual_server 10.10.10.100 80 {
delay_loop 2 #
lb_algo rr # 轮询策略
lb_kind DR # DR负载模式
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP

real_server 10.10.10.12 80 { # 真实服务器
weight 1 # 权重1
TCP_CHECK {
connect_port 80
connect_timeout 3 # 3秒超时
nb_get_retry 3 # 重试3次
delay_before_retry 4 # 间隔4秒
}
}
real_server 10.10.10.13 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}

# 启动keepalived
$ service keepalived start

Leave Comment

电子邮件地址不会被公开。 必填项已用*标注