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)
8、排错
keepalived ip address associated with VRID not present in received packet
 
参考:
  http://blog.csdn.net/gzh0222/article/details/7962954

Keepalived + Mysql 双主的更多相关文章

  1. MySQL 高可用性—keepalived+mysql双主

    MySQL 高可用性—keepalived+mysql双主(有详细步骤和全部配置项解释) - 我的博客 - CSDN博客https://blog.csdn.net/qq_36276335/articl ...

  2. MySQL 高可用性—keepalived+mysql双主(有详细步骤和全部配置项解释)

    博主QQ:819594300 博客地址:http://zpf666.blog.51cto.com/ 有什么疑问的朋友可以联系博主,博主会帮你们解答,谢谢支持! 前言:生产环境中一台mysql主机存在单 ...

  3. keepalived+MySQL双主搭建

    keepalived+MySQL双主搭建过程 首先要简单了解一下keepalived: Keepalived是Linux下一个轻量级别的高可用解决方案.高可用(High Avalilability,H ...

  4. Keepalived+MySQL双主

    一.Keepalived+MySQL Replication的应用场景 MySQL的高可用方案有cluster,MMM,MHA等,这些高可用方案都要三台服务器以上,成本有点高,今天介绍一个低成本高可用 ...

  5. keepalived+mysql双主复制高可用方案

    MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了 ...

  6. keepalived+mysql双主热备

    这里使用keepalived实现mysql的双主热备高可用 实验环境: 主机名 IP 系统版本 软件版本 master 192.168.199.6/vip:192.168.199.111 Rhel7. ...

  7. 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 ...

  8. Mysql + keepalived 实现双主热备读写分离【转】

    Mysql + keepalived 实现双主热备读写分离 2013年6月16日frankwong发表评论阅读评论   架构图 系统:CentOS6.4_X86_64软件版本:Mysql-5.6.12 ...

  9. mysql双主+keepalived

    环境 OS: centos7Mysql 版本: mysql 5.7Keepalived: keepalived-1.2.20Mysql-vip:192.168.41.100Mysql-master1: ...

随机推荐

  1. GCJ1C09C - Bribe the Prisoners

    GCJ1C09C - Bribe the Prisoners Problem In a kingdom there are prison cells (numbered 1 to P) built t ...

  2. class-dump 和 iOSOpenDev 的使用

    class-dump 官网地址:这里 我这里下载的是 class-dump-3.5.dmg 版本号的. 双击.dmg 文件,将  拉倒 /usr / local / bin 文件夹下,这样就能够在终端 ...

  3. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  4. Dubbo springcloud

    简而言之,Dubbo确实类似于Spring Cloud的一个子集,Dubbo功能和文档完善,在国内有很多的成熟用户,然而鉴于Dubbo的社区现状(曾经长期停止维护,2017年7月31日团队又宣布重点维 ...

  5. java(运算符,控制流程语句,函数 )

    运算符 数据类型转换: 小数据类型-------->大数据类型(自动类型转换) 大数据类型--------->小数据类型(强制类型转换) 强制类型转换的格式: 小数据类型  变量名 = ( ...

  6. 微信小程序从零开始开发步骤(一)搭建开发环境

    从零到有写一个小程序系列专题,很早以前就想写来分享,但由于项目一直在进展,没有过多的时间研究技术,现在可以继续分享了. 1:注册 用没有注册过微信公众平台的邮箱注册一个微信公众号, 申请帐号 ,网址: ...

  7. 【Henu ACM Round #12 A】 Grandma Laura and Apples

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 知道题意之后就是一个模拟的过程了. 用int now记录当前苹果的个数.bool flag记录是否有小数(即半个苹果) (这样处理为 ...

  8. 各种join一目了然: join 、inner join、left join 、right join、full join

    各种join一幅图一目了然 一下每幅图都是指: A * join B on A.id = B.in 这个帖子也非常形象.比較好:http://www.phpddt.com/db/inner_join- ...

  9. 用for和while循环求e的值[e=1+1/1!+1/2!+1/3!+1/4!+1/5!+...+1/n!]

    /*编敲代码,依据下面公式求e的值. 要求用两种方法计算: 1)for循环.计算前50项 2)while循环,直至最后一项的值小于10-4 e=1+1/1!+1/2!+1/3!+1/4!+1/5!+. ...

  10. 如果笔记本的 WIN7 运行很卡,请尝试运行这些批处理

    如果笔记本的 WIN7 运行很卡,请尝试运行这些批处理 WIN7是不是很卡?关掉下列服务吧 @echo off rem AppXSvc 为部署应用商店应用程序提供基础结构支持 rem BITS 微软的 ...