当前位置: 首页 > news >正文

Keepalived+http高可用实战

环境准备:

两台安装了keepalived的服务器

ip:192.168.134.170;192.168.134.172

1、安装http服务

yum install httpd -y

2、写一个测试页面

[root@localhost ~]# echo "`hostname -I`,web1 test page. " > /var/www/html/inde
[root@localhost ~]# systemctl start httpd

3、修改keepalived配置文件(/etc/keepalived/keepalived.conf)

主节点
! Configuration File for keepalivedglobal_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVEL1
}vrrp_instance VI_1 {state MASTER# nopreemptinterface ens33virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.134.100}
}
备节点:修改优先级和state即可

4、结果

但是此时如果出现了web服务器故障,没有办法进行自动切换。

5、写检查脚本

#!/bin/bashwhile true
dohttp_pid_num=`ps -C httpd --no-header | wc -l`if [ $http_pid_num -eq 0 ]thensystemctl start httpdsleep 2http_pid_num=`ps -C httpd --no-header | wc -l`if [ $http_pid_num -eq 0 ]thensystemctl stop keepalivedfifi
done

6、添加运行(放到后台)==>执行完此步骤后重新启动,再次测试,便可以进行故障切换。

nohup ./check_httpd.sh > nohup.out 2>&1 &
http://www.lryc.cn/news/124682.html

相关文章:

  • Linux文件系统管理
  • MyBatis-Plugin源码全面分析
  • Vscode 常用操作教程
  • Linux设备树详解
  • .netcore grpc服务端流方法详解
  • python爬虫数据解析xpath、jsonpath,bs4
  • go语言的database/sql结合squirrel工具sql生成器完成数据库操作
  • LVS集群和分布式
  • 使用QT可视化设计对话框详细步骤与代码
  • TFTP Server
  • 登录验证码实现
  • 2. 获取自己CSDN文章列表并按质量分由小到大排序(文章质量分、博客质量分、博文质量分)(阿里云API认证)
  • 在Windows和MacOS环境下实现批量doc转docx,xls转xlsx
  • 【网络编程(二)】NIO快速入门
  • 【Vue-Router】嵌套路由
  • MySQL索引总结
  • 谷粒商城第十二天-基本属性销售属性管理功能的实现
  • 利用安全区域的概念解决移动端兼容不同手机刘海的问题
  • 数据结构---图
  • 励志长篇小说《周兴和》书连载之十八 内外交困搞发明
  • web基础入门和php语言基础入门 二
  • typeScript 之 Array
  • 【题解】二叉树的前中后遍历
  • 文件操作/IO
  • 基于Java+SpringBoot+vue前后端分离共享汽车管理系统设计实现
  • Mac RN环境搭建
  • log4j教程_编程入门自学教程_菜鸟教程-免费教程分享
  • DP——背包问题
  • 【从零学习python 】29. 「函数参数详解」——了解Python函数参数的不同用法
  • 10个经典战略分析模型,助力洞察市场明确优势