共计 3182 个字符,预计需要花费 8 分钟才能阅读完成。
本篇内容主要讲解“mysql+keepalived 的安装配置方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“mysql+keepalived 的安装配置方法”吧!
注意: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 的安装配置方法”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!