mysql+keepalived的安装配置方法

发布时间:2021-08-18 09:42:10 作者:chen
来源:亿速云 阅读:212

本篇内容主要讲解“mysql+keepalived的安装配置方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“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的安装配置方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. MySQL高可用架构:mysql+keepalived实现
  2. mysql+keepalived高可用业务配置教程

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

keepalived mysql

上一篇:Java注释、关键字和标识符知识点整理

下一篇:mybatis查询语句之封装数据的示例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》