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. 构建基于Javascript的移动CMS——加入滑动

    在和几个有兴趣做移动CMS的小伙伴讨论了一番之后,我们认为当前比較重要的便是统一一下RESTful API.然而近期持续断网中,又遭遇了一次停电,暂停了对API的思考.在周末无聊的时光了看了<人 ...

  2. JavaScript定时调用函数(SetInterval与setTimeout)

    setTimeout和setInterval的语法同样.它们都有两个參数.一个是将要运行的代码字符串.另一个是以毫秒为单位的时间间隔,当过了那个时间段之后就将运行那段代码. 只是这两个函数还是有差别的 ...

  3. JavaFX 一 出生新手村(阅读小规则)

    我就不讲IDE怎么装的,网上有的是,我仅仅是说说我学习过程中遇到的,该注意的东西 1.JavaFX刚開始出是基于脚本script开发的语言,所以网上会有流传比較多关于script的JavaFX,对于被 ...

  4. 利用日志文件恢复MYSQL数据库

    利用日志文件恢复MYSQL数据库 650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic ...

  5. C#使用一般处理程序(ashx)中session

    .ashx中引用 session必须 using System.Web.SessionState ,继承IReadOnlySessionState/IRequiresSessionState IRea ...

  6. 转 SQL集合函数中利用case when then 技巧

    SQL集合函数中利用case when then 技巧 我们都知道SQL中适用case when then来转化数据库中的信息 比如  select (case sex when 0 then '男' ...

  7. Self-Taught Learning

    the promise of self-taught learning and unsupervised feature learning is that if we can get our algo ...

  8. Oracle定义变量、常量

    1 定义变量 declare var_countryname varchar2(50):='中国'; 2 定义常量 con_day constant integer:=365;

  9. [React] Use a Render Porp

    More detail check LInk. Render Prop vs HOC: HOC version for withMouse: import React from 'react' imp ...

  10. JavaWeb学习笔记:Tomcat

    Tomcat 开源的 Servlet 容器. 部署并启动 tomcat server. 解压 apache-tomcat-6.0.16.zip 到一个非中文文件夹下. 配置一个环境变量. java_h ...