Keepalived 架構高可用 Mysql
Keepalived 架構高可用 Mysql
以下是我實驗的步驟,僅供參考。
1、實驗網路拓撲圖
2、keepalived的安裝
在10.72.16.226和10.72.16.227分別安裝keepalived軟體。
[root@localhost ~]# tar xf keepalived-1.2.1.tar.gz
[root@localhost ~]# cd keepalived-1.2.1
[root@localhost keepalived-1.2.1]# ./configure --prefix=/ --mandir=/usr/local/share/man/ --with-kernel-dir=/usr/src/kernels/2.6.18-194.el5xen-i686/
--選擇和自己一樣的kernel,tab鍵補齊。
[root@localhost keepalived-1.2.1]# make
[root@localhost keepalived-1.2.1]# make install
主備機器都如上安裝。
3、keepalived的配置
3.1在10.72.16.226(master)上面配置
[root@localhost keepalived-1.2.1]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.default
[root@localhost keepalived]# vim keepalived.conf
主備mysql中只是黃色字型不一樣,其他都一樣
global_defs {
router_id Hadb_1
}
vrrp_sync_group VGM {
group {
VI_HA
}
}
vrrp_script chk_mysql {
script "killall -0 mysqld"
#script "/tcp/127.0.0.1/3306"
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.72.16.230
}
track_script {
chk_mysql
}
}
[root@localhost keepalived]#scp keepalived.conf 10.72.16.227:/etc/keepalived/
3.2在10.72.16.227(backup)上面的配置
[root@localhost keepalived-1.2.1]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.default
[root@localhost keepalived]# vim keepalived.conf
主備的keepalived.conf中只是黃色字型不一樣,其他都一樣。
所以只需將state改成BACKUP,priority改成50即可
global_defs {
router_id Hadb_1
}
vrrp_sync_group VGM {
group {
VI_HA
}
}
vrrp_script chk_mysql {
script "killall -0 mysqld"
#script "/tcp/127.0.0.1/3306"
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.72.16.230
}
track_script {
chk_mysql
}
}
3.3啟動 Keepalived 服務
分別啟動兩臺伺服器(10.72.16.226和10.72.16227)的 Keepalived 服務並觀察其日誌,校驗高可用是否成功。
[localhost@localhost ~]# service keepalived start
[localhost @localhost ~]# tail /var/log/messages
3.4 測試keepalived
1)在一臺裝有 mysql 客戶端的 windows 或 linux 機器登陸 VIP 10.72.16.230 測試。
# mysql -uroot –p123 -h10.72.16.230
2)keepalived 故障轉移測試
A:在 windows 或 linux 客戶端一直去 ping VIP 10.72.16.230,然後關閉 10.72.16.226 上的 keepalived,正常情況下 VIP 10.72.16.230就會切換到 10.72.16.227 上面去。
注:透過命令ip a來檢視vip 10.72.16.230,ifconfig看不到。
B:開啟 10.72.16.226 上的 keepalived,看vip是否能自動切換回來。
3)MySQL 故障轉移測試
A:在 10.72.16.226 上關閉 MySQL 服務,看 VIP 是否會切換到 10.72.16.227上
[localhost@localhost ~]# service mysqld stop
[localhost @localhost ~]# tail /var/log/messages -f
[root@localhost keepalived]# ip a
2: eth0:
link/ether 00:0c:29:76:fe:3b brd ff:ff:ff:ff:ff:ff
inet 10.72.16.226/24 brd 10.72.16.255 scope global eth0
inet 10.72.16.230/32 scope global eth0
inet6 fe80::20c:29ff:fe76:fe3b/64 scope link
valid_lft forever preferred_lft forever
4 、MySQL主主複製
4.1 授權使用者
在10.72.16.226上
grant replication slave,file on *.* to 'repl1'@'10.72.16.227' identified by '123';
在10.72.16.227上
grant replication slave,file on *.* to 'repl2'@'10.72.16.226' identified by '123';
4.2 修改配置檔案
4.2.1 在10.72.16.226上
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=db1 #需要進行同步的資料庫
binlog-ignore-db=mysql
replicate-do-db=db1 #需要進行同步的資料庫
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
master-host=10.72.16.227
master-user=repl2
master-password=123
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
4.2.2 在10.72.16.227上
vi /etc/my.cnf
新增如下標黃色部分,其中只需要修改紅色字型部分。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
log-bin=mysql-bin
server-id=2
binlog-do-db=db1 #需要同步的資料庫
binlog-ignore-db=mysql
replicate-do-db=db1 #需要同步的資料庫
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
master-host=10.72.16.226
master-user=repl1
master-password=123
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
~
4.3分別重啟兩伺服器的 Mysql 服務
service mysqld restart
4.4 分別在兩伺服器上檢視從伺服器狀態
mysql>show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
檢視以上兩項的值,均為 Yes 則表示狀態正常
4.5 測試主主同步
A:測試伺服器 Master,在伺服器 Master 中新建資料
mysql> use db1
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
1 row in set (0.00 sec)
mysql> create table t2 (id int,name varchar(10));
Query OK, 0 rows affected (0.00 sec)
B:在 Backup 伺服器進行檢視
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t2 |
+----------------+
2 rows in set (0.00 sec)
C:在 Backup 伺服器中插入一條記錄
mysql> insert into t2 values (001,"ganxing");
Query OK, 1 row affected (0.01 sec)
D:在 Master 伺服器中檢視
mysql> select * from t2;
+------+---------+
| id | name |
+------+---------+
| 1 | ganxing |
+------+---------+
1 row in set (0.00 sec)
以上,我們搭建完成了MYSQL的主主複製和keepalived提供vip漂移的高可用模式。
完!
附件列表
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28916011/viewspace-1409122/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL高可用架構:mysql+keepalived實現MySql架構
- MySQL高可用架構之Keepalived+主從架構部署MySql架構
- 部署MHA+keepalived+ProxySQL高可用架構SQL架構
- mysql高可用之keepalivedMySql
- 基於MySQL Cluster + LVS + KeepAlived部署負載均衡高可用架構MySql負載架構
- mysql高可用衡搭建(Keepalived)MySql
- Mysql高可用架構方案MySql架構
- MySQL 高可用架構之 MMM 架構MySql架構
- keepalived+MySQL實現高可用MySql
- MySQL主主模式+Keepalived高可用MySql模式
- MySQL高可用架構對比MySql架構
- mysql高可用架構MHA搭建MySql架構
- Keepalived 高可用
- MySQL高可用架構設計分析MySql架構
- MySQL 高可用性—keepalived+mysql雙主MySql
- MySQL 實現高可用架構之 MHAMySql架構
- MySQL高可用架構-MMM、MHA、MGR、PXCMySql架構
- 高可用架構架構
- 使用Keepalived構建LVS高可用叢集
- MySQL叢集搭建(6)-雙主+keepalived高可用MySql
- MySQL進階:主主複製+Keepalived高可用MySql
- MySQL主從原理, 高可用架構與高效能架構MySql架構
- MySQL資料庫架構——高可用演進MySql資料庫架構
- PostgreSQL repmgr高可用叢集+keepalived高可用SQL
- mysql高可用架構MHA搭建(centos7+mysql5.7.28)MySql架構CentOS
- 構建MHA實現MySQL高可用叢集架構MySql架構
- Keepalived 高可用詳解
- LVS+keepalived高可用
- 高可用(keepalived)部署方案
- nginx+keepalived高可用Nginx
- 【IT老齊075】高可用架構避免單點經典方案Keepalived+VIP架構
- keepalived+haproxy實現mysql負載均衡高可用MySql負載
- mysql5.6主主複製及keepalived 高可用MySql
- MySQL高可用架構之MHA 原理與實踐MySql架構
- MySQL高可用架構案例篇:UCloud最佳實踐MySql架構Cloud
- MySQL 高可用架構 - MHA環境部署記錄MySql架構
- java程式設計—如何搭建Keepalived+Nginx+Tomcat高可用負載均衡架構Java程式設計NginxTomcat負載架構
- keepalived高可用負載均衡負載
- nginx實現keepalived高可用Nginx