mysql启用keepalive_keepalive+mysql 主主配置
1. 环境说明:
机器名
eth0
说明
server01
192.168.100.30/24
Mysql、keepalive
server02
192.168.100.31/24
Mysql、keepalive
2. 安装mysql
去官网下载mysql5.5的安装包,源码安装比较麻烦所以忽略
MySQL-client-5.5.29-1.el6.x86_64.rpm MySQL-server-5.5.29-1.el6.x86_64.rpm MySQL-devel-5.5.29-2.el6.x86_64.rpm
出现错误提示:
[root@server01 ~]# rpm -ivhMySQL-server-5.5.29-1.el6.x86_64.rpm
Preparing... ########################################### [100%]
file /usr/share/mysql/charsets/Index.xml from install ofMySQL-server-5.5.29-1.el6.x86_64 conflicts with file from packagemysql-libs-5.1.61-4.el6.x86_64
这个是因为安装了5.1的工具包的问题卸载加参数-nodeps不检查依赖
[root@server01 ~]# rpm -e --nodepsmysql-libs
[root@server01 ~]# rpm -ivh MySQL-server-5.5.29-1.el6.x86_64.rpm
[root@server01 ~]# rpm -ivh MySQL-client-5.5.29-1.el6.x86_64.rpm
3. 配置mysql
查看mysql安装路径
[root@server01 mysql]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql/usr/share/mysql /usr/share/man/man1/mysql.1.gz
创建配置文件夹可以直接放在/etc目录下
[root@server01mysql]# cp my-medium.cnf /etc/
[root@server01 mysql]# mv my-medium.cnfmy.cnf
[root@server01 mysql]# chown mysql:mysql /etc/my.conf
配置my.cnf
master.cnf:
[mysqld]
server-id=1
log-bin=server01.log
relay-log-index=slave-relay-bin.index #配置双主模式所以服务器都要配置从的relay-log
relay-log=slave-relay-bin
innodb_flush_log_at_trx_commit=1
sync_binlog=1
注意:为了使用事务的InnoDB在复制中最大的持久性和一致性,你应该指定innodb_flush_log_at_trx_commit=1,sync_binlog=1 选项。
需要在从机的slave.cnf文件的【mysqld】部分增加server-id选项。server-id的值类似主机,必须是 1到2 的32次方之间的一个正整数,而且必须和主机的ID不一样。如果你设置多台从机,那么每台必须有别于主机和其他从机的唯一的server-id值。可以把server-id值认为是类似IP地址的东西:这些ID在复制服务器通信的时候标识了每台唯一的服务器实例。
slave.cnf:
[mysqld]
server-id=2
log-bin=server02-bin.log
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
innodb_flush_log_at_trx_commit=1
sync_binlog=1
设置mysql自启动
[root@server01 mysql]# chkconfig mysql on
[root@server01 etc]# service mysql start
[root@server01 ~]# mysqladmin -urootpassword password
4. 创建复制账户
[root@server01 ~]# mysql –uroot
mysql> create userrepl_user@192.168.100.31;
mysql> grant replication slave on *.* torepl_user@192.168.100.31 identified by 'password';
锁住主机,禁止用户写入mysql
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
不改变mysql用户,复制test测试同步库
mysqldump -urrot -password test >test.sql
从机启动会解锁
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec
拷贝test.sql到从机
从机执行
mysql -uroot -ppassword test < test.sql
回到主机查看当前日志偏差值
mysql> show master status;
+---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB|
+---------------------+----------+--------------+------------------+
| server01-bin.000003 | 4921 | | |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
在从机上初始化复制了。在从机上执行以下命令
mysql> slave stop;
Query OK, 0 rows affected, 1 warning (0.00sec)
mysql> change master toMASTER_HOST='192.168.100.30',
-> MASTER_USER='repl_user',
-> MASTER_PASSWORD='password',
-> MASTER_LOG_FILE='server01-bin.000003',
-> MASTER_LOG_POS= 2877;
Query OK, 0 rows affected (0.03 sec)
mysql> slave start;
Query OK, 0 rows affected (0.00 sec)
查看状态
mysql> show slave status\G
*************************** 1. row***************************
Slave_IO_State: Waiting formaster to send event
Master_Host: 192.168.100.30
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File:server01-bin.000003
Read_Master_Log_Pos: 4921
Relay_Log_File:slave-relay-bin.000002
Relay_Log_Pos: 256
Relay_Master_Log_File: server01-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 4921
Relay_Log_Space: 412
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
5. 验证从机复制特性
主机数据库内容如下:
mysql> use test
Database changed
mysql> select * from new
-> ;
+----+------+------+
| id | col1 | col2 |
+----+------+------+
| 1| hah | test |
| 2| s | b |
+----+------+------+
2 rows in set (0.00 sec)
从机数据库内容:
Database changed
mysql> select * from new;
+----+------+------+
| id | col1 | col2 |
+----+------+------+
| 1| hah | test |
| 2| s | b |
+----+------+------+
2 rows in set (0.02 sec)
回到主机修改数据:
mysql> update new setcol1='haha',col2='change' where id='1';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from new
-> ;
+----+------+--------+
| id | col1 | col2 |
+----+------+--------+
| 1| haha | change |
| 2| s | b |
+----+------+--------+
2 rows in set (0.00 sec)
查看从机是否修改:
mysql> select * from new;
+----+------+--------+
| id | col1 | col2 |
+----+------+--------+
| 1| haha | change |
| 2| s | b |
+----+------+--------+
2 rows in set (0.00 sec)
观察得出从机已经从主机同步到了数据。
6. 主主模式配置
现在的设置为192.168.100.30为主机,192.168.100.31为从机,
按照上述设置再将192.168.100.31设为主机,192.168.100.30设为从机。
设置完成后两台机器既相互为主机也相互为备机,都可以写入数据并同步到对方机器。
7. 安装keepalived(两台均安装)
安装依赖包
[root@server01 ~]# yum install -y gcc gcc+gcc-c++ openssl openssl-devel popt-devel
下载
[root@server01 ~]# wgethttp://www.keepalived.org/software/keepalived-1.2.7.tar.gz
[root@server01 ~]# tar -xzf keepalived-1.2.7.tar.gz
[root@server01 ~]#./configure --prefix=/usr/local/keeplived
[root@server01 ~]# make
[root@server01 ~]# make install
[root@server01 ~]# cp/usr/local/keeplived/sbin/keepalived /usr/bin/
[root@server01 ~]# cp /usr/local/keeplived/etc/sysconfig/keepalived /etc/sysconfig/
[root@server01 ~]# cp/usr/local/keeplived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@server01 ~]# mkdir /etc/keepalived
创建 vi keepalived.conf如下内容
! Configuration File for keepalived
global_defs {
notification_email {
cmwu@biencloud.com
}
notification_email_from haha@biencloud.com
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 50
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.40
}
}
192.168.100.31上的配置文件为
global_defs {
notification_email {
cmwu@biencloud.com
}
notification_email_from haha@biencloud.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 50
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.40
}
}
[root@server01 ~]# ping 192.168.100.40
PING 192.168.100.40 (192.168.100.40) 56(84)bytes of data.
64 bytes from 192.168.100.40: icmp_seq=1ttl=64 time=0.262 ms
[root@server02 ~]# ping 192.168.100.40
PING 192.168.100.40 (192.168.100.40) 56(84)bytes of data.
64 bytes from 192.168.100.40: icmp_seq=1ttl=64 time=0.064 ms
两台服务器均可以ping通服务器。
Ip addr可以看到虚拟IP已经绑定到网卡上了
mysql启用keepalive_keepalive+mysql 主主配置相关推荐
- Mysql数据库主从及主主复制配置演示
From : http://www.cnblogs.com/tae44/p/4682810.html 实验系统:CentOS 6.6_x86_64 实验前提:提前准备好编译环境,防火墙和selinux ...
- mysql主主备份_MySQL主从备份和主主备份配置+Keepalived+MySQL读写分离
一.MySQL主从备份 为保证数据库的安全和效率,可以使用主从备份,当有写的操作可以在主服务器上操作,操作完之后备份到从服务器上,当有读操作时可以访问从服务器,这样在一定程度上保证了数据库的安全,当主 ...
- MySql主主(主从)同步配置详解
一.MySQL复制概述 MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.MySQL复制基于主服务器在二进制日志中跟踪所有对数据库的更改(更新.删除等 ...
- mysql备份-a是什么_MySQL主从备份和主主备份配置+Keepalived+MySQL读写分离
一.MYSQL主从备份 为保证数据库的安全和效率,可以使用主从备份,当有写的操作可以在主服务器上操作,操作完之后备份到从服务器上,当有读操作时可以访问从服务器,这样在一定程度上保证了数据库的安全,当主 ...
- MySQL数据库的主主同步配置
一.架构方案思路 1.两台mysql都可读写,互为主备.本文的实验中:默认只使用一台(DCGH-DB1)负责数据的写入,另一台(DCGH-DB2)备用. 2.DCGH-DB1是DCGH-DB2的主库, ...
- mysql数据库主主模式配置
主主复制 互为主从:问题 1.数据不一致,因此慎用. 2.自动增长ID: 配置一个节点使用奇数id auto_increment_offset=1 auto_increment_increment=2 ...
- MySQL主从(MySQL proxy Lua读写分离设置,一主多从同步配置,分库分表方案)
Mysql Proxy Lua读写分离设置 一.读写分离说明 读写分离(Read/Write Splitting),基本的原理是让主数据库处理事务性增.改.删操作(INSERT.UPDATE.DELE ...
- mysql数据库-主主配置
环境: 主机A( huangzp2):172.16.115.157 主机B( huangzp3):172.16.115.100 说明:双向的主从配置,互为主从:两台服务器均可以给用户访问(具备冗余功能 ...
- Mysql主主复制架构配置
MySQL主主复制结构区别于主从复制结构.在主主复制结构中,两台服务器的任 何一台上面的数据库存发生了改变都会同步到另一台服务器上,这样两台服务器 互为主从,并且都能向外提供服务. 这就比使用主从复制 ...
最新文章
- 2个YUV视频拼接技术
- 巨头纷纷看上的中国Robobus又获1亿美元投资
- 表达对别人的感激之情
- 对SetViewportOrg和SetWindowOrg的理解
- win10 git bash 闪退
- subprogram or cursor is declared in a package specification and must be defined in the package body
- librosa能量_librosa与python_speech_features
- java滑动窗体动画_java – 为布局滑入和滑出动画
- 使用AWS DMS 升级Postgre 10到12
- 6个部件组成一个圆球_怎样找一个好月嫂?这6个问题一问便知!
- 流程图的虚线是什么意思_这些新标识啥意思?交警教你怎么走
- 整理的部分Java和C#不同点
- 知其然不知其所以然!
- ASO优化技巧:利用好App下载周期变化,aso优化技巧介绍
- vscode 报Open a folder or workspace... (File -> Open Folder)解决办法
- cookie用法--抽屉网的自动登录(cookie是通过代码自动获取的)
- 光剑评注:其实,说了这么多废话,无非就是: 一切皆是映射。不管是嵌套 XML,还是 Lisp 嵌套括号,还是 XXX 的 Map 数据结构,一切都是树形结构——映射。...
- Mimikatz获取系统密码攻防研究
- 数据库SQL实战 --47.将所有获取奖金的员工当前的薪水增加10%
- 【Go】Go Ubuntu 安装 gvm:Go 版本管理工具
热门文章
- 使用 Pytorch 实现 skip-gram 的 word2vec
- Debug常用指令和DOSBox使用步骤
- LeetCode简单题之最长的美好子字符串
- MindSpore张量mindspore::tensor
- 用NVIDIA A100 GPUs提高计算机视觉
- 地面标识检测与识别算法
- 2个RecyclerView 联动
- Binary XML file line #8: Error inflating class android.support.v7.widget.RecyclerView
- 吴恩达Drive.ai因经营困难“卖身”苹果
- 2022-2028年中国微机电系统(MEMS)行业投资分析及前景预测报告