REDHAT6.2 X86_64下安装基于keepalive的msyql主主复制
2013-04-17 09:59
477 查看
一 初始化配置[/b]
本配置共有两个测试节点,分别是node1.ewt.cc和node2.ewt.cc,相对应的IP地址分别为
1)192.168.2.71和192.168.2.72
集群服务为mysql服务
集群VIP:192.168.2.200
设置两个节点上的/etc/hosts文件均为下面的内容
192.168.2.71 node1.ewt.cc node1
192.168.2.72 node2.ewt.cc node2
2)为了方便两个主机的文件对拷,配置双机互信访问,设定两个节点可以基于密钥进行ssh通信,这可以通过如下的命令实现:
在node1上
# ssh-keygen -t rsa #一直输入空格
# ssh-copy-id -i /root/.ssh/id_rsa.pub node2
在node2上
# ssh-keygen -t rsa #一直输入空格
#ssh-copy-id -i /root/.ssh/id_rsa.pub node1
3)为了测试方便,通过如下命令在两个节点都关闭iptables
service iptables stop
使它开机也不自启动:chkconfig –level 2345 iptables off
4)本地yum源配置
[root@node2 yum.repos.d]# cat /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///iso
enable=1
gpgcheck=0
5) 安装mysql
yum –y install mysql mysql-bench mysql-bench mysql-server mysql-test libtool-ltdl perl-DBD-MySQL perl-DBI
二 主从单向复制配置
*先把node1配置成node2的主
(一)node1上面配置
1 /etc/my.cmf文件如下,在默认的文件里面增加如下参数:
log-bin=mysql.bin
server-id=1
relay-log=relay.bin
sync-binlog=1
auto_increment_offet=1
auto_increment_increment=2
2 mysql命令行下面:
mysql>grant replication client,replication slave on *.* to 'node2'@'192.168.2.72' identified by 'node2';
mysql> flush privileges;
3 mysql> show master status;
+--------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------+----------+--------------+------------------+
| mysql.00005| 106 | | |
+--------------+----------+--------------+------------------+
1 row in set (0.00 sec)
(二)node2上面配置
1 /etc/my.cmf文件如下,在默认的文件里面增加如下参数:
log-bin=mysql.bin
server-id=2
relay-log=relay.bin
sync-binlog=1
auto_increment_offet=2 #用来设定数据库中自动增长的起点的
auto_increment_increment=2 #用来设定数据库中自动增长的步长
2 mysql> change master to master_host='192.168.2.71',master_user='node2', master_password='node2',master_log_file='mysql.000005',master_log_pos=106,master_port=3306;
mysql> slave start;
(三)主从复制验证略
三主主双向复制配置
(一) Node2上面配置
1 mysql>grant replication client,replication slave on *.* to 'node1'@'192.168.2.71' identified by 'node1';
2 mysql> flush privileges;
3 mysql> show master status;
+--------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------+----------+--------------+------------------+
| mysql.000004 | 517 | | |
+--------------+----------+--------------+------------------+
(二) Node1上面配置
1 mysql> change master to master_host='192.168.2.72', master_user='node1', master_password='node1', master_log_file='mysql.000004', master_log_pos=517, master_port=3306;
2 mysql> slave start;
(三) 主主双向复制验证略
四 安装keepalive
(一) 下载 wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
(二)解压 tar zxvf keepalived-1.2.7.tar.gz
(三) 检查编译环境和配置makefile
./configure --sysconfdir=/etc --prefix=/usr/local/keepalive --with-kernel-dir=/usr/src/kernels/2.6.32-220.el6.x86_64/
出现报错:
configure: error: Popt libraries is required
用yum install popt-devel –y解决之
(四)编译&安装
make &&mak insall
(五)修改配置文件如下
1 在node1上面 vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
524813834@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id mysql-ha
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.200
}
}
virtual_server 192.168.2.200 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
# nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.2.71 3306 {
weight 1
notify_down /usr/local/mysql/bin/mysqltest.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
2 编写检测服务down后所要执行的脚本
mkdir –p /usr/local/mysql/bin
cd /usr/local/mysql/bin
vi mysqltest.sh
#!/bin/bash
pkill keepalived
保存退出
最后chmod +x mysqtest.sh
3 简单测试
找一台局域网PC,然后去ping MySQL的VIP,这时候MySQL的VIP是可以ping得通的
停止MySQL服务,看keepalived健康检查程序是否会触发我们编写的脚本,正确的话,keepalived进程被杀死,PING过程会中断。
4在node1上面 vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
524813834@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id mysql-ha
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 90
advert_int 1
# nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.200
}
}
virtual_server 192.168.2.200 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.2.72 3306 {
weight 1
notify_down /usr/local/mysql/bin/mysqltest.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
5编写检测服务down后所要执行的脚本
mkdir –p /usr/local/mysql/bin
cd /usr/local/mysql/bin
vi mysqltest.sh
#!/bin/bash
pkill keepalived
保存退出
最后chmod +x mysqtest.sh
四最终测试
MySQL远程登录测试
我们找一台安装有MySQL客户端的windows,然后登录VIP,看是否能登录,在登录前两台MySQL服务器都要授权允许从远程登录
MySQL> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MySQL> flush privileges;
Query OK, 0 rows affected (0.00 sec)
使用客户端登录VIP测试
C:\MySQL\bin>MySQL.exe -uroot -p123456 -h192.168.2.200
MySQL>
● keepalived故障转移测试
※在windows客户端一直去ping VIP,然后关闭192.168.2.71上的keepalived,正常情况下VIP就会切换到192.168.2.72上面去
※开启192.168.2.71上的keepalived,关闭192.168.2.72上的keepalived,看是否能自动切换,正常情况下VIP又会属于192.168.2.71
注:keepalived切换速度还是非常块的,整个切换过程只需1-3秒
● MySQL故障转移测试
※在192.168.2.71上关闭MySQL服务,看VIP是否会切换到192.168.2.72上
※开启192.168.2.71上的MySQL和keepalived,然后关闭192.168.2.72上的MySQL,看VIP是否会切换到192.168.2.71上
本配置共有两个测试节点,分别是node1.ewt.cc和node2.ewt.cc,相对应的IP地址分别为
1)192.168.2.71和192.168.2.72
集群服务为mysql服务
集群VIP:192.168.2.200
设置两个节点上的/etc/hosts文件均为下面的内容
192.168.2.71 node1.ewt.cc node1
192.168.2.72 node2.ewt.cc node2
2)为了方便两个主机的文件对拷,配置双机互信访问,设定两个节点可以基于密钥进行ssh通信,这可以通过如下的命令实现:
在node1上
# ssh-keygen -t rsa #一直输入空格
# ssh-copy-id -i /root/.ssh/id_rsa.pub node2
在node2上
# ssh-keygen -t rsa #一直输入空格
#ssh-copy-id -i /root/.ssh/id_rsa.pub node1
3)为了测试方便,通过如下命令在两个节点都关闭iptables
service iptables stop
使它开机也不自启动:chkconfig –level 2345 iptables off
4)本地yum源配置
[root@node2 yum.repos.d]# cat /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///iso
enable=1
gpgcheck=0
5) 安装mysql
yum –y install mysql mysql-bench mysql-bench mysql-server mysql-test libtool-ltdl perl-DBD-MySQL perl-DBI
二 主从单向复制配置
*先把node1配置成node2的主
(一)node1上面配置
1 /etc/my.cmf文件如下,在默认的文件里面增加如下参数:
log-bin=mysql.bin
server-id=1
relay-log=relay.bin
sync-binlog=1
auto_increment_offet=1
auto_increment_increment=2
2 mysql命令行下面:
mysql>grant replication client,replication slave on *.* to 'node2'@'192.168.2.72' identified by 'node2';
mysql> flush privileges;
3 mysql> show master status;
+--------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------+----------+--------------+------------------+
| mysql.00005| 106 | | |
+--------------+----------+--------------+------------------+
1 row in set (0.00 sec)
(二)node2上面配置
1 /etc/my.cmf文件如下,在默认的文件里面增加如下参数:
log-bin=mysql.bin
server-id=2
relay-log=relay.bin
sync-binlog=1
auto_increment_offet=2 #用来设定数据库中自动增长的起点的
auto_increment_increment=2 #用来设定数据库中自动增长的步长
2 mysql> change master to master_host='192.168.2.71',master_user='node2', master_password='node2',master_log_file='mysql.000005',master_log_pos=106,master_port=3306;
mysql> slave start;
(三)主从复制验证略
三主主双向复制配置
(一) Node2上面配置
1 mysql>grant replication client,replication slave on *.* to 'node1'@'192.168.2.71' identified by 'node1';
2 mysql> flush privileges;
3 mysql> show master status;
+--------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------+----------+--------------+------------------+
| mysql.000004 | 517 | | |
+--------------+----------+--------------+------------------+
(二) Node1上面配置
1 mysql> change master to master_host='192.168.2.72', master_user='node1', master_password='node1', master_log_file='mysql.000004', master_log_pos=517, master_port=3306;
2 mysql> slave start;
(三) 主主双向复制验证略
四 安装keepalive
(一) 下载 wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
(二)解压 tar zxvf keepalived-1.2.7.tar.gz
(三) 检查编译环境和配置makefile
./configure --sysconfdir=/etc --prefix=/usr/local/keepalive --with-kernel-dir=/usr/src/kernels/2.6.32-220.el6.x86_64/
出现报错:
configure: error: Popt libraries is required
用yum install popt-devel –y解决之
(四)编译&安装
make &&mak insall
(五)修改配置文件如下
1 在node1上面 vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
524813834@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id mysql-ha
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.200
}
}
virtual_server 192.168.2.200 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
# nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.2.71 3306 {
weight 1
notify_down /usr/local/mysql/bin/mysqltest.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
2 编写检测服务down后所要执行的脚本
mkdir –p /usr/local/mysql/bin
cd /usr/local/mysql/bin
vi mysqltest.sh
#!/bin/bash
pkill keepalived
保存退出
最后chmod +x mysqtest.sh
3 简单测试
找一台局域网PC,然后去ping MySQL的VIP,这时候MySQL的VIP是可以ping得通的
停止MySQL服务,看keepalived健康检查程序是否会触发我们编写的脚本,正确的话,keepalived进程被杀死,PING过程会中断。
4在node1上面 vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
524813834@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id mysql-ha
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 90
advert_int 1
# nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.200
}
}
virtual_server 192.168.2.200 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.2.72 3306 {
weight 1
notify_down /usr/local/mysql/bin/mysqltest.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
5编写检测服务down后所要执行的脚本
mkdir –p /usr/local/mysql/bin
cd /usr/local/mysql/bin
vi mysqltest.sh
#!/bin/bash
pkill keepalived
保存退出
最后chmod +x mysqtest.sh
四最终测试
MySQL远程登录测试
我们找一台安装有MySQL客户端的windows,然后登录VIP,看是否能登录,在登录前两台MySQL服务器都要授权允许从远程登录
MySQL> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MySQL> flush privileges;
Query OK, 0 rows affected (0.00 sec)
使用客户端登录VIP测试
C:\MySQL\bin>MySQL.exe -uroot -p123456 -h192.168.2.200
MySQL>
● keepalived故障转移测试
※在windows客户端一直去ping VIP,然后关闭192.168.2.71上的keepalived,正常情况下VIP就会切换到192.168.2.72上面去
※开启192.168.2.71上的keepalived,关闭192.168.2.72上的keepalived,看是否能自动切换,正常情况下VIP又会属于192.168.2.71
注:keepalived切换速度还是非常块的,整个切换过程只需1-3秒
● MySQL故障转移测试
※在192.168.2.71上关闭MySQL服务,看VIP是否会切换到192.168.2.72上
※开启192.168.2.71上的MySQL和keepalived,然后关闭192.168.2.72上的MySQL,看VIP是否会切换到192.168.2.71上
相关文章推荐
- Oracle学习笔记安装篇之在Redhat Enterprise Linux 6.3 x86_64下安装Oracle11g R2
- Centos 6.2_X86_64 编译安装postfix+amavisd-new+clamav
- Oracle学习笔记安装篇之在Redhat Enterprise Linux 6.3 x86_64下安装Oracle11g R2
- Oracle BIEE 10g在RedHat 5.4 x86_64下的安装
- redhat server 6.2 x86_64使用中国科技大的centos源
- RedHat 5.6_x86_64 + ASM + RAW+ Oracle 10g RAC (八) 添加节点—安装clusterware
- RedHat 5.6_x86_64 + ASM + RAW+ Oracle 10g RAC (九) 添加节点—安装数据库软件
- Oracle学习笔记安装篇之在Redhat Enterprise Linux 6.3 x86_64下安装Oracle11g R2
- 四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装)
- [原]Redhat-el5_x86_64下Xen安装、配置、使用及出现的问题和解决方法
- RHEL 6.2 x86_64 下安装Oracle 11g步骤
- redhat6.2 x86_64 heartbeat的yum源
- Redhat Enterprise Linux 6.3 x86_64 安装oracle 11g R2
- PF_RING 6.0.2在Redhat 6.3 x86_64上编译和安装
- PF_RING 6.0.2在Redhat 6.3 x86_64上编译和安装
- Oracle10g(10.2) 在Redhat AS4u2 x86_64 上安装
- Oracle学习笔记安装篇之在Redhat Enterprise Linux 7.0 x86_64下安装Oracle12cR1数据库
- Redhat Enterprise Linux 6.3 x86_64下安装Oracle11g R2
- redhat enterprise 6.3 x86_64 上安装VirtualBox详细教程
- Oracle学习笔记安装篇之在Redhat Enterprise Linux 7.0 x86_64下安装Oracle11g R2