首页 技术 正文
技术 2022年11月14日
0 收藏 990 点赞 4,465 浏览 2755 个字

下载tar包

./configure –prefix=/usr/local/keepalived –with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ \      注意加内核

&&make && make install

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

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

cp /usr/local/keepalived/sbin/keepalived  /usr/sbin/

cp -r /usr/local/keepalived/etc/keepalived/ /etc   将配置文件 CP可到/etc

架构 192.168.10.129 httpd服务器 连的VIP    192.168.10.128 真实IP 为master   192.168.10.130 真实IP 为bakcup

配置文件  VIP需跟本地IP同一网段且IP未曾使用

master 配置

! Configuration File for keepalived
global_defs {
notification_email {
liu6630@qq.com
}
notification_email_from liu6630@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 100
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.111.111
}
}
virtual_server 192.168.111.111 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.128 3306 {
weight 100
notify_down /root/shell/mysql_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}

BACK_UP 配置

! Configuration File for keepalived
global_defs {
notification_email {
liu6630@qq.com
}
notification_email_from liu6630@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 100
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.111.111
}
}
virtual_server 192.168.111.111 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.130 3306 {
weight 100
notify_down /root/shell/mysql_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}

}

TCP_CHECK  模板只能 检测本机端口    notify_down检测到端口挂了执行 杀死keepalived 脚本

global_defs {
notification_email {
wgkgood@139.com
}
notification_email_from wgkgood@139.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}

vrrp_script chk_nginx {
script “/data/sh/nginx.sh”
interval 2
weight 2
}

vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 90
advert_int 5
authentication {
auth_type PASS
auth_pass 2222
}

track_script {
chk_nginx
}

virtual_ipaddress {
192.168.111.188
}
}

用脚本检测   脚本内容可为

BACKMSG= `ps -C nginx –noheader |wc -l `

if [ $BACKMSG -eq 0 ];then

  service keepalived stop

else

  exit  

fi

notify_master 脚本 放到VRRP实例
URL_CHECK
HTTP_GET

配置文件重启keeeplived

需手动加载 modprobe ip_vs  

排错

1.编译是否加了内核 没加内核不会启动检测 加了

2配置文件是否在 /etc/keepalivde 下  cp -r /usr/local/keepalived/etc/keepalived/ /etc                 最终配置文件/etc/keepalived/keepalived.cof

3是否加载modprobe ip_vs   未加载虚拟IP模块 有VIP也不能 其他服务也不能访问VIP

4是否VIP与真实IP同一网段且无IP冲突 

5VIP是否起来 可以用 ip addr list 查看

6 virtual_router_id  同一集群的keepalived的主、备机的virtual_router_id 必须相同,取值0-255 但是同一内网中不应有相同virtual_router_id的集群

7 查看/var/messages日志

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,136
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,301