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

mysql keepalived6_MySQL+Keepalived实现主主高可用方案

Mysql主主高可用方案

master配置

[root@master ~]# yum -y install keepalived

[root@master ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

router_id LVS_MASTER-A

}

vrry_script mysql {

script "/opt/mysql.sh"

interval 2

weight -5

fall 2

rise 1

}

vrrp_instance VI_1 {

stateMASTER

interfaceens33

virtual_router_id 51

priority100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

track_script {

mysql

}

virtual_ipaddress {

192.168.200.210

}

}

}

[root@master ~]# vim /opt/mysql.sh

#!/bin/bash

counter=$(netstat -na |grep "LISTEN" |grep "3306" |wc -l)

if [ "${counter}" -eq 0 ]

then

systemctl stop keepalived

fi

~

[root@master ~]# chmod +x /opt/mysql.sh

[root@master ~]# systemctl start keepalived

2: ens33: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

inet 192.168.30.25/24 brd 192.168.30.255 scope global noprefixroute ens33

inet 192.168.200.210/32 scope global ens33

[root@master ~]# tail -f /var/log/messages

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 0.centos.pool.ntp.org

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 1.centos.pool.ntp.org

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 2.centos.pool.ntp.org

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 3.centos.pool.ntp.org

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:40:01 master systemd: Started Session 40 of user root.

Apr  9 15:40:01 master systemd: Starting Session 40 of user root.

第二台master2从

[root@master1 ~]# yum -y install keepalived

[root@master1 ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

router_id LVS_MASTER-B

}

vrry_script mysql {

script "/opt/mysql.sh"

interval 2

weight -5

fall 2

rise 1

}

vrrp_instance VI_1 {

stateBACKUP

interfaceens33

virtual_router_id 51

priority 90

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

track_script {

mysql

}

virtual_ipaddress {

192.168.200.210

}

}

}

测试VIP转移

[root@master1 ~]# vim /opt/mysql.sh

#!/bin/bash

counter=$(netstat -na |grep "LISTEN"|grep "3306" |wc -l)

if [ "${counter}" -eq 0 ]

then

systemctl stop keepalived

fi

[root@master1 ~]# chmod +x /opt/mysql.sh

[root@master1 ~]# systemctl start keepalived

[root@master1 ~]# tail -f /var/log/messages

[root@master ~]# systemctl stop mariadb

[root@master ~]# ip a |grep ens33

[root@localhost ~]# ip a |grep ens33

2: ens33: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

inet 192.168.30.25/24 brd 192.168.30.255 scope global noprefixroute ens33

2,在远程客户端 测试

Mysql 服务器授权

[root@localhost ~]# mysql -uroot

MariaDB [(none)]> grant all on *.* to 'root'@'192.168.30.%'identified by '123456';

MariaDB [(none)]> flush privileges;

通过vip 登陆测试

[root@localhost ~]# mysql -uroot -p123456 -h 192.168.30.210;

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sampdb             |

| test               |

| test01             |

| test02             |

+--------------------+

相关文章:

  • python install package_python install package作为另一个包的子包
  • 易语言 excel_易语言初级教程-将图片转化为excel像素画
  • PHP启动mysql时出现路径_MySQL数据库改路径后没办法启动的问题
  • es6 三点运算符_ES6-- 扩展运算符与剩余操作符...
  • mysql teaching_php同步mysql两个数据库中表的数据
  • windows 命令行远程连接_Linux下远程连接Windows桌面
  • 数据库逻辑设计mysql_数据库设计(一)分析及逻辑设计
  • 叠瓦盘为什么不推荐_叠瓦盘还是固态盘还是垂直盘?
  • mysql优化器RBO_RBO基于规则的优化器access paths优先级
  • python类函数里面创建线程_详解python中的线程
  • java取拼音首字母_java怎么根据汉字获取字的拼音首字母
  • reactor java_Java reactor响应式编程
  • awstats mysql_将awstats分析日志结果导入mysql
  • java 什么是swing_Java-Swing是什么?
  • java中的for循环例子_Java中使用增强for循环的实例方法
  • SegmentFault for Android 3.0 发布
  • 0x05 Python数据分析,Anaconda八斩刀
  • Angularjs之国际化
  • download使用浅析
  • JavaScript-Array类型
  • javascript数组去重/查找/插入/删除
  • mac修复ab及siege安装
  • node入门
  • Spring声明式事务管理之一:五大属性分析
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • 创建一个Struts2项目maven 方式
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 前端技术周刊 2018-12-10:前端自动化测试
  • 一个项目push到多个远程Git仓库
  • 06-01 点餐小程序前台界面搭建
  • 昨天1024程序员节,我故意写了个死循环~
  • ​比特币大跌的 2 个原因
  • # 数据结构
  • (6)添加vue-cookie
  • (八)五种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (附源码)python房屋租赁管理系统 毕业设计 745613
  • (四)TensorRT | 基于 GPU 端的 Python 推理
  • (原创) cocos2dx使用Curl连接网络(客户端)
  • (原創) 博客園正式支援VHDL語法著色功能 (SOC) (VHDL)
  • (转)linux下的时间函数使用
  • (转)ObjectiveC 深浅拷贝学习
  • (转)Oracle存储过程编写经验和优化措施
  • (转)大型网站架构演变和知识体系
  • ***通过什么方式***网吧
  • .NET C#版本和.NET版本以及VS版本的对应关系
  • .net core 6 使用注解自动注入实例,无需构造注入 autowrite4net
  • .NET Core 版本不支持的问题
  • .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
  • /使用匿名内部类来复写Handler当中的handlerMessage()方法
  • ?php echo ?,?php echo Hello world!;?
  • @Query中countQuery的介绍
  • [ C++ ] STL_vector -- 迭代器失效问题
  • []常用AT命令解释()
  • [AI]文心一言出圈的同时,NLP处理下的ChatGPT-4.5最新资讯
  • [Android Pro] Notification的使用