Keepalived + Mysql 双主
VIP 192.168.1.41
Master 192.168.1.42
Slave 192.168.1.43 、配置
yum -y install mysql-server
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start 登录
mysql -u root Master
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=
#开启binlog日志功能
log-bin=mysql-bin
#会打印mysql的所以sql语句
log=/var/log/mysql.log
#两台MySQL的server-ID不能一样,默认情况下两台MySQL的serverID都是1,需将其中一台修改为2即可
server-id=
#需要同步的库名称
binlog-do-db=mysql
auto-increment-increment=
auto-increment-offset= [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid scp /etc/my.cnf 192.168.1.43:/etc/my.cnf Slave
vim /etc/my.cnf
#修改Server-id
server-id= 、建授权用户
在Master上新建授权用户
grant replication slave on *.* to 'user01'@'192.168.1.%' identified by '';
在Slave服务器上建授权用户
grant replication slave on *.* to 'user01'@'192.168.1.%' identified by ''; 、将Master设为Slave的主服务器
在192.168.1.43上将192.168.1.42设为自己的主服务器 在Master 上执行查询数据库日志号状态
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin. | | mysql | |
+------------------+----------+--------------+------------------+
row in set (0.00 sec) 在Slave 执行
MySQL> change master to master_host='192.168.1.42',master_user='user01',master_password='',master_log_file='mysql-bin.000003',master_log_pos=;
Query OK, rows affected (0.05 sec)
MySQL> start slave;
Query OK, rows affected (0.00 sec)
mysql> show slave status \G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes \\如果此2项都为yes,master-master配置即成功 、将Slave设为Master的主服务器
在192.168.1.42上将192.168.1.43设为自己的主服务器 在Slave 上执行查询数据库日志号状态
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin. | | mysql | |
+------------------+----------+--------------+------------------+
row in set (0.00 sec) 在Master 执行
MySQL> change master to master_host='192.168.1.43',master_user='user01',master_password='',master_log_file='mysql-bin.000003',master_log_pos=;
Query OK, rows affected (0.05 sec)
MySQL> start slave;
Query OK, rows affected (0.00 sec)
mysql> show slave status \G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes \\如果此2项都为yes,master-master配置即成功 、测试
如上述均正确配置,现在在任何一台MySQL上更新数据都会同步到另一台MySQL(仅限mysql库)
select user from mysql.user;
create user 'test'@'192.168.1.%' identified by 'www'; 、keepalived 部署并配置
在Master 上配置
yum install -y gcc openssl-devel popt-devel
tar zxvf keepalived-1.2..tar.gz
cd keepalived-1.2.
./configure --prefix=/usr/local/keepalived
make && make install cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived/
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
chmod +x /etc/init.d/keepalived vim /etc/keepalived/keepalived.conf =============================================
! Configuration File for keepalived global_defs {
notification_email {
story_media@.com
}
notification_email_from root@LDR.local
smtp_server 127.0.0.1
smtp_connect_timeout
router_id MYSQL-HA
} vrrp_instance VI_1 {
#两台配置此处均是BACKUP
state BACKUP
#注意网卡名称
interface eth0
#多套keepalived 在同一个局域网内该ID不能重复
virtual_router_id
#优先级,另一台改为90
priority
advert_int
#不主动抢占资源,只在优先级高的机器上设置即可,优先级低的机器不设置
nopreempt
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.1.41
}
} virtual_server 192.168.1.41 {
#每个2秒检查一次real_server状态
delay_loop
#LVS算法
lb_algo wrr
lb_kind DR
#会话保持时间
persistence_timeout
protocol TCP real_server 192.168.1.42 {
weight
#检测到服务down后执行的脚本
notify_down /etc/init.d/my.sh
TCP_CHECK {
#连接超时时间
connect_timeout
#重连次数
nb_get_retry
#重连间隔时间
delay_before_retry
#健康检查端口
connect_port
}
}
}
================================================
编写检测服务down后所要执行的脚本
注:此脚本是上面配置文件notify_down选项所用到的,keepalived使用notify_down选项来检查real_server的服务状态,当发现real_server服务故障时,便触发此脚本;
vim /etc/init.d/my.sh
#!/bin/sh pkill keepalived chmod +x /etc/init.d/my.sh service keepalived start ps aux | grep keepalived
此处测试如果关闭mysql服务keepalived 会通过/etc/ini.d/my.sh 将keepalived 进程杀死,VIP自动被另外一台服务器接管 在Slave 上配置
yum install -y gcc openssl-devel popt-devel
tar zxvf keepalived-1.2..tar.gz
cd keepalived-1.2.
./configure --prefix=/usr/local/keepalived
make && make install cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
chmod +x /etc/init.d/keepalived 在Master 上执行如下命令拷贝配置文件
scp /etc/keepalived/keepalived.conf 192.168.1.43:/etc/keepalived/keepalived.conf
scp /etc/init.d/my.sh 192.168.1.43:/etc/init.d/my.sh 编辑配置文件
vim /etc/keepalived/keepalived.conf
==========================================
! Configuration File for keepalived global_defs {
notification_email {
story_media@.com
}
notification_email_from root@LDR.local
smtp_server 127.0.0.1
smtp_connect_timeout
router_id MYSQL-HA
} vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id
#优先级修改为90
priority
advert_int
nopreempt
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.1.41
}
} virtual_server 192.168.1.41 {
delay_loop
lb_algo wrr
lb_kind DR
persistence_timeout
protocol TCP #本机真实IP
real_server 192.168.1.43 {
weight
notify_down /etc/init.d/my.sh
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
}
}
}
========================================= 、测试
两台MySQL服务器都要授权允许从远程登录
MySQL> grant all privileges on *.* to www@'%' identified by '';
Query OK, rowsaffected (0.00 sec)
MySQL> flush privileges;
Query OK, rowsaffected (0.00 sec)
Keepalived + Mysql 双主的更多相关文章
- MySQL 高可用性—keepalived+mysql双主
MySQL 高可用性—keepalived+mysql双主(有详细步骤和全部配置项解释) - 我的博客 - CSDN博客https://blog.csdn.net/qq_36276335/articl ...
- MySQL 高可用性—keepalived+mysql双主(有详细步骤和全部配置项解释)
博主QQ:819594300 博客地址:http://zpf666.blog.51cto.com/ 有什么疑问的朋友可以联系博主,博主会帮你们解答,谢谢支持! 前言:生产环境中一台mysql主机存在单 ...
- keepalived+MySQL双主搭建
keepalived+MySQL双主搭建过程 首先要简单了解一下keepalived: Keepalived是Linux下一个轻量级别的高可用解决方案.高可用(High Avalilability,H ...
- Keepalived+MySQL双主
一.Keepalived+MySQL Replication的应用场景 MySQL的高可用方案有cluster,MMM,MHA等,这些高可用方案都要三台服务器以上,成本有点高,今天介绍一个低成本高可用 ...
- keepalived+mysql双主复制高可用方案
MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了 ...
- keepalived+mysql双主热备
这里使用keepalived实现mysql的双主热备高可用 实验环境: 主机名 IP 系统版本 软件版本 master 192.168.199.6/vip:192.168.199.111 Rhel7. ...
- Keepalived+MySQL双主架构
l 架构准备 Node1 192.168.15.3 Node2 192.168.15.4 VIP 192.168.15.254 l 软件 MySQL 5.6 Keepalive yum insta ...
- Mysql + keepalived 实现双主热备读写分离【转】
Mysql + keepalived 实现双主热备读写分离 2013年6月16日frankwong发表评论阅读评论 架构图 系统:CentOS6.4_X86_64软件版本:Mysql-5.6.12 ...
- mysql双主+keepalived
环境 OS: centos7Mysql 版本: mysql 5.7Keepalived: keepalived-1.2.20Mysql-vip:192.168.41.100Mysql-master1: ...
随机推荐
- 【Henu ACM Round#16 D】Bear and Two Paths
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先搞一条a到b的路径 a c x3 x4 x5....xn-2 d b 然后第二个人的路径可以这样 c a x3 x4 x5...x ...
- Springboot分布式限流实践
高并发访问时,缓存.限流.降级往往是系统的利剑,在互联网蓬勃发展的时期,经常会面临因用户暴涨导致的请求不可用的情况,甚至引发连锁反映导致整个系统崩溃.这个时候常见的解决方案之一就是限流了,当请求达到一 ...
- 【Oracle】使用bbed恢复delete的数据
表中的数据被delete之后并不会真正删除数据,而是打了一个删除标记,仅仅要还没有被覆盖就能够恢复回来. 实验步骤例如以下: SYS@ORCL>create table bbed_test(x ...
- es6 ----- export 和 import
ES6 模块不是对象,而是通过export命令显式指定输出的代码,再通过import命令输入. 下面列出几种import和export的基本语法: 第一种方式: 在lib.js文件中, 使用 expo ...
- GridView1.DataKeys[e.RowIndex].Value 是什么含义?
https://zhidao.baidu.com/question/88518619.html举个例子来说吧 你将一个student表绑定到grid上 这个表里有一些字段 包括id 姓名 学号 等等等 ...
- c# winform 技术提升
http://www.cnblogs.com/junjie94wan/category/303961.html http://www.cnblogs.com/springyangwc/archive/ ...
- hdoj-1870-愚人节的礼物(栈)
愚人节的礼物 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Hirens Boot DVD 15.2 功能恢复版 v1.1 -- 制作U盘启动盘
Hirens Boot DVD 15.2 功能恢复版 v1.1 这个版本比 Hirens Boot DVD 15.2 功能要多,在正式版本中缺少的商业工具这个版本都包含了,所以这个应用程序被称为恢复版 ...
- RingtoneManager-获得系统当前的铃声
我们直接看代码 bt1 = (Button) findViewById(R.id.bt1); bt2 = (Button) findViewById(R.id.bt2); bt3 = (Button) ...
- TextView- 内容过长省略号设定
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_conte ...