Linux下MySQL+Keepalived高可用性配置

前言*在mysql高可用配置中,我们会看到有很多的方法,每种方法都有各自优缺点,那今天我们来看参看一下Mysql+Keepalived高可用配置。

一、安装环境:

系统版本:CentOS6.0 x86_64

Mysql版本:mysql-5.1.61

Mysqlserver_1: 192.9.117.140

Mysqlserver_2: 192.9.117.141

Keepalived-VIP:192.9.117.142

二、正式安装:

在两台服务器上分别安装mysql,这里直接采用yum安装,如下:

  1. yum install –y mysql mysql-devel mysql-server mysql-libs

安装完后,配置MySQL配置文件,mysql采用主主模式:

1) 192.9.117.140的配置文件如下:vi /etc/my.cnf

  1. [mysqld]
  2. datadir=/data/mysql
  3. socket=/var/lib/mysql/mysql.sock
  4. user=mysql
  5. # Disabling symbolic-links is recommended to prevent assorted security risks
  6. symbolic-links=0
  7. log-bin=mysql-bin
  8. server-id = 1
  9. auto_increment_offset=1
  10. auto_increment_increment=2
  11. [mysqld_safe]
  12. log-error=/var/log/mysqld.log
  13. pid-file=/var/run/mysqld/mysqld.pid
  14. master-host =192.9.117.141
  15. master-user=tongbu
  16. master-pass=123456
  17. master-port =3306
  18. master-connect-retry=60
  19. replicate-do-db =map

2) 192.9.117.141的配置文件如下:vi /etc/my.cnf

    1. [mysqld]
    2. datadir=/data/mysql
    3. socket=/var/lib/mysql/mysql.sock
    4. user=mysql
    5. # Disabling symbolic-links is recommended to prevent assorted security risks
    6. symbolic-links=0
    7. log-bin=mysql-bin
    8. server-id = 2
  • auto_increment_offset=2
  • auto_increment_increment=2
  1. [mysqld_safe]
  2. log-error=/var/log/mysqld.log
  3. pid-file=/var/run/mysqld/mysqld.pid
  4. master-host =192.9.117.140
  5. master-user=tongbu
  6. master-pass=123456
  7. master-port =3306
  8. master-connect-retry=60
  9. replicate-do-db =map
  10. 如上设置bin-log文件,并都设置对方为自己的主服务器,配置同步的数据库为map

相关推荐