博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
keepalived 实现web应用的高可用
阅读量:7053 次
发布时间:2019-06-28

本文共 3042 字,大约阅读时间需要 10 分钟。

项目需求:公司需要我做privacyIDEA认证服务器的高可用,我的思路是在两台服务器上搭两套应用程序,后端存储公用一个mysql数据库,没有mysql数据库可以主备的形式,然后再做一下数据库的异地备份。基本思路就是这样的。

我主要介绍一下使用keepalived实现高可用。

本次实现使用两台机器master:10.236.44.62 ,slave:10.236.45.91

一、安装需要的软件(master和slave都操作)

yum install keepalived -y

yum install -y httpd

二、配置 master机器的 /etc/keepalived/keepalived.conf 

! Configuration File forkeepalived  global_defs {                                               #全局定义段   notification_email {     acassen@firewall.loc     failover@firewall.loc     sysadmin@firewall.loc   }   notification_email_fromAlexandre.Cassen@firewall.loc   smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id LVS_DEVEL}vrrp_script check_running {	script "/usr/local/bin/check_running"	interval 3	weight 10}  vrrp_instance VI_1 {                                 #实例名称    state MASTER                                     #当前节点为主节点    interface eno16777736                            #指定网卡    virtual_router_id 132                            #虚拟路由ID,默认为51    priority 100                                     #优先级,主节点要数字要大于从节点    advert_int 1    authentication {        auth_type PASS        auth_pass 111111    }    virtual_ipaddress {                               #虚拟IP地址       10.236.44.77    }   track_script {	check_running weight 20   }}

三、配置 slave机器的 /etc/keepalived/keepalived.conf

! Configuration File forkeepalived  global_defs {                                          #全局定义段   notification_email {     acassen@firewall.loc     failover@firewall.loc     sysadmin@firewall.loc   }   notification_email_fromAlexandre.Cassen@firewall.loc   smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id LVS_DEVEL}vrrp_script check_running {        script "/usr/local/bin/check_running"        interval 1        weight 10}  vrrp_instance VI_1 {                                 #实例名称    state BACKUP                                     #当前节点为主节点    interface eno16777736                            #指定网卡    virtual_router_id 132                            #虚拟路由ID,默认为51    priority 99                                      #优先级,主节点要数字要大于从节点    advert_int 1    authentication {        auth_type PASS        auth_pass 111111    }    virtual_ipaddress {                               #虚拟IP地址        10.236.44.77    }    track_script {       check_running weight 20   }}

四、编辑脚本文件:/usr/local/bin/check_running (master和slave都一样)

#!/bin/bashsystemctl status httpd |grep runningif [ $? -ne 0 ]then     systemctl restart httpd.service    sleep 1    systemctl status httpd |grep running    if [ $? -ne 0 ]    then          systemctl stop keepalived.service    fifi

给文件可执行权限 chmod +x /usr/local/bin/check_running 

五、把httpd和keeplaived都启起来。(主和从上都操作)

systemctl  restart httpd.service 

systemctl  restart keepalived.service

六、测试

编辑/var/www/html/index.html  

master机器文件内容:master 机器  slave机器文件内容:slave 机器

①:访问vip:10.236.44.77

②:把master的http停掉,然后再访问vip:10.236.44.77

systemctl  stop httpd 

这是因为我的脚本里会做判断,如果httpd停了,就把它启起来。

③:随便修改一下httpd的配置文件,让它不能正常启动,这个时候我们再把它停掉

systemctl  stop httpd.service

这个时候先看下主的ip show

再看下从的ip show

这个时候访问一下vip:10.236.44.77

转载地址:http://lasol.baihongyu.com/

你可能感兴趣的文章
在java中如何在非servlet的普通类中获取request、response、session
查看>>
Linux Rsync
查看>>
Redis实现消息队列
查看>>
2k8 32bit下载
查看>>
密码需要带特殊字符
查看>>
个人收集的java精品网站
查看>>
卫生间排风设计规范
查看>>
eclipse.ini
查看>>
sql查询表结构,过程,视图,主键,外键,约束
查看>>
范式图形辨析
查看>>
Android WebView坑摘要
查看>>
Win 10 UWP开发系列:设置AppBarButton的图标
查看>>
Windows Cmder
查看>>
阿里云服务器常见用语
查看>>
ibatis中的$和#的区别
查看>>
Emmet插件详解
查看>>
数据结构 树的创建(线索化二叉树)
查看>>
036 关于网站的UV分析
查看>>
zabbix监控网络的出入口流量
查看>>
webstorm 破解方式
查看>>