实现拓扑图:
实验流程:
-
先对两主机安装上corosync和pacemaker
-
两主机安装drbd服务,并且设置好drbd的组设备
-
选择drbd主节点上,进行数据库的初始化
-
进行资源的定义和配置
-
测试
实验前,我们还需要做一些准备工作:
1、时间必须保持同步
使用ntp服务器
2、节点必须名称互相通信
解析节点名称
/etc/host
集群中使用的主机名为`uname -n`表示的主机名;
3、ping node
仅偶数节点才需要;
4、ssh密钥认证进行通信;
实验步骤:
安装corosync和pacemaker:
yum install corosync pacemaker -y
配置corosync,同时让pacemaker在corosync以插件的方式运行:
vim /etc/corosync/corosync.conf compatibility: whitetank totem { version: 2 secauth: off threads: 0 interface { ringnumber: 0 bindnetaddr: 172.16.100.0 mcastaddr: 226.94.1.1 mcastport: 5405 ttl: 1 } } service { ver: 0 name: pacemaker } aisexec { user: root group: root } logging { fileline: off to_stderr: no 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 }
为corosync服务提供密钥文件:
corosync-keygen
然后,我们需要把这些配置都要往另一个主机上配置一次。
安装drbd,并且进行全局配置和配置drbd组资源的定义:
这里说明一下,我已经把分区准备好了,且容量一样,分区为/dev/sdb1
rpm -ivh drbd-8.4.3-33.el6.x86_64.rpm drbd-kmdl-2.6.32-431.el6-8.4.3-33.el6.x86_64.rpm(这个包的后缀要与你uanme -r的一致) vim /etc/drbd.d/global_common.conf 配置drbd全局配置文件 global { usage-count no; # minor-count dialog-refresh disable-ip-verification } common { protocol C; handlers { # These are EXAMPLE handlers only. # They may have severe implications, # like hard resetting the node under certain circumstances. # Be careful when chosing your poison. # local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f"; # fence-peer "/usr/lib/drbd/crm-fence-peer.sh"; # split-brain "/usr/lib/drbd/notify-split-brain.sh root"; # out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root"; # before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k"; # after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh; } startup { # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb } options { # cpu-mask on-no-data-accessible } disk { # size max-bio-bvecs on-io-error fencing disk-barrier disk-flushes # disk-drain md-flushes resync-rate resync-after al-extents # c-plan-ahead c-delay-target c-fill-target c-max-rate # c-min-rate disk-timeout on-io-error detach; } net { # protocol timeout max-epoch-size max-buffers unplug-watermark # connect-int ping-int sndbuf-size rcvbuf-size ko-count # allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri # after-sb-1pri after-sb-2pri always-asbp rr-conflict # ping-timeout data-integrity-alg tcp-cork on-congestion # congestion-fill congestion-extents csums-alg verify-alg # use-rle cram-hmac-alg "sha1"; shared-secret "mydrbdlab"; } syncer { rate 1000M; } } 配置drbd组资源的配置文件: vim /etc/drbd.d/mysqldata.res resource mysqldata { on www.bwei.com { device /dev/drbd0; disk /dev/sdb1; address 172.16.100.1:7789; meta-disk internal; } on www2.bwei.com { device /dev/drbd0; disk /dev/sdb1; address 172.16.100.5:7789; meta-disk internal; } } drbdadm create-md mysqldata 启动drbd服务: service drbd start 我们查看drbd的状态: [root@www drbd.d]# drbd-overview 0:mysqldata/0 Connected Secondary/Secondary Inconsistent/Inconsistent C r----- 我们把一个节点设置成主节点: [root@www drbd.d]# drbdadm -- --overwrite-data-of-peer primary mysqldata [root@www drbd.d]# drbd-overview 0:mysqldata/0 Connected Primary/Secondary UpToDate/UpToDate C r----- 把这个分区进行格式化: mke2fs -t ext4 /dev/drbd0 创建mysql的数据目录: mkdir /data mount /dev/drbd0 /data mkdir /data/mysql 提供mysql的用户和组,把数据目录的属主和属组改为mysql: [root@www ~]# groupadd -r mysql -g 360 [root@www ~]# useradd mysql -g mysql -u 360 -r [root@www ~]# chown mysql:mysql /data/mysql/ 接着,我们开始进行数据的初始化: [root@www ~]# tar xf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local/ [root@www local]# ln -sv mariadb-10.0.10-linux-x86_64 mysql `mysql' -> `mariadb-10.0.10-linux-x86_64' [root@www local]# mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/ [root@www local]# cp mysql/support-files/my-huge.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y [root@www local]# vim /etc/my.cnf [mysqld] datadir = /data/mysql [root@www local]# cp mysql/support-files/mysql.server /etc/init.d/mysqld [root@www local]# chkconfig --add mysqld [root@www local]# chkconfig mysqld off [root@www local]# service mysqld start Starting MySQL.. [ OK ] [root@www local]# mysql/bin/mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.0.10-MariaDB-log MariaDB Server Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> 我们的mysql已经做好了,注意另一个主机也是需要mysql的配置文件和启动脚本,不需要再进行mysql的初始化了。 下面我们需要安装crmsh进行资源配置文件的定义: rpm -ivh crmsh-1.2.6-4.el6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm service corosync start crm crm(live)# configure crm(live)configure# property no-quorum-policy=ignore crm(live)configure# property stonith-enabled=false crm(live)configure# verify crm(live)configure# commit crm(live)configure# primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysqldata op monitor interval=30 role=Master timeout=30 op monitor interval=40 role=Slave timeout=30 op start timeout=240 op stop timeout=100 crm(live)configure#primitive mysqlfs ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/data/mysql fstype=ext4 op start timeout=60 op stop timeout=60 crm(live)configure# primitive mysqld lsb:mysqld crm(live)configure# primitive mysqlvip ocf:heartbeat:IPaddr params ip=172.16.100.4 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# colocation mysqld_with_mysqlfs inf: mysqld mysqlfs crm(live)configure# crm(live)configure# crm(live)configure# order mysqlfs_after_ms_mysqldrbd inf: ms_mysqldrbd:promote mysqlfs:start crm(live)configure# order mysqld_after_mysqlfs inf: mysqlfs mysqld crm(live)configure# commit crm(live) status Last updated: Thu Nov 5 05:29:23 2015 Last change: Thu Nov 5 05:26:49 2015 via cibadmin on www.bwei.com Stack: classic openais (with plugin) Current DC: www2.bwei.com - partition with quorum Version: 1.1.10-14.el6-368c726 2 Nodes configured, 2 expected votes 5 Resources configured Online: [ www.bwei.com www2.bwei.com ] mysqlfs (ocf::heartbeat:Filesystem): Started www.bwei.com mysqlvip (ocf::heartbeat:IPaddr): Started www.bwei.com Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ www.bwei.com ] Slaves: [ www2.bwei.com ] mysqld (lsb:mysqld): Started www.bwei.com 这里看出,我们的服务已经配置完毕!!
原创文章,作者:13-广州-杨过,如若转载,请注明出处:http://www.178linux.com/9071
评论列表(1条)
不错,提升余地还有不少,加油