您好,登錄后才能下訂單哦!
小編給大家分享一下MySQL如何實現高可用+共享存儲NFS,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
規劃圖
1、首先進行資源的分析
1)Vip
2)Mysqld
3)Nfs
理清他們之間的啟動先后順序:nfs必須在mysqld啟動前啟動
2、nfs的配置
NFS共享目錄上掛載的分區,最好做成lvm,實現自動擴展
2.1 安裝
# yum -y install nfs-utils
2.2 配置
# mkdir /share
# vim /etc/exports
172.16.98.3:/share 172.16.98.1(rw,no_root_squash) 172.16.98.2(rw,no_root_squash)
# service nfs start
# groupadd -g 186 mysql
# useradd -u 186 -g mysql -s /sbin/nologin -M mysql
# chown mysql:mysql /share
3、在mysql1上掛載nfs分區進行mysql安裝測試
3.1 掛載nfs
# mkdir /data
# chown mysql:mysql /data
# mount 172.16.98.3:/share /data
3.2 使用mysql的解壓縮包安裝
# groupadd -g 186 mysql
# useradd -u 186 -g mysql -s /sbin/nologin -M mysql
在三臺機器上,創建的mysql組和用戶的uid、gid要保持一致
# tar -zxvf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local
# cd /usr/local
# ln -s mysql-5.5.24-linux2.6-i686 mysql
# cd mysql
# chown -R mysql:mysql .
# scripts/mysql_install_db --user=mysql --datadir=/data
# chowm -R root .
# cp support-files/my-large.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin
# export PATH=$PATH:/usr/local/mysql/bin
3.3 編輯配置文件,啟動服務
# vim /etc/my.cnf
[mysqld]
thread_concurrency = 2
datadir=/data
# service mysqld start
3.4 在mysql2上的安裝
參考前面的步驟,需要說明一點的是MySQL的安裝,這里不需要再進行初始化mysql
# tar -zxvf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local
# cd /usr/local
# ln -s mysql-5.5.24-linux2.6-i686 mysql
# cd mysql
# chowm -R root .
# cp support-files/my-large.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin
# export PATH=$PATH:/usr/local/mysql/bin
# service mysqld start
# cd /data
3.5 停止所有資源
1)關閉mysql服務
# service mysqld stop
2)將nfs共享目錄卸載
# umount /data
4、Corosync的安裝
前期準備
1)ssh雙機互信,方便配置
2)時間保持一致
3)/etc/hosts ,主機名設置,互相解析
4.1 在mysql1、mysql2上安裝corosync
# yum install -y cluster-glue-1.0.6-1.6.el5.i386.rpm
cluster-glue-libs-1.0.6-1.6.el5.i386.rpm
corosynclib-1.2.7-1.1.el5.i386.rpm corosync-1.2.7-1.1.el5.i386.rpm
heartbeat-3.0.3-2.3.el5.i386.rpm heartbeat-libs-3.0.3-2.3.el5.i386.rpm
libesmtp-1.0.4-5.el5.i386.rpm pacemaker-cts-1.1.5-1.1.el5.i386.rpm
pacemaker-libs-1.1.5-1.1.el5.i386.rpm pacemaker-1.1.5-1.1.el5.i386.rpm
perl-TimeDate-1.16-5.el5.noarch.rpm
resource-agents-1.0.4-1.1.el5.i386.rpm
4.2 corosync的配置
1)mysql1
# cd /etc/corosync
# cp corosync.conf.example corosync.conf
# vim corosync.conf
compatibility: whitetank
totem {
version: 2
secauth:on 開啟身份驗證
threads: 0
interface {
ringnumber: 0
bindnetaddr: 172.16.0.0
mcastaddr: 226.94.1.1
mcastport: 5405
}
}
logging {
fileline: off
to_stderr: on
to_logfile: yes
# to_syslog: yes
logfile: /var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
service {
ver:0
name:pacemaker
}
# corosync-keygen 創建authkeys
# scp authkeys corosync.conf node2:/etc/corosync
兩臺mysql上分別創建用于日志的目錄
# mkdir /var/log/cluster
4.3 通過mysql1開啟corosync,配置資源
1)開啟
# service corosync start
# ssh node2 'service corosync start'
# crm_mon
============
Last updated: Thu Aug 9 22:12:22 2012
Stack: openais
Current DC: node1.linuxidc.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
0 Resources configured.
============
Online: [ node2.linuxidc.com node1.linuxidc.com ]
2)資源的配置
# crm
crm(live)# configure
crm(live)configure# primitive vip ocf:heartbeat:IPaddr params ip=172.16.99.1
crm(live)configure# primitive mysqld lsb:mysqld
crm(live)configure# primitive nfs ocf:heartbeat:Filesystem params device=172.16.98.3:/share directory=/data fstype=nfs op start timeout=60 op stop timeout=60
//定義nfs資源,默認的超時時間是20s,是小于建議的時間60s的,所以手動配置
crm(live)configure# colocation vip_mysqld_nfs inf: mysqld nfs vip
crm(live)configure# order mysqld_after_nfs inf: nfs mysqld
crm(live)configure# property stonith-enabled=false
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# verify
crm(live)configure# commit
3)檢測
# crm_mon
Last updated: Thu Aug 9 22:34:52 2012
Stack: openais
Current DC: node1.linuxidc.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
3 Resources configured.
============
Online: [ node2.linuxidc.com node1.linuxidc.com ]
nfs (ocf::heartbeat:Filesystem): Started node1.linuxidc.com
vip (ocf::heartbeat:IPaddr): Started node1.linuxidc.com
mysqld (lsb:mysqld): Started node1.linuxidc.com
# crm node standy
# crm_mon
============
Last updated: Thu Aug 9 22:36:18 2012
Stack: openais
Current DC: node1.linuxidc.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
3 Resources configured.
============
Node node1.linuxidc.com: standby
Online: [ node2.linuxidc.com ]
nfs (ocf::heartbeat:Filesystem): Started node2.linuxidc.com
vip (ocf::heartbeat:IPaddr): Started node2.linuxidc.com
mysqld (lsb:mysqld): Started node2.linuxidc.com
以上是“MySQL如何實現高可用+共享存儲NFS”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。