您好,登錄后才能下訂單哦!
下文給大家?guī)碛嘘P(guān)配置及安裝drbd+corosync實現(xiàn)高可用mysql教程內(nèi)容,相信大家一定看過類似的文章。我們給大家?guī)淼挠泻尾煌??一起來看看正文部分吧,相信看完配置及安裝drbd+corosync實現(xiàn)高可用mysql教程你一定會有所收獲。
前提:
本配置共有兩個測試節(jié)點,分別node1和node2,相的IP地址分別為202.207.178.6和202.207.178.7,管理節(jié)點202.207.178.8,對node1和node2進行配置。此時已經(jīng)配置好drbd,并且可以正常工作了!
(為避免影響,先關(guān)閉防火墻和SElinux,DRBD相關(guān)配置詳見http://10927734.blog.51cto.com/10917734/1867283)
一、安裝corosync
1、先停止drbd服務(wù),并禁止其開機自動啟動
主節(jié)點:
[root@node2 ~]# umount /mydata/
[root@node2 ~]# drbdadm secondary mydrbd
[root@node2 ~]# service drbd stop
[root@node2 ~]# chkconfig drbd off
從節(jié)點:
[root@node1 ~]# service drbd stop
[root@node1 ~]# chkconfig drbd off
2、安裝相關(guān)軟件包
[root@fsy ~]# for I in {1..2}; do ssh node$I 'mkdir /root/corosync/'; scp *.rpm node$I:/root/corosync; ssh node$I 'yum -y --nogpgcheck localinstall /root/corosync/*.rpm'; done
(將heartbeat-3.0.4-2.el6.i686.rpm和heartbeat-libs-3.0.4-2.el6.i686.rpm復(fù)制到主目錄下進行)
[root@fsy ~]# for I in {1..2}; do ssh node$I 'yum -y install cluster-glue corosync libesmtp pacemaker pacemaker-cts'; done
3、創(chuàng)建所需日志目錄
[root@node1 corosync]# mkdir /var/log/cluster
[root@node2 ~]# mkdir /var/log/cluster
4、配置corosync,(以下命令在node1上執(zhí)行),并嘗試啟動
# cd /etc/corosync
# cp corosync.conf.example corosync.conf
接著編輯corosync.conf,添加如下內(nèi)容:
修改以下語句:
bindnetaddr: 202.207.178.0 #網(wǎng)絡(luò)地址,節(jié)點所在的網(wǎng)絡(luò)地址段
secauth: on #打開安全認(rèn)證
threads: 2 #啟動的線程數(shù)
to_syslog: no (不在默認(rèn)位置記錄日志)
添加如下內(nèi)容,定義pacemaker隨corosync啟動,并且定義corosync的工作用戶和組:
service {
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}
生成節(jié)點間通信時用到的認(rèn)證密鑰文件:
# corosync-keygen
將corosync和authkey復(fù)制至node2:
# scp -p corosync.conf authkey node2:/etc/corosync/
嘗試啟動,(以下命令在node1上執(zhí)行):
# service corosync start
注意:啟動node2需要在node1上使用如上命令進行,不要在node2節(jié)點上直接啟動
# ssh node2 '/etc/init.d/corosync start'
5、測試是否正常
查看corosync引擎是否正常啟動:
# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log
輸出以下內(nèi)容:
Oct 23 00:38:06 corosync [MAIN ] Corosync Cluster Engine ('1.4.7'): started and ready to provide service.
Oct 23 00:38:06 corosync [MAIN ] Successfully read main configuration file '/etc/corosync/corosync.conf'
查看初始化成員節(jié)點通知是否正常發(fā)出:
# grep TOTEM /var/log/cluster/corosync.log
輸出如下內(nèi)容:
Oct 23 00:38:06 corosync [TOTEM ] Initializing transport (UDP/IP Multicast).
Oct 23 00:38:06 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Oct 23 00:38:06 corosync [TOTEM ] The network interface [202.207.178.6] is now up.
Oct 23 00:39:35 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.
檢查啟動過程中是否有錯誤產(chǎn)生:
# grep ERROR: /var/log/messages | grep -v unpack_resources
查看pacemaker是否正常啟動:
# grep pcmk_startup /var/log/cluster/corosync.log
輸出如下內(nèi)容:
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: CRM: Initialized
Oct 23 00:38:06 corosync [pcmk ] Logging: Initialized pcmk_startup
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: Maximum core file size is: 4294967295
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: Service: 9
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: Local hostname: node1
使用如下命令查看集群節(jié)點的啟動狀態(tài):
# crm_mon
Last updated: Tue Oct 25 17:28:10 2016 Last change: Tue Oct 25 17:21:56 2016 by hacluster via crmd on node1
Stack: classic openais (with plugin)
Current DC: node1 (version 1.1.14-8.el6_8.1-70404b0) - partition with quorum
2 nodes and 0 resources configured, 2 expected votes
Online: [ node1 node2 ]
從上面的信息可以看出兩個節(jié)點都已經(jīng)正常啟動,并且集群已經(jīng)處于正常工作狀態(tài)。
二、配置資源及約束
1、安裝crmsh軟件包:
pacemaker本身只是一個資源管理器,我們需要一個接口才能對pacemker上的資源進行定義與管理,而crmsh即是pacemaker的配置接口,從pacemaker 1.1.8開始,crmsh 發(fā)展成一個獨立項目,
pacemaker中不再提供。crmsh提供了一個命令行的交互接口來對Pacemaker集群進行管理,它具有更強大的管理功能,同樣也更加易用,在更多的集群上都得到了廣泛的應(yīng)用,類似軟件還有 pcs;
在/etc/yum.repo.d/ 下的配置文件中添加以下內(nèi)容
[ewai]
name=aaa
baseurl=http://download.opensuse.org/repositories/network:/ha- clustering:/Stable/CentOS_CentOS-6/
enabled=1
gpgcheck=0
# yum clean all
# yum makecache
[root@node1 yum.repos.d]# yum install crmsh
2、檢查配置文件有無語法錯誤,并進行相關(guān)配置
crm(live)configure# verify
我們里可以通過如下命令先禁用stonith:
# crm configure property stonith-enabled=false
或 crm(live)configure# property stonith-enabled=false
crm(live)configure# commit
配置不具備法定票數(shù)的處理方式:
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# verify
crm(live)configure# commit
配置資源粘性,使資源更愿意留在當(dāng)前節(jié)點
crm(live)configure# rsc_defaults resource-stickiness=100
crm(live)configure# verify
crm(live)configure# commit
3、配置資源
定義一個名為mysqldrbd的資源:
(interval:定義監(jiān)控的時間間隔)
crm(live)configure# primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mydrbd op start timeout=240 op stop timeout=100 op monitor role=Master interval=20 timeout=30 op monitor role=Slave interval=30 timeout=30
crm(live)configure# verify
定義一個名為ms_mysqldrbd的主從類型的資源:
指明是mysqldrbd的克隆,master-max=1:定義最多出現(xiàn)1個主資源,master-node-max=1:主資源在同一時刻只能出現(xiàn)在一個節(jié)點上,clone-max=2:定義最多有兩個克隆資源,clone-node-max:定義在每個節(jié)點上只能啟動1個克隆資源
crm(live)configure# ms ms_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
crm(live)configure# verify
crm(live)configure# commit
4、測試
[root@node1 ~]# crm status
Last updated: Sun Oct 23 13:05:43 2016 Last change: Sun Oct 23 13:03:52 2016 by root via cibadmin on node1
Stack: classic openais (with plugin)
Current DC: node1 (version 1.1.14-8.el6_8.1-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes
Online: [ node1 node2 ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ node1 ]
Slaves: [ node2 ]
[root@node1 ~]# drbd-overview
0:mydrbd Connected Primary/Secondary UpToDate/UpToDate C r-----
[root@node1 ~]# crm node standby
[root@node1 ~]# crm status
Last updated: Sun Oct 23 13:06:30 2016 Last change: Sun Oct 23 13:06:25 2016 by root via crm_attribute on node1
Stack: classic openais (with plugin)
Current DC: node1 (version 1.1.14-8.el6_8.1-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes
Node node1: standby
Online: [ node2 ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ node2 ]
Stopped: [ node1 ]
[root@node1 ~]# crm node online
[root@node1 ~]# crm status
Last updated: Sun Oct 23 13:07:00 2016 Last change: Sun Oct 23 13:06:58 2016 by root via crm_attribute on node1
Stack: classic openais (with plugin)
Current DC: node1 (version 1.1.14-8.el6_8.1-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes
Online: [ node1 node2 ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ node2 ]
Slaves: [ node1 ]
服務(wù)正常!
5、配置一個文件系統(tǒng)資源,使DRBD自動掛載,并配置排列約束,使此資源和主節(jié)點在一起;同時配置一個順序約束,實現(xiàn)先啟動drbd,再啟動mystor
crm(live)configure# primitive mystore ocf:Filesystem params device=/dev/drbd0 directory=/mydata fstype=ext4 op start timeout=60 op stop timeout=60
crm(live)configure# verify
crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master
crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start
crm(live)configure# verify
crm(live)configure# commit
測試:
[root@node2 ~]# crm node standby
[root@node2 ~]# crm status
Last updated: Sun Oct 23 13:45:26 2016 Last change: Sun Oct 23 13:45:20 2016 by root via crm_attribute on node2
Stack: classic openais (with plugin)
Current DC: node2 (version 1.1.14-8.el6_8.1-70404b0) - partition with quorum
2 nodes and 3 resources configured, 2 expected votes
Node node2: standby
Online: [ node1 ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ node1 ]
Stopped: [ node2 ]
mystore (ocf::heartbeat:Filesystem): Started node1
[root@node1 yum.repos.d]# ls /mydata/
fsy lost+found
此時測試,一切正常!
三、安裝Mysql(先在主節(jié)點上,后在從節(jié)點上)
1.將下載好的壓縮包解壓至/usr/local,并進入此目錄
#tar xf mysql-5.5.52-linux2.6-i686.tar.gz -C /usr/local
#cd /usr/local/
2.為解壓后的目錄創(chuàng)建一個鏈接,并進入此目錄
#ln -sv mysql-5.5.52-linux2.6-i686 mysql
#cd mysql
3.創(chuàng)建MySQL用戶(使其成為系統(tǒng)用戶)和MySQL組
#groupadd -r -g 306 mysql
#useradd -g 306 -r -u 306 mysql
4.使mysql下的所有文件都屬于mysql用戶和mysql組
#chown -R mysql:mysql /usr/local/mysql/*
5.創(chuàng)建數(shù)據(jù)目錄,并使其屬于mysql用戶和mysql組,其他人無權(quán)限
#mkdir /mydata/data
#chown -R mysql:mysql /mydata/data/
#chmod o-rx /mydata/data/
6.準(zhǔn)備就緒,開始安裝
#scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
7.安裝完成后為了安全,更改/usr/local/mysql下所有文件的權(quán)限
#chown -R root:mysql /usr/local/mysql/*
8.準(zhǔn)備啟動腳本,并禁止其開機自動啟動
#cp support-files/mysql.server /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig mysqld off
9.編輯數(shù)據(jù)庫配置文件
#cp support-files/my-large.cnf /etc/my.cnf
#vim /etc/my.cnf,修改和添加以下內(nèi)容:
thread_concurrency =2(因為我的CPU數(shù)為1,所以線程數(shù)改為2)
datadir = /mydata/data
10.啟動mysql
# service mysqld start
# /usr/local/mysql/bin/mysql
11.測試是否正常
mysql> show databases;
mysql> CREATE DATABASE mydb;
mysql> show databases;
12.關(guān)閉主節(jié)點上的mysql服務(wù),使從節(jié)點變?yōu)橹鞴?jié)點,安裝mysql
[root@node1 mysql]# service mysqld stop
[root@node1 mysql]# crm node standby
[root@node1 mysql]# crm node online
13.將下載好的壓縮包解壓至/usr/local,并進入此目錄
#tar xf mysql-5.5.52-linux2.6-i686.tar.gz -C /usr/local
#cd /usr/local/
14.為解壓后的目錄創(chuàng)建一個鏈接,并進入此目錄
#ln -sv mysql-5.5.52-linux2.6-i686 mysql
#cd mysql
15.創(chuàng)建MySQL用戶(使其成為系統(tǒng)用戶)和MySQL組
#groupadd -r -g 306 mysql
#useradd -g 306 -r -u 306 mysql
16.使mysql下的所有文件都屬于root用戶和mysql組
#chown -R root:mysql /usr/local/mysql/*
17.準(zhǔn)備啟動腳本,并禁止其開機自動啟動
#cp support-files/mysql.server /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig mysqld off
18.編輯數(shù)據(jù)庫配置文件
#cp support-files/my-large.cnf /etc/my.cnf
#vim /etc/my.cnf,修改和添加以下內(nèi)容:
thread_concurrency =2(因為我的CPU數(shù)為1,所以線程數(shù)改為2)
datadir = /mydata/data
19.啟動mysql
# service mysqld start
# /usr/local/mysql/bin/mysql
20.測試是否正常
mysql> show databases;
發(fā)現(xiàn)有mydb數(shù)據(jù)庫!
測試成功!
四、配置mysql資源
1、停止主節(jié)點上的mysql服務(wù)
# service mysqld stop
2、定義主資源
crm(live)configure# primitive mysqld lsb:mysqld
crm(live)configure# verify
3、定義資源約束
定義排列約束,使mysqld和mystore在一起
crm(live)configure# colocation mysqld_with_mystore inf: mysqld mystore
crm(live)configure# verify
定義順序約束,使mystore先啟動,mysqld后啟動
crm(live)configure# order mysqld_after_mystore mandatory: mystore mysqld
crm(live)configure# verify
crm(live)configure# commit
4、測試
1)在主節(jié)點上連接mysql,并創(chuàng)建數(shù)據(jù)庫
mysql> CREATE DATABASES hellodb;
mysql> show databases;
2)節(jié)點切換(主節(jié)點上)
# crm node standby
# crm node online
3)在原來的從節(jié)點(及現(xiàn)在的主節(jié)點上測試)
mysql> show databases;
發(fā)現(xiàn)有hellodb數(shù)據(jù)庫!
測試成功!
至此,drbd+corosync的高可用mysql配置完成!
對于上文關(guān)于配置及安裝drbd+corosync實現(xiàn)高可用mysql教程,大家覺得是自己想要的嗎?如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。