负载均衡
KEEPALIVED安装与使用
keepalived配置说明
keepalived检测方式
keepalived LVS配置
LVS
LVS-NAT集群的搭建
LVS-DR集群的搭建
KEEPALIVED+LVS
HAproxy
HAProxy配置说明
HAproxy算法
HAProxy管理页
HAProxy保持
HAProxyACL规则
NGINX
NGINX负载均衡
NGINX负载示例二
负载转发路径问题
缓冲缓存参数详解
限制代理ip方法
负载参数详解
nginx_upstream_check_module
正向代理(HTTP)
本文档使用MrDoc发布
返回首页
-
+
KEEPALIVED安装与使用
2020年2月14日 16:43
admin
#官网 https://www.keepalived.org/download.html #安装 ###源码安装 #安装依赖 yum -y install openssl openssl-devel #下载安装 wget https://www.keepalived.org/software/keepalived-2.2.4.tar.gz tar -zxvf keepalived-2.2.4.tar.gz mv keepalived-2.2.4 /usr/local/keepalived cd /usr/local/keepalived ./configure --sysconf=/etc make make install ###yum安装 yum -y install keepalived --- ###启动与停止 systemctl start keepalived.service systemctl status keepalived.service ###修改主配置 vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { wja84281865@163.com wutianhao@163.com #当服务器出现故障进行主从切换时会发邮件给这列表中的人 } notification_email_from root@localhost #邮件发送者 smtp_server 192.168.31.88 #邮件服务器IP地址 smtp_connect_timeout 30 #连接超时时间 router_id MySQL1 #设备标识 vrrp_skip_check_adv_addr vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_script check_nginx { #监控脚本 script "/etc/keepalived/nginx_check.sh" interval 2 } vrrp_instance VI_1 { state BACKUP #角色 interface ens33 #绑定网卡 virtual_router_id 60 #主从此配置一定要相同 priority 100 #优先级,越高为主 advert_int 1 nopreempt #非抢占模式 authentication { auth_type PASS auth_pass 1qaz@WSX } track_script { check_nginx #监控脚本 } virtual_ipaddress { 192.168.31.240 #浮动IP } } ####主脚本 vim /etc/keepalived/nginx_check.sh #!/bin/bash Ng=`ps -C nginx --no-header | wc -l` if [ $Ng -eq 0 ];then NG_STATUS=1 else NG_STATUS=0 fi exit $NG_STATUS ###修改从配置 vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { wja84281865@163.com wutianhao@163.com #当服务器出现故障进行主从切换时会发邮件给这列表中的人 } notification_email_from root@localhost #邮件发送者 smtp_server 192.168.31.88 #邮件服务器IP地址 smtp_connect_timeout 30 #连接超时时间 router_id MySQL2 #设备标识 vrrp_skip_check_adv_addr vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_script check_nginx { #监控脚本 script "/etc/keepalived/nginx_check.sh" interval 2 } vrrp_instance VI_1 { state BACKUP #角色 interface ens33 #绑定网卡 virtual_router_id 60 #主从此配置一定要相同 priority 90 #优先级,越高为主 advert_int 1 nopreempt #非抢占模式 authentication { auth_type PASS auth_pass 1qaz@WSX } track_script { check_nginx #监控脚本 } virtual_ipaddress { 192.168.31.240 #浮动IP } } ####从脚本 vim /etc/keepalived/mysql_down.sh #!/bin/bash Ng=`ps -C nginx --no-header | wc -l` if [ $Ng -eq 0 ];then NG_STATUS=1 else NG_STATUS=0 fi exit $NG_STATUS ###keepalived配置,解决vip无法ping通,虚拟服务器端口无法访问的问题 keepalived.conf中vip配置好后,通过ip addr可以看到vip已经顺利挂载,但是无法ping通,并且防火墙都已关闭,**原因是keepalived.conf配置中默认vrrp_strict打开了,需要把它注释掉。重启keepalived即可ping通。** --- ###keepalived防火墙配置 ####Keepalived使用vrrp组播,默认地址是224.0.0.18,因此要配置防火墙放过。 iptables -I INPUT -i eth0 -d 224.0.0.0/8 -p vrrp -j ACCEPT iptables -I OUTPUT -o eth0 -d 224.0.0.0/8 -p vrrp -j ACCEPT ---
分享到: