系统运输
一、keepalive实现双主:
1.1实验准备
两台主机地址分别为172.20.10.9、172.20.10.10,
vip1为172.20.10.10,vip2为172.20.10.11
1.2通知脚本:
[ root @ node5/] # vim/etc/keepalived/notify.sh
#! /bin/bash
contact=\\&; quot; root@localhost\\&; quot;
通告( )。
local mailsubject=$(hostname ) to be $1,vip floating
本地邮件=$ ( date\\ & amp; quot; %f%t\\&; quot; vrrptransition,$(hostname ) changed to be $1
echo $ mailbody|mail-s $ mail subject $ contact
}
case $1 in
大师)
通告主程序
;
备份)
通知备份
;
自动)
通知故障
;
* )
echo Usage: $(basename $0) { master|backup >
exit 1
;
欧洲航空
1.3将node 5配置为vip1地址的主节点、vip2地址的备用节点
[ root @ node5~ ] # vim/etc/keepalived/keepalived.conf
! 配置文件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 node5
vrrp_mcast_group4 224.0.100.19
}
vrrp_instance VI_1 {
状态主控器
界面ens 33
virtual_router_id 51
优先级100
advert_int 1
授权{
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.20.10.10/28 devens 33 label ens 33:0
}
notify _ master/etc/keepalived/notify.sh master
notify _ backup/etc/keepalived/notify.sh backup
notify _ fault/etc/keepalived/notify.sh fault
}
vrrp_instance VI_2 {
状态备份
界面ens 33
virtual_router_id 52
优先级98
advert_int 1
授权{
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.20.10.11/28 devens 33 label ens 33:1
}
notify _ master/etc/keepalived/notify.sh master
notify _ backup/etc/keepalived/notify.sh backup
notify _ fault/etc/keepalived/notify.sh fault
}
1.4将node 6配置为vip1地址备用节点、vip2地址的主节点
[ root @ node6~~] # vim/etc/keepalived/keepalived.conf
! 配置文件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 node5
vrrp_mcast_group4 224.0.100.19
}
vrrp_instance VI_1 {
状态备份
界面ens 33
virtual_router_id 51
优先级98
advert_int 1
授权{
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.20.10.10/28 devens 33 label ens 33:0
}
notify _ master/etc/keepalived/notify.sh master
notify _ backup/etc/keepalived/notify.sh backup
notify _ fault/etc/keepalived/notify.sh fault
}
vrrp_instance VI_2 {
状态主控器
界面ens 33
virtual_router_id 52
优先级100
advert_int 1
授权{
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.20.10.11/28 devens 33 label ens 33:1
}
notify _ master/etc/keepalived/notify.sh master
notify _ backup/etc/keepalived/notify.sh backup
notify _ fault/etc/keepalived/notify.sh fault
}
1.5验证:
)1)首先打开node6节点的keepalived服务,确认IP地址、状态:
两个VIP地址都位于node6节点上:
)2)重新启动node5节点keepalived服务,验证IP地址和状态:
VIP1地址已经飘到了node5节点
二. Nginx Keepalived实现网站的高可用性
2.1实验准备:
两台主机:节点5的地址为172.20.10.9,节点6的节点为172.20.10.8
vip地址为172.20.10.10
2.2nginx配置
(1)节点5节点
[ root @ node5~ ] # yuminstallnginx-y
[ root @ node5/] # vim/usr/share/nginx/html/index.html
节点5 web page
[ root @ node5~ ] # systemctlstartnginx
)2)节点6节点
[ root @ node6/] # yum install-y nginx
[ root @ node6/] # vim/usr/share/nginx/html/index.html
node 6网络页面
[ root @ node 6至~ ] # systemctlstartnginx
2.3将node 5配置为vip主节点,并配置用于检查nginx的监视脚本:
[ root @ node5/] # vim/etc/keepalived/keepalived.conf
! 配置文件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 node5
vrrp_mcast_group4 224.0.100.19
}
vrrp_script chk_nginx {
script/usr/bin/kill all-0 nginx exit0||| exit 1
间隔1
微信5
桨2
rise 1
}
vrrp_instance VI_1 {
状态主控器
界面ens 33
virtual_router_id 51
优先级100
advert_int 1
授权{
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.20.10.10/28 devens 33 label ens 33:0
}
track_script {
chk_nginx
}
track_interface {
ens33
}
notify _ master/etc/keepalived/notify.sh master
notify _ backup/etc/keepalived/notify.sh backup
notify _ fault/etc/keepalived/notify.sh fault
}
[ root @ node5keepalived ] # systemctlstartkeepalived
2.4将node 6配置为vip备用节点,并配置用于检查nginx的监视脚本:
[ root @ node6/] # vim/etc/keepalived/keepalived.conf
! 配置文件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 node5
vrrp_mcast_group4 224.0.100.19
}
vrrp_script chk_nginx {
script/usr/bin/kill all-0 nginx exit0||| exit 1
间隔1
微信5
桨2
rise 1
}
vrrp_instance VI_1 {
状态备份
界面ens 33
virtual_router_id 51
优先级98
advert_int 1
授权{
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.20.10.10/28 devens 33 label ens 33:0
}
track_script {
chk_nginx
}
track_interface {
ens33
}
notify _ master/etc/keepalived/notify.sh master
notify _ backup/etc/keepalived/notify.sh backup
notify _ fault/etc/keepalived/notify.sh fault
}
[ root @ node6html ] # systemctlstartkeepalived
3 .验证:
3.1如果服务全部正常,则vip地址位于节点5上,并测试访问172.20.10.10的情况。
3.2down遗漏node5节点上的nginx服务时,观察vip地址及其访问情况:
如果vip地址漂浮在节点6节点、curl172.20.10.10中,则在访问时节点6节点
3.3在恢复节点5上的nginx服务时,vip地址漂浮在节点5节点上,访问172.20.10.10的是节点5上的nginx
详情请访问云服务器、域名注册、虚拟主机的问题,请访问西部数码代理商官方网站: www.chenqinet.cn