mysql+keepalived的安装配置方法
本篇内容主要讲解“MySQL+keepalived的安装配置方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“mysql+keepalived的安装配置方法”吧!
创新互联2013年开创至今,先为宜良等服务建站,宜良等地企业,进行企业商务咨询服务。为宜良企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
注意:keepalived在每一台的服务器上都需要安装
环境介绍:
master_mysql: 10.20.20.51
slave_mysql : 10.20.20.61
virtual_ip : 10.20.20.201
注意:关闭防火墙、selinux
一、安装keepalived
下载地址:
1、 http://www.keepalived.org/software/keepalived-1.1.20.tar.gz
3、安装C编译器
yum install popt-devel openssl-devel popt-devel
yum install gcc gcc-c++ autoconf automake
4、编译安装
[root@node1 ~]# tar zxvf keepalived-1.2.13.tar.gz
[root@node1 keepalived-1.2.13]# cd keepalived-1.2.13
[root@node1 keepalived-1.2.13]# ./configure --prefix=/usr/local/keepalived --disable-fwmark
[root@node1 keepalived-1.2.13]# make
[root@node1 keepalived-1.2.13]# make install
[root@node1 keepalived-1.2.13]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@node1 keepalived-1.2.13]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@node1 keepalived-1.2.13]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@node1 keepalived-1.2.13]# cd /etc/init.d/
[root@node1 init.d]# chkconfig --add keepalived
[root@node1 init.d]# chkconfig keepalived on
[root@node1 init.d]# mkdir -p /etc/keepalived
5、配置keepalived文件
1)主库的keepalived配置文件
vim /etc/keepalived/keepalived.conf
global_defs {
router_id Hadb_1
}
vrrp_sync_group VGM {
group {
VI_HA
}
}
vrrp_script chk_mysql {
script "
interval 1
}
# vvrp_instance define #
vrrp_instance VI_HA {
state MASTER
interface eth0
virtual_router_id 54
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass hamysql
}
virtual_ipaddress {
10.20.20.201
}
track_script {
chk_mysql
}
}
2)从库的keepalived的配置文件
vim /etc/keepalived/keepalived.conf
global_defs {
router_id Hadb_1
}
vrrp_sync_group VGM {
group {
VI_HA
}
}
vrrp_script chk_mysql {
script "
interval 1
}
# vvrp_instance define #
vrrp_instance VI_HA {
state BACKUP
interface eth0
virtual_router_id 54
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass hamysql
}
virtual_ipaddress {
10.20.20.201
}
track_script {
chk_mysql
}
}
6、启动keepalived服务
service keepalived start
二、配置mysql的AB复制(互相的AB复制)
1、1.主库配置(master服务器)
#vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin //[必须]启用二进制日志
server-id=51 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
2.修改从服务器slave:
#vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin //[必须]启用二进制日志
server-id=61 //[必须]服务器唯一ID,默认是1,一般取IP最后一段
3、重启两台服务器的mysql
/etc/init.d/mysql restart
4、在主服务器上建立帐户并授权slave:
10.20.20.51:
mysql>GRANT REPLICATION SLAVE ON *.* to 'repler'@'%' identified by '123.com';
10.20.20.61:
mysql>GRANT REPLICATION SLAVE ON *.* to 'repler'@'%' identified by '123.com';
5、登录主服务器的mysql,查询master的状态
mysql>show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 | 308 | | |
+------------------+----------+--------------+------------------+
6、配置从服务器Slave:
10.20.20.61:
mysql>change master to master_host='10.20.20.51',master_user='repler',master_password='123.com',
master_log_file='mysql-bin.000004',master_log_pos=308;
10.20.20.51:
mysql>change master to master_host='10.20.20.61',master_user='repler',master_password='123.com',
master_log_file='mysql-bin.000004',master_log_pos=308;
7、启动从服务器复制功能
mysql>start slave;
8、检查从服务器复制功能状态:
mysql> show slave status\G
到此,相信大家对“mysql+keepalived的安装配置方法”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
本文名称:mysql+keepalived的安装配置方法
文章出自:http://ybzwz.com/article/jphdhj.html