keeplived + mysql双主复制部署 --原创
环境:
master 1: | 192.168.100.10 | oracle linux 7.4 | mysql 5.7.1 |
master 2: | 192.168.100.11 | oracle linux 7.4 | mysql 5.7.1 |
keepalived VIP | 192.168.100.12 |
配置本地yum仓库
vim /etc/yum.repo.d/public-yum-ol7.repo [yum_repo]
name=yum_repo
baseurl=file:///share/repo
gpgcheck=
enabled=
安装mysql
检查是否已经安装
rpm -qa | grep mysql
1.mysql安装包安装顺序 安装包有依赖关系必须按照顺序安装
1. mysql-community-common-5.7.21-1.el7.x86_64.rpm
2. mysql-community-libs-5.7.21-1.el7.x86_64.rpm
3. mysql-community-client-5.7.21-1.el7.x86_64.rpm
4. mysql-community-server-5.7.21-1.el7.x86_64.rpm
2.初始化mysql 在初始化完成后会生成一个过期的root密码,登录mysql后需要立刻更改,否则无法使用任何命令
rpm -qa | grep mysql
3.启动mysql
systemctl start mysqld
4.查看mysql root密码
cat /var/log/mysqld.log | grep password
5.mysql安全设置 (可选项,可以重置root密码)
mysql_secure_installation
6.登录mysql
mysql -u root -p
7.修改root密码
alter user 'root'@'%' identified by 'Len#qwer';
8.设置root账户永不过期 (可选项)
alter user 'root'@'%' password expire never;
配置双主
修改mysql配置文件c
master1节点
vim /etc/my.cnf [mysqld]
log-bin=mysql-bin #开启二进制日志
server-id= #设置server-id 主备库必须不同
log_slave_updates=
master2节点
vim /etc/my.cnf [mysqld]
log-bin=mysql-bin #开启二进制日志
server-id=2 #设置server-id 主备库必须不同
log_slave_updates=
2.重启mysql,
master1节点
systemctl restart mysqld
master2节点
systemctl restart mysqld
创建同步用户
master1节点
CREATE USER 'repl'@'192.168.100.11' IDENTIFIED BY 'Phjj#qwer';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.100.11';
master2节点
CREATE USER 'repl'@'192.168.100.10' IDENTIFIED BY 'Phjj#qwer';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.100.10';
查看两个节点的binlog文件名称和post位置,用于配置复制
master1节点
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin. | 619 | | | |
+------------------+----------+--------------+------------------+-------------------+
row in set (0.00 sec)
master2节点
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 1175 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
master1节点
start slave;
master2节点
start slave;
配置复制
master1节点
CHANGE MASTER TO
MASTER_HOST='192.168.100.11',
MASTER_USER='repl',
MASTER_PASSWORD='Phjj#qwer',
MASTER_LOG_FILE='mysql-bin.000002',
MASTER_LOG_POS=;
master2节点
CHANGE MASTER TO
MASTER_HOST='192.168.100.10',
MASTER_USER='repl',
MASTER_PASSWORD='Phjj#qwer',
MASTER_LOG_FILE='mysql-bin.000004',
MASTER_LOG_POS=;
master1启动复制
start slave;
master2启动复制
start slave;
查看复制状态 Slave_IO_Running,Slave_SQL_Running 状态必须为running才为正常
mysql> show slave status\G; Slave_IO_Running: Yes
Slave_SQL_Running: Yes
安装Keepalived
yum install -y keepalived
配置keepalived
master1节点
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
# vrrp_strict
vrrp_garp_interval
vrrp_gna_interval
} vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.100.12/
}
}
virtual_server 192.168.100.12 3306 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 192.168.100.10 3306 {
weight 3
notify_down /etc/keepalived/kill_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
master2节点
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
# vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
} vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.12/24
}
}
virtual_server 192.168.100.12 3306 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 192.168.100.11 3306 {
weight 3
notify_down /etc/keepalived/kill_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
配置关闭keepalived脚本
vim /etc/keepalived/kill_keepalived.sh
#!/bin/bash
pkill keepalived
添加执行权限给 关闭keepalived脚本
chmod +x /etc/keepalived/kill_keepalived.sh
查看keepalived VIP地址
ip addr
UUID相同导致mysql无法进行复制
故障现象
vim /var/log/mysqld.log
--12T02::.499315Z [Note] Slave SQL thread for channel '' initialized, starting replication in log 'mysql-bin.000001' at position , relay log './ajiamysql1-relay-bin.000001' position:
--12T02::.499839Z [Note] Slave I/O thread for channel '': connected to master 'repl@192.168.100.11:3306',replication started in log 'mysql-bin.000001' at position
--12T02::.501900Z [ERROR] Slave I/O for channel '': Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work. Error_code:
故障原因:直接复制已经安装好mysql的虚拟机导致mysql UUID相同无法进行复制连接 注意:UUID和server_id一样不能相同
故障解决: 修改mysql UUID
[root@ajiamysql1 mysql]# vim /var/lib/mysql/auto.cnf
[auto]
server-uuid=6fe77f0a-eae1-11e7-805e-005056b309100
keeplived + mysql双主复制部署 --原创的更多相关文章
- 分布式数据存储 - MySQL双主复制
上篇文章<分布式数据存储 - MySQL主从复制>,我们说到MySQL主从复制很好的保障了从库,读的高可用性.so,问题来了: 1.针对主库,写的高可用性又是如何做到高可用性? 2.如果需 ...
- keepalived+mysql双主复制高可用方案
MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了 ...
- MySQL双主复制
原文发表于cu:2017-06-12 本文简单介绍MySQL双主复制原理及1个简单是双主复制验证. 一.MySQL双主复制原理 1. 双主复制原理 master-master复制的两台服务器,既是ma ...
- linux环境下配置mysql双主复制
简单来说,双主复制就是让两台mysql服务器中的数据保持同步,可以用来实现灾备和负载均衡 主机1 IP:192.168.200.128 主机2 IP:192.168.200.131 两台主机系统均为c ...
- mysql双主复制总结
双主复制: 1).在两台服务器上各自建立一个具有复制权限的用户: 2).修改配置文件: # 主服务器A上 [mysqld] server-id = 10 log-bin = mysql-bin rel ...
- mysql 双主复制 centos7
mysql 安装请看:http://www.cnblogs.com/leohe/p/6839705.html 双主复制设置 1. 两台虚拟机,都是 centos7 主: 10.1.1.115 从: 1 ...
- 利用LVS+Keepalived搭建Mysql双主复制高可用负载均衡环境
应用背景: MySQL复制(主主,主从...)能在保证数据的备份的同时也能够做读写分离分摊系统压力,但是发生单点故障时,需要手动 切换到另外一台主机.LVS和Keppalived可以设定一个VIP来实 ...
- 003.Heartbeat MySQL双主复制
一 基础环境 节点 系统版本 MySQL版本 业务IP 心跳IP Master01 CentOS 7.5 MySQL 5.6 192.168.88.100 192.168.77.100 Master0 ...
- Heartbeat MySQL双主复制
目录 一 基础环境 二 实际部署 2.1 安装MySQL 2.2 初始化MySQL 2.3 master01 my.cf配置 2.4 创建账号 2.5 master02 my.cf配置配置 2.6 创 ...
随机推荐
- TensorFlow基础笔记(8) TensorFlow简单人脸识别
数据材料 这是一个小型的人脸数据库,一共有40个人,每个人有10张照片作为样本数据.这些图片都是黑白照片,意味着这些图片都只有灰度0-255,没有rgb三通道.于是我们需要对这张大图片切分成一个个的小 ...
- ResultSet是结果集对象
ResultSet是结果集对象 DriverManager管理一组驱动程序 PreparedStatement预编译的,用来发送和执行SQL语句的
- SQL还可以这么玩儿
对于数据库的增删改查,我们都再熟悉不过了,今天,将和您一起探讨几种不一样的SQL用法,原来,SQL还可以这么玩儿. 以下是数据库的原表,如图-1. 1.快速复制表结构 这时,如果我们需要复制一份一模一 ...
- adb server is out of date.killing的解决办法
当把手机连接到电脑端口运行adb程序调试时,出现了下面这样的情况: 分析:出错的原因是adb的端口被其他程序的进程占领了,所以要做的就是找到并kill该进程. 工具/原料 cmd.exe. ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 【转】Native Thread for Win32 B-Threads Synchronization(通俗易懂,非常好)
http://www.bogotobogo.com/cplusplus/multithreading_win32B.php Synchronization Between Threads In t ...
- STL容器:list双向链表学习
list是一个双向列表容器,完成了标准C++数据结构中链表的所有功能; list与vector和deque类似,只不过其中的对象提供了对元素的随机访问. STL以双向链表的方式实现list,访问需要从 ...
- nyoj1237 最大岛屿(河南省第八届acm程序设计大赛)
题目1237 pid=1237" style="color:rgb(55,119,188)">题目信息 执行结果 本题排行 讨论区 最大岛屿 时间限制:1000 m ...
- 快学scala习题解答--第五章 类
5 类 5.1 改进5.1节的Counter类,让它不要在Int.MaxValue时变成负数 class Count{ private var value = Int.MaxValue else v ...
- subprocess.Popen() 常用方法
p.stdout.read() :用于读取标准输出,会一次性读取所有内容,返回一个字符串p.stdout.readline() :用于读取标准输出,一次只读取一行内容,返回一个字符串p.stdout. ...