|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!本次试验重要引见Mysql的高可用集群构建;其他的不多说了,上面直接开端装置设置装备摆设
1、情况引见及预备
1、本次设置装备摆设有两个节点:nod1.allen.com(172.16.14.1)与nod2.allen.com(172.16.14.2)
1
2
3
4
5
6
######在NOD1与NOD2节点履行以下敕令
cat>/etc/hosts<<EOF
172.16.14.1nod1.allen.comnod1
172.16.14.2nod2.allen.comnod2
EOF
正文:让一切节点的主机称号与对应的IP地址可以正常解析
2、每一个节点的主机称号须跟"uname-n"敕令的履行成果一样
1
2
3
4
5
6
7
######NOD1节点履行
sed-is@(HOSTNAME=).*@1nod1.allen.com@g/etc/sysconfig/network
hostnamenod1.allen.com
######NOD2节点履行
sed-is@(HOSTNAME=).*@1nod2.allen.com@g/etc/sysconfig/network
hostnamenod2.allen.com
正文:修正文件须重启体系失效,这里先修正文件然后履行敕令修正主机称号可以不消重启
3、nod1与nod2两个节点上各供给了一个雷同巨细的分区作为DRBD装备,这里我们在两个节点上分离创立"/dev/sda3"作为DRBD装备,巨细容量为2G
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
######在NOD1与NOD2节点上分离创立分区,分区巨细必需坚持一样
fdisk/dev/sda
Command(mforhelp):n
Commandaction
eextended
pprimarypartition(1-4)
p
Partitionnumber(1-4):3
Firstcylinder(7859-15665,default7859):
Usingdefaultvalue7859
Lastcylinder,+cylindersor+size{K,M,G}(7859-15665,default15665):+2G
Command(mforhelp):w
partx/dev/sda#让内核从新读取分区
######检查内核有无辨认分区,假如没有须要从新启动,这里没有辨认须要重启体系
cat/proc/partitions
majorminor#blocksname
80125829120sda
81204800sda1
8262914560sda2
253020971520dm-0
25312097152dm-1
253210485760dm-2
253320971520dm-3
reboot
4、封闭两台办事器的SELinux、Iptables与NetworkManager
1
2
3
4
5
6
7
8
9
10
11
12
setenforce0#封闭SELinux
serviceiptablesstop#封闭Iptables
chkconfigiptablesoff#制止Iptables开机启动
serviceNetworkManagerstop
chkconfigNetworkManageroff
chkconfig--listNetworkManager
NetworkManager0:off1:off2:off3:off4:off5:off6:off
chkconfignetworkon
chkconfig--listnetwork
network0:off1:off2:on3:on4:on5:on6:off
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
留意:做的过程当中必需封闭NetworkManager办事封闭并设置开机不克不及主动启动;将network办事设置开机自启动;不然作试验过程当中会带来不用要的费事,形成集群体系不克不及正常运转
5、设置装备摆设好YUM源并同步时光,且包管两个节点的时光要同步epel源下载
1
2
3
######设置装备摆设epel源
######在NOD1与NOD2节点分离装置
rpm-ivhepel-release-6-8.noarch.rpm
6、做双机互信
1
2
3
4
5
[root@nod1~]#ssh-keygen-trsa
[root@nod1~]#ssh-copy-id-i.ssh/id_rsa.pubnod2
==================================================
[root@nod2~]#ssh-keygen-trsa
[root@nod2~]#ssh-copy-id-i.ssh/id_rsa.pubnod1
7、体系版本:CentOS6.4_x86_64
8、应用软件:个中pacemaker与corosync在光盘映像中有
pssh-2.3.1-2.el6.x86_64下载见附件
crmsh-1.2.6-4.el6.x86_64下载见附件
drbd-8.4.3-33.el6.x86_64DRBD下载地址:http://rpmfind.net
drbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64
mysql-5.5.33-linux2.6-x86_64点此下载
pacemaker-1.1.8-7.el6.x86_64
corosync-1.4.1-15.el6.x86_64
2、装置设置装备摆设DRBDDRBD详解
1、在NOD1与NOD2节点上装置DRBD软件包
1
2
3
4
5
6
7
8
######NOD1
[root@nod1~]#lsdrbd-*
drbd-8.4.3-33.el6.x86_64.rpmdrbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64.rpm
[root@nod1~]#yum-yinstalldrbd-*.rpm
######NOD2
[root@nod2~]#lsdrbd-*
drbd-8.4.3-33.el6.x86_64.rpmdrbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64.rpm
[root@nod2~]#yum-yinstalldrbd-*.rpm
2、检查DRBD设置装备摆设文件
1
2
3
4
5
6
7
8
9
10
ll/etc/drbd.conf;ll/etc/drbd.d/
-rw-r--r--1rootroot133May1421:12/etc/drbd.conf#主设置装备摆设文件
total4
-rw-r--r--1rootroot1836May1421:12global_common.conf#全局设置装备摆设文件
######检查主设置装备摆设文件内容
cat/etc/drbd.conf
######主设置装备摆设文件中包括了全局设置装备摆设文件及"drbd.d/"目次下以.res开头的文件
#Youcanfindanexamplein/usr/share/doc/drbd.../drbd.conf.example
include"drbd.d/global_common.conf";
include"drbd.d/*.res";
3、修正设置装备摆设文件以下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[root@nod1~]#vim/etc/drbd.d/global_common.conf
global{
usage-countno;#能否加入DRBD应用统计,默许为yes
#minor-countdialog-refreshdisable-ip-verification
}
common{
protocolC;#应用DRBD的同步协定
handlers{
#TheseareEXAMPLEhandlersonly.
#Theymayhavesevereimplications,
#likehardresettingthenodeundercertaincircumstances.
#Becarefulwhenchosingyourpoison.
pri-on-incon-degr"/usr/lib/drbd/notify-pri-on-incon-degr.sh;/usr/lib/drbd/notify-emergency-reboot.sh;echob>/proc/sysrq-trigger;reboot-f";
pri-lost-after-sb"/usr/lib/drbd/notify-pri-lost-after-sb.sh;/usr/lib/drbd/notify-emergency-reboot.sh;echob>/proc/sysrq-trigger;reboot-f";
local-io-error"/usr/lib/drbd/notify-io-error.sh;/usr/lib/drbd/notify-emergency-shutdown.sh;echoo>/proc/sysrq-trigger;halt-f";
#fence-peer"/usr/lib/drbd/crm-fence-peer.sh";
#split-brain"/usr/lib/drbd/notify-split-brain.shroot";
#out-of-sync"/usr/lib/drbd/notify-out-of-sync.shroot";
#before-resync-target"/usr/lib/drbd/snapshot-resync-target-lvm.sh-p15---c16k";
#after-resync-target/usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
startup{
#wfc-timeoutdegr-wfc-timeoutoutdated-wfc-timeoutwait-after-sb
}
options{
#cpu-maskon-no-data-accessible
}
disk{
on-io-errordetach;#设置装备摆设I/O毛病处置战略为分别
#sizemax-bio-bvecson-io-errorfencingdisk-barrierdisk-flushes
#disk-drainmd-flushesresync-rateresync-afteral-extents
#c-plan-aheadc-delay-targetc-fill-targetc-max-rate
#c-min-ratedisk-timeout
}
net{
cram-hmac-alg"sha1";#设置加密算法
shared-secret"allendrbd";#设置加密密钥
#protocoltimeoutmax-epoch-sizemax-buffersunplug-watermark
#connect-intping-intsndbuf-sizercvbuf-sizeko-count
#allow-two-primariescram-hmac-algshared-secretafter-sb-0pri
#after-sb-1priafter-sb-2prialways-asbprr-conflict
#ping-timeoutdata-integrity-algtcp-corkon-congestion
#congestion-fillcongestion-extentscsums-algverify-alg
#use-rle
}
syncer{
rate1024M;#设置主备节点同步时的收集速度
}
}
4、添加资本文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@nod1~]#vim/etc/drbd.d/drbd.res
resourcedrbd{
onnod1.allen.com{#第个主机解释以on开首,前面是主机称号
device/dev/drbd0;#DRBD装备称号
disk/dev/sda3;#drbd0应用的磁盘分区为"sda3"
address172.16.14.1:7789;#设置DRBD监听地址与端口
meta-diskinternal;
}
onnod2.allen.com{
device/dev/drbd0;
disk/dev/sda3;
address172.16.14.2:7789;
meta-diskinternal;
}
}
5、将设置装备摆设文件为NOD2供给一份
1
2
3
4
5
6
7
8
[root@nod1~]#scp/etc/drbd.d/{global_common.conf,drbd.res}nod2:/etc/drbd.d/
Theauthenticityofhostnod2(172.16.14.2)cantbeestablished.
RSAkeyfingerprintis29:d3:28:85:20:a1:1f:2a:11:e5:88:cd:25:d0:95:c7.
Areyousureyouwanttocontinueconnecting(yes/no)?yes
Warning:Permanentlyaddednod2(RSA)tothelistofknownhosts.
root@nod2spassword:
global_common.conf100%19431.9KB/s00:00
drbd.res100%3180.3KB/s00:00
6、初始化资本并启动办事
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
######在NOD1与NOD2节点上初始化资本并启动办事
[root@nod1~]#drbdadmcreate-mddrbd
Writingmetadata...
initializingactivitylog
NOTinitializingbitmap
lk_bdev_save(/var/lib/drbd/drbd-minor-0.lkbd)failed:Nosuchfileordirectory
Newdrbdmetadatablocksuccessfullycreated.#提醒曾经创立胜利
lk_bdev_save(/var/lib/drbd/drbd-minor-0.lkbd)failed:Nosuchfileordirectory
######启动办事
[root@nod1~]#servicedrbdstart
StartingDRBDresources:[
createres:drbd
preparedisk:drbd
adjustdisk:drbd
adjustnet:drbd
]
..........
***************************************************************
DRBDsstartupscriptwaitsforthepeernode(s)toappear.
-Incasethisnodewasalreadyadegradedclusterbeforethe
rebootthetimeoutis0seconds.[degr-wfc-timeout]
-Ifthepeerwasavailablebeforetherebootthetimeoutwill
expireafter0seconds.[wfc-timeout]
(Thesevaluesareforresourcedrbd;0sec->waitforever)
Toabortwaitingenteryes[12]:yes
7、初始化装备同步
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@nod1~]#drbdadm----overwrite-data-of-peerprimarydrbd
[root@nod1~]#cat/proc/drbd#检查同步进度
version:8.4.3(api:1/proto:86-101)
GIT-hash:89a294209144b68adb3ee85a73221f964d3ee515buildbygardner@,2013-05-2704:30:21
0:cs:SyncSourcero:Primary/Secondaryds:UpToDate/InconsistentCr---n-
ns:1897624nr:0dw:0dr:1901216al:0bm:115lo:0pe:3ua:3ap:0ep:1wo:foos:207988
[=================>..]synced:90.3%(207988/2103412)K
finish:0:00:07speed:26,792(27,076)K/sec
######当同步完成时如以下状况
version:8.4.3(api:1/proto:86-101)
GIT-hash:89a294209144b68adb3ee85a73221f964d3ee515buildbygardner@,2013-05-2704:30:21
0:cs:Connectedro:Primary/Secondaryds:UpToDate/UpToDateCr-----
ns:2103412nr:0dw:0dr:2104084al:0bm:129lo:0pe:0ua:0ap:0ep:1wo:foos:0
正文:drbd:为资本称号
######检查同步进度也可以使用以下敕令
drbd-overview
8、创立文件体系
1
2
######格局化文件体系
[root@nod1~]#mkfs.ext4/dev/drbd0
9、制止NOD1与NOD2节点上的DRBD办事开机自启动
1
2
3
4
5
6
7
[root@nod1~]#chkconfigdrbdoff
[root@nod1~]#chkconfig--listdrbd
drbd0:off1:off2:off3:off4:off5:off6:off
=====================================================================
[root@nod2~]#chkconfigdrbdoff
[root@nod2~]#chkconfig--listdrbd
drbd0:off1:off2:off3:off4:off5:off6:off
3、装置Mysql
1、装置Mysql并设置装备摆设
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
######在NOD1节点上装置Mysql
[root@nod1~]#mkdir/mydata
[root@nod1~]#mount/dev/drbd0/mydata/
[root@nod1~]#mkdir/mydata/data
[root@nod1~]#tarxfmysql-5.5.33-linux2.6-x86_64.tar.gz-C/usr/local/
[root@nod1~]#cd/usr/local/
[root@nod1local]#ln-smysql-5.5.33-linux2.6-x86_64mysql
[root@nod1local]#cdmysql
[root@nod1mysql]#cpsupport-files/my-large.cnf/etc/my.cnf
[root@nod1mysql]#cpsupport-files/mysql.server/etc/init.d/mysqld
[root@nod1mysql]#chmod+x/etc/init.d/mysqld
[root@nod1mysql]#chkconfig--addmysqld
[root@nod1mysql]#chkconfigmysqldoff
[root@nod1mysql]#vim/etc/my.cnf
datadir=/mydata/data
innodb_file_per_table=1
[root@nod1mysql]#echo"PATH=/usr/local/mysql/bin:$PATH">>/etc/profile
[root@nod1mysql]#./etc/profile
[root@nod1mysql]#useradd-r-u306mysql
[root@nod1mysql]#chownmysql.mysql-R/mydata
[root@nod1mysql]#chownroot.mysql*
[root@nod1mysql]#./scripts/mysql_install_db--user=mysql--datadir=/mydata/data/
[root@nod1mysql]#servicemysqldstart
StartingMySQL.....[OK]
[root@nod1mysql]#chkconfig--listmysqld
mysqld0:off1:off2:off3:off4:off5:off6:off
[root@nod1mysql]#servicemysqldstop
ShuttingdownMySQL.[OK]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
######在NOD2节点上装置Mysql
[root@nod2~]#scpnod1:/root/mysql-5.5.33-linux2.6-x86_64.tar.gz./
[root@nod2~]#mkdir/mydata
[root@nod2~]#tarxfmysql-5.5.33-linux2.6-x86_64.tar.gz-C/usr/local/
[root@nod2~]#cd/usr/local/
[root@nod2local]#ln-smysql-5.5.33-linux2.6-x86_64mysql
[root@nod2local]#cdmysql
[root@nod2mysql]#cpsupport-files/my-large.cnf/etc/my.cnf
######修正设置装备摆设文件添加以下设置装备摆设
[root@nod2mysql]#vim/etc/my.cnf
datadir=/mydata/data
innodb_file_per_table=1
[root@nod2mysql]#cpsupport-files/mysql.server/etc/init.d/mysqld
[root@nod2mysql]#chkconfig--addmysqld
[root@nod2mysql]#chkconfigmysqldoff
[root@nod2mysql]#useradd-r-u306mysql
[root@nod2mysql]#chown-Rroot.mysql*
2、卸载NOD1节点上的DRBD装备然后升级
1
2
3
4
5
6
[root@nod1~]#drbd-overview
0:drbd/0ConnectedPrimary/SecondaryUpToDate/UpToDateCr-----
[root@nod1~]#umount/mydata/
[root@nod1~]#drbdadmsecondarydrbd
[root@nod1~]#drbd-overview
0:drbd/0ConnectedSecondary/SecondaryUpToDate/UpToDateCr-----
3、在NOD2节点进级DBRD为主然后挂载DRBD装备
1
2
3
4
5
6
[root@nod2~]#drbd-overview
0:drbd/0ConnectedSecondary/SecondaryUpToDate/UpToDateCr-----
[root@nod2~]#drbdadmprimarydrbd
[root@nod2~]#drbd-overview
0:drbd/0ConnectedPrimary/SecondaryUpToDate/UpToDateCr-----
[root@nod2~]#mount/dev/drbd0/mydata/
4、在NOD2节点上启动Mysql办事停止测试
1
2
3
4
5
6
7
[root@nod2~]#chown-Rmysql.mysql/mydata
[root@nod2~]#servicemysqldstart
StartingMySQL..[OK]
[root@nod2~]#servicemysqldstop
ShuttingdownMySQL.[OK]
[root@nod2~]#chkconfig--listmysqld
mysqld0:off1:off2:off3:off4:off5:off6:off
5、将DRBD办事都设置为备用节点如:
1
2
3
[root@nod2~]#drbdadmsecondarydrbd
[root@nod2~]#drbd-overview
0:drbd/0ConnectedSecondary/SecondaryUpToDate/UpToDateCr-----
6、卸载DRBD装备并停滞NOD1与NOD2节点上的DRBD办事
<divid="highlighter_865738"class="syntaxhighlighterbashie">1
2
3 |
|