标签:业务 serve ip add http 测试 var proxy 邮件发送 tail
集群介绍[root@akuilinux01 ~]# > /etc/keepalived/keepalived.conf
[root@akuilinux01 ~]# vim !$
vim /etc/keepalived/keepalived.conf
global_defs { #这个全局定义参数
notification_email { #出现问题给邮箱发邮件,
aming@aminglinux.com
}
notification_email_from root@aminglinux.com #由哪一个邮件发送
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx { #检测一个服务是否正常,需要有个脚本
script "/usr/local/sbin/check_ng.sh"
interval 3 # 3秒检测一次
}
vrrp_instance VI_1 { # 定义master相关的
state MASTER #如果是从就是backup
interface ens33 #定义网卡
virtual_router_id 51 # 定义路由器的id
priority 100 #定义权重
advert_int 1
authentication { #认证相关
auth_type PASS
auth_pass aminglinux>com
}
virtual_ipaddress { #定义vip(公有的ip)
192.168.21.100
}
track_script { #加载服务
chk_nginx
}
}
[root@akuilinux01 ~]# vim /usr/local/sbin/check_ng.sh
#!/bin/bash
#时间变量,用于记录日志
d=`date --date today +%Y%m%d_%H:%M:%S`
#计算nginx进程数量
n=`ps -C nginx --no-heading|wc -l`
#如果进程为0,则启动nginx,并且再次检测nginx进程数量,
#如果还为0,说明nginx无法启动,此时需要关闭keepalived(防止脑裂)
if [ $n -eq "0" ]; then
/etc/init.d/nginx start
n2=`ps -C nginx --no-heading|wc -l`
if [ $n2 -eq "0" ]; then
echo "$d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
[root@akuilinux01 ~]# chmod 755 /usr/local/sbin/check_ng.sh
[root@akuilinux01 ~]# systemctl start keepalived
[root@akuilinux01 ~]# ps aux |grep keepa
root 2895 0.0 0.0 118608 1388 ? Ss 23:20 0:00 /usr/sbin/keepalived -D
root 2896 0.1 0.1 127468 3304 ? S 23:20 0:00 /usr/sbin/keepalived -D
root 2899 0.3 0.1 127408 2836 ? S 23:20 0:00 /usr/sbin/keepalived -D
root 2961 0.0 0.0 112676 980 pts/1 S+ 23:20 0:00 grep --color=auto keepa
[root@akuilinux01 ~]# ps aux |grep nginx
root 1016 0.0 0.0 46008 1260 ? Ss 20:52 0:00 nginx: master process /usr/localnginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 1017 0.0 0.2 48496 4152 ? S 20:52 0:00 nginx: worker process
nobody 1018 0.0 0.2 48496 3896 ? S 20:52 0:00 nginx: worker process
root 2982 0.0 0.0 112680 980 pts/1 S+ 23:20 0:00 grep --color=auto nginx
[root@akuilinux01 ~]# /etc/init.d/nginx stop
Stopping nginx (via systemctl): [ 确定 ]
[root@akuilinux01 ~]# ps aux |grep nginx
root 3266 1.0 0.0 46008 1252 ? Ss 23:22 0:00 nginx: master process /usr/localnginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 3267 0.0 0.2 48496 3892 ? S 23:22 0:00 nginx: worker process
nobody 3268 0.0 0.2 48496 3892 ? S 23:22 0:00 nginx: worker process
root 3273 0.0 0.0 112676 984 pts/1 S+ 23:22 0:00 grep --color=auto nginx
[root@akuilinux01 ~]# less /var/log/messages
[root@akuilinux01 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:87:fb:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.21.128/24 brd 192.168.21.255 scope global ens33
valid_lft forever preferred_lft forever
inet 192.168.21.100/32 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::68fd:e6fa:c781:f5a6/64 scope link
valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:87:fb:91 brd ff:ff:ff:ff:ff:ff
inet 192.168.110.136/24 brd 192.168.110.255 scope global dynamic ens37
valid_lft 1278sec preferred_lft 1278sec
inet6 fe80::c559:4a92:72f1:b448/64 scope link
valid_lft forever preferred_lft forever
132上编辑配置文件
[root@akuilinux02 ~]# > /etc/keepalived/keepalived.conf
[root@akuilinux02 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
notification_email {
aming@aminglinux.com
}
notification_email_from root@aminglinux.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/usr/local/sbin/check_ng.sh"
interval 3
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass aminglinux>com
}
virtual_ipaddress {
192.168.21.100
}
track_script {
chk_nginx
}
}
[root@akuilinux02 ~]# vim /usr/local/sbin/check_ng.sh
#时间变量,用于记录日志
d=`date --date today +%Y%m%d_%H:%M:%S`
#计算nginx进程数量
n=`ps -C nginx --no-heading|wc -l`
#如果进程为0,则启动nginx,并且再次检测nginx进程数量,
#如果还为0,说明nginx无法启动,此时需要关闭keepalived
if [ $n -eq "0" ]; then
systemctl start nginx
n2=`ps -C nginx --no-heading|wc -l`
if [ $n2 -eq "0" ]; then
echo "$d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
[root@akuilinux02 ~]# chmod 755 /usr/local/sbin/check_ng.sh
[root@akuilinux02 ~]# systemctl start keepalived
[root@akuilinux01 ~]# curl localhost@192.168.21.128
master,master.
[root@akuilinux01 ~]# curl localhost@192.168.21.129
backup,backup.
[root@akuilinux01 ~]# curl localhost@192.168.21.100
master,master.
[root@akuilinux01 ~]# systemctl stop keepalived
[root@akuilinux01 ~]# curl localhost@192.168.21.100
backup,backup.
[root@akuilinux01 ~]# systemctl start keepalived
[root@akuilinux01 ~]# curl localhost@192.168.21.100
master,master.
集群介绍,keepalived介绍,用keepalived配置高可用集群
标签:业务 serve ip add http 测试 var proxy 邮件发送 tail
原文地址:http://blog.51cto.com/akui2521/2135810