作者:張發表於:2014-08-19
版權聲明:可以任意轉載,轉載時請務必以超鏈接形式標明文章原始出處和作者信息及本版權聲明
利用Mysql+ PaceMaker+NFS構建MySQL高可用
環境說明:
MySQL-vip192.168.11.33
MySQL-server01192.168.11.22
MySQL-server02192.168.11.23
軟件版本:
mysql-server-5.1.73
pacemaker-1.1.10
關於pacemaker詳細配置請參見,這里只做簡單配置介紹。
1.1.1 MySQL高可用
以下操作在主備節點均操作
安裝Mysql服務
yum install -y mysql-server
關閉MySQL服務自啟動操作,此目的是為了讓pacemaker接管MySQL服務的啟動關閉。
chkconfig mysqld off
本方案中MySQL在主備節點掛載共享目錄實現數據的一致性,掛載目錄為/var/lib/mysql/
mount 192.168.11.21:/nfs/mysql /var/lib/mysql
復制主節點配置到備節點上
scp /etc/ my.cnf 192.168.11.23:/etc/
scp -r /etc/mysql/ 192.168.11.23:/etc/
ssh 192.168.11.23 -C "chown -R mysql /etc/mysql&&chown mysql /etc/my.cnf"
配置MySQL crm 腳本
crm configure
primitive p_vip_mysql ocf:heartbeat:IPaddr2 \
paramsip="192.168.11.33" cidr_netmask="24" \
opmonitor interval="30s" timeout="30s"
commit
exit
crm configure
primitive p_mysql ocf:heartbeat:mysql \
params config="/etc/my.cnf" \
pid="/var/run/mysqld/mysqld.pid" \
socket="/var/lib/mysql/mysql.sock" \
log="/var/log/mysqld.log" \
datadir="/var/lib/mysql" \
op monitor interval="30s"timeout="30s" \
op start timeout="120s" \
op stop timeout="120s"
colocation col_p_mysql_on_vip inf: p_mysqlp_vip_mysql
order ord_vip_before_p_vip_mysql inf:p_vip_mysql p_mysql
commit
exit
#################
# 開啟資源 #
#################
crmresource start p_mysql
#################
# 停止資源 #
#################
crmresource stop p_mysql
#################
# 刪除資源 #
#################
crmresource stop p_mysql
crmresource cleanup p_mysql
crmresource delete p_mysql
crmresource stop p_vip_mysql
crmresource cleanup p_vip_mysql
crmresource delete p_vip_mysql