一环境介绍
主机名
ip
安装软件
nginx_mysql_m
192.168.255.67
keepalived+nginx
nginx_mysql_s
192.168.255.66
keepalived+nginx
mysql1
192.168.255.52
mysql、mysql-server
mysql2
192.168.255.57
mysql、mysql-server
二、keepalived配置
keepalived的配置和上一篇的类似
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id nginx_mysql_s
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh" # 检查nginx状态的脚本
interval 2
weight 3
}
vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id 66
priority 100 #backup这里要比100小
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.255.200
}
track_script {
chk_nginx
}
}
三、nginx的配置
因为这里nginx监听的是3306的端口,不需要web服务所以配置文件较简单,但是需要用到stream模块
在配置的时候需要添加上--w