Keepalive+LVS+MySQL的高可用的双机解决方案
对比这个方案,共享存储对于解决mysql的高可用的数据同步,无疑要优异的多,对于随着对keepalived了解的渐渐入门,无意间发现了mysql数据同步的解决方案,十分的感兴趣,自然而然本方案的技术重点在于mysql的数据同步,废话不说了,开始做实验。
实验原理:两台VM 下的linux(CentOS5.5)服务器,采用keepalived软件作为高可用和负载均衡的处理软件。
主节点IP:192.168.1.196
备用节点IP:192.168.1.195
自行配置好yum源,采用本地镜像和外部的yum源都可以,以下的这个步骤是在两台服务器上安装相关的软件,当然根据系统不同,需要安装的软件不尽相同,这里是列出来我需要安装的软件,大家可以根据提示自行安装。
第一:先说在双节点都要做的相同的步骤
[root@localhost ~]# yum -y install ipvsadm kernel-devel openssl openssl-devel
[root@localhost ~]# ln -s /usr/src/kernels/2.6.18-194.el5-i686/ /usr/src/linux
[root@localhost ~]# wget http://www.keepalived.org/software/keepalived-1.2.1.tar.gz
[root@localhost ~]# ls keepalived-1.2.1.tar.gz
keepalived-1.2.1.tar.gz
[root@localhost ~]# tar zxvf keepalived-1.2.1.tar.gz
[root@localhost ~]# cd keepalived-1.2.1
[root@localhost keepalived-1.2.1]# ./configure //结束后出现以下的内容表示可以编译安装了
Keepalived configuration
------------------------
Keepalived version : 1.2.1
Compiler : gcc
Compiler flags : -g -O2 -DETHERTYPE_IPV6=0x86dd
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use Debug flags : No
[root@localhost keepalived-1.2.1]# make && make install
[root@localhost ~]# yum -y install mysql-server mysql
第二:mysql在主节点上的设置(MASTER)
首先是对mysql的设置(关键)
[root@localhost ~]# /etc/init.d/mysqld start
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> grant replication slave,file on *.* to 'repl1'@'192.168.1.195' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
mysql> \q
Bye
[root@localhost ~]# /etc/init.d/mysqld stop
[root@localhost ~]# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
log-bin=mysql-bin
server-id=1
binlog-do-db=test
binlog-ignore-db=mysql
replicate-do-db=test
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[root@localhost ~]# /etc/init.d/mysqld start
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> flush tables with read lock\G
Query OK, 0 rows affected (0.00 sec)
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 98
Binlog_Do_DB: test
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
mysql> change master to master_host='192.168.1.195', master_user='repl2', master_password='123456', master_log_file='mysql-bin.000001', master_log_pos=98;
mysql> slave start;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> unlock tables;
Query OK, 0 rows affected (0.15 sec)
mysql> show slave status\G; //这个步骤关键是看到以下两项开启
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)