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 




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30345407/viewspace-2088053/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30345407/viewspace-2088053/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值