案例应用:红帽企业群集和存储管理之
mysql服务器的HA集群之corosync+drbd+pacemaker实现-上篇
下篇地址:
http://xjzhujunjie.blog.51cto.com/3582724/886323
案例应用企业需求:
案例应用拓扑图:
案例应用实现步骤:
一.准备工作:
1.1 修改node1.junjie.com主机名,IP地址和系统时间
[root@node1 ~]# hostname
node1.junjie.com
[root@node1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=node1.junjie.com
[root@node1 ~]# hwclock -s
[root@node1 ~]# date
Tue Feb 7 20:24:22 CST 2012
[root@node1 ~]#
[root@node1 ~]# setup
[root@node1 ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@node1 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:AE:83:D1
inet addr:192.168.101.81 Bcast:192.168.101.255 Mask:255.255.255.0
1.2 修改node2.junjie.com主机名,IP地址和系统时间
[root@node2 ~]# hostname
node2.junjie.com
[root@node2 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=node2.junjie.com
[root@node2 ~]# hwclock -s
[root@node2 ~]# date
Tue Feb 7 20:25:49 CST 2012
[root@node2 ~]#
[root@node2 ~]# setup
[root@node2 ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@node2 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:D1:D4:32
inet addr:192.168.101.82 Bcast:192.168.101.255 Mask:255.255.255.0
1.3 在node1和node2上配置hosts文件和ssh密钥信息
有利于以后在一个节点对另一节点直接操作。
1.3.1 在node1上修改/etc/hosts文件
[root@node1 ~]# echo "192.168.101.81 node1.junjie.com node1" >>/etc/hosts
[root@node1 ~]# echo "192.168.101.82 node2.junjie.com node2" >>/etc/hosts
1.3.1 在node1上修改/etc/hosts文件
[root@node2 ~]# echo "192.168.101.81 node1.junjie.com node1" >>/etc/hosts
[root@node2 ~]# echo "192.168.101.82 node2.junjie.com node2" >>/etc/hosts
1.3.3 在node1上配置ssh密钥信息
[root@node1 ~]# ssh-keygen -t rsa #一直输入空格
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2.junjie.com
1.3.4 在node2上配置ssh密钥信息
[root@node2 ~]# ssh-keygen -t rsa #一直输入空格
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1.junjie.com
[root@node2 ~]# ssh node1 'ifconfig' #将看到node2上的信息
The authenticity of host 'node1 (192.168.101.81)' can't be established.
RSA key fingerprint is d4:f1:06:3b:a0:81:fd:85:65:20:9e:a1:ee:46:a6:8b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node1' (RSA) to the list of known hosts.
eth0 Link encap:Ethernet HWaddr 00:0C:29:AE:83:D1
inet addr:192.168.101.81 Bcast:192.168.101.255 Mask:255.255.255.0
资源的下载地址:http://down.51cto.com/data/402802
[root@node1 ~]# cd ha/
[root@node1 ha]#
cluster-glue-1.0.6-1.6.el5.i386.rpm
cluster-glue-libs-1.0.6-1.6.el5.i386.rpm
corosync-1.2.7-1.1.el5.i386.rpm
corosynclib-1.2.7-1.1.el5.i386.rpm
drbd83-8.3.8-1.el5.centos.i386.rpm
heartbeat-3.0.3-2.3.el5.i386.rpm
heartbeat-libs-3.0.3-2.3.el5.i386.rpm
kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
ldirectord-1.0.1-1.el5.i386.rpm
libesmtp-1.0.4-5.el5.i386.rpm
mysql-5.5.15-linux2.6-i686.tar.gz
openais-1.1.3-1.6.el5.i386.rpm
openaislib-1.1.3-1.6.el5.i386.rpm
pacemaker-1.1.5-1.1.el5.i386.rpm
pacemaker-cts-1.1.5-1.1.el5.i386.rpm
pacemaker-libs-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
这里不需要ldirectord-1.0.1-1.el5.i386.rpm,故将其删除
[root@node1 ha]# rm ldirectord-1.0.1-1.el5.i386.rpm
rm: remove regular file `ldirectord-1.0.1-1.el5.i386.rpm'? y
[root@node1 ha]# ssh node2 'mkdir /root/ha'
[root@node1 ha]# scp *.rpm node2:/root/ha/#将相关软件包移动到node2上
[root@node1 ha]# scp *.rpm node2:/root/ha/
cluster-glue-1.0.6-1.6.el5.i386.rpm 100% 265KB 265.0KB/s 00:00
cluster-glue-libs-1.0.6-1.6.el5.i386.rpm 100% 130KB 130.1KB/s 00:00
corosync-1.2.7-1.1.el5.i386.rpm 100% 166KB 166.1KB/s 00:00
corosynclib-1.2.7-1.1.el5.i386.rpm 100% 155KB 154.8KB/s 00:00
drbd83-8.3.8-1.el5.centos.i386.rpm 100% 217KB 216.7KB/s 00:00
heartbeat-3.0.3-2.3.el5.i386.rpm 100% 162KB 161.7KB/s 00:00
heartbeat-libs-3.0.3-2.3.el5.i386.rpm 100% 283KB 282.8KB/s 00:00
kmod-drbd83-8.3.8-1.el5.centos.i686.rpm 100% 123KB 123.0KB/s 00:00
libesmtp-1.0.4-5.el5.i386.rpm 100% 59KB 59.0KB/s 00:00
openais-1.1.3-1.6.el5.i386.rpm 100% 202KB 202.2KB/s 00:00
openaislib-1.1.3-1.6.el5.i386.rpm 100% 92KB 92.4KB/s 00:00
pacemaker-1.1.5-1.1.el5.i386.rpm 100% 778KB 778.1KB/s 00:00
pacemaker-cts-1.1.5-1.1.el5.i386.rpm 100% 203KB 203.1KB/s 00:00
pacemaker-libs-1.1.5-1.1.el5.i386.rpm 100% 324KB 324.2KB/s 00:00
perl-TimeDate-1.16-5.el5.noarch.rpm 100% 32KB 32.1KB/s 00:00
resource-agents-1.0.4-1.1.el5.i386.rpm 100% 380KB 379.5KB/s 00:00
[root@node1 ha]# scp mysql-5.5.15-linux2.6-i686.tar.gz node2:/root/ha/
mysql-5.5.15-linux2.6-i686.tar.gz 100% 155MB 10.3MB/s 00:15
1.5 配置本地yum数据库
[root@node1 ha]#
[root@node1 ha]# mkdir /mnt/cdrom/
[root@node1 ha]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@node1 ha]# yum list all
[root@node1 ha]#
[root@node1 ha]# scp /etc/yum.repos.d/server.repo node2:/etc/yum.repos.d/
server.repo 100% 647 0.6KB/s 00:00
[root@node1 ha]#
[root@node1 ha]# ssh node2 'mkdir /mnt/cdrom/'
[root@node1 ha]# ssh node2 'mount /dev/cdrom /mnt/cdrom/'
[root@node1 ha]# ssh node2 'yum list all'
1.6 在node1上新增磁盘
[root@node1 ha]# cd
[root@node1 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
[root@node1 ~]# fdisk /dev/sda
p/n/p//+1000M/p/w
[root@node1 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
/dev/sda4 1580 1702 987997+ 83 Linux
[root@node1 ~]# partprobe /dev/sda
[root@node1 ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 104391 sda1
8 2 10482412 sda2
8 3 2096482 sda3
8 4 987997 sda4
[root@node1 ~]#
1.7 在node2上新增磁盘
[root@node2 ha]# cd
[root@node2 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
[root@node2 ~]# fdisk /dev/sda
p/n/p//+1000M/p/w
[root@node2 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
/dev/sda4 1580 1702 987997+ 83 Linux
[root@node2 ~]# partprobe /dev/sda
[root@node2 ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 104391 sda1
8 2 10482412 sda2
8 3 2096482 sda3
8 4 987997 sda4
[root@node2 ~]#
2.1、安装DRBD 套件
[root@node1 ~]# cd ha/
[root@node1 ha]# ls
[root@node1 ha]# yum localinstall -y drbd83-8.3.8-1.el5.centos.i386.rpm kmod-drbd83-8.3.8-1.el5.centos.i686.rpm –nogpgcheck
...
Installed:
drbd83.i386 0:8.3.8-1.el5.centos kmod-drbd83.i686 0:8.3.8-1.el5.centos
Complete!
[root@node1 ha]# cd
[root@node2 ~]# cd ha/
[root@node2 ha]# ls
[root@node2 ha]# yum localinstall -y drbd83-8.3.8-1.el5.centos.i386.rpm kmod-drbd83-8.3.8-1.el5.centos.i686.rpm –nogpgcheck
...
Installed:
drbd83.i386 0:8.3.8-1.el5.centos kmod-drbd83.i686 0:8.3.8-1.el5.centos
Complete!
[root@node2 ha]# cd
2.2、加载DRBD 模块
[root@node1 ~]# modprobe drbd
[root@node1 ~]# lsmod |grep drbd
drbd 228528 0
[root@node1 ~]#
[root@node1 ~]# ssh node2 'modprobe drbd'
[root@node1 ~]# ssh node2 'lsmod |grep drbd'
drbd 228528 0
[root@node1 ~]#
2.3、修改配置文件
drbd.conf配置文件DRBD运行时,会读取一个配置文件/etc/drbd.conf.这个文件里描述了DRBD设备与硬盘分区的映射关系
2.3.1 在node1上以下配置
[root@node1 ~]# cp /usr/share/doc/drbd83-8.3.8/drbd.conf /etc/
cp: overwrite `/etc/drbd.conf'? y
[root@node1 ~]# cat /etc/drbd.conf
# You can find an example in /usr/share/doc/drbd.../drbd.conf.example
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
[root@node1 ~]# cd /etc/drbd.d/
[root@node1 drbd.d]# ll
total 4
-rwxr-xr-x 1 root root 1418 Jun 4 2010 global_common.conf
[root@node1 drbd.d]# cp global_common.conf global_common.conf.bak
#修改全局配置文件(说明略)
[root@node1 drbd.d]# vim global_common.conf
global {
usage-count yes;
}
common {
protocol C;
handlers {
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /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; echo b > /proc/sysrq-trigger ; reboot -f";
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
}
startup {
wfc-timeout 120;
degr-wfc-timeout 100;
}
disk {
on-io-error detach;
}
net {
cram-hmac-alg "sha1";
shared-secret "mydrbd123";
}
syncer {
rate 100M;
}
}
#修改资源配置文件(说明略)
[root@node1 drbd.d]# vim /etc/drbd.d/mysql.res
resource mysql {
on node1.junjie.com {
device /dev/drbd0;
disk /dev/sda4;
address 192.168.101.81:7898;
meta-disk internal;
}
on node2.junjie.com {
device /dev/drbd0;
disk /dev/sda4;
address 192.168.101.82:7898;
meta-disk internal;
}
}
2.3.2 复制配置到node2上:
[root@node1 drbd.d]# scp /etc/drbd.conf node2:/etc/
drbd.conf 100% 133 0.1KB/s 00:00
[root@node1 drbd.d]# scp /etc/drbd.d/* node2:/etc/drbd.d/
global_common.conf 100% 682 0.7KB/s 00:00
global_common.conf.bak 100% 1418 1.4KB/s 00:00
mysql.res 100% 468 0.5KB/s 00:00
2.4、 检测配置文件, 创建nfs 的资源
//分别在node1和node2上初始化定义的mysql的资源
//检测配置文件(两次执行如下命令)
在node1上:
[root@node1 drbd.d]# drbdadm adjust mysql
--== Thank you for participating in the global usage survey ==--
The server's response is:
0: Failure: (119) No valid meta-data signature found.
==> Use 'drbdadm create-md res' to initialize meta-data area. <==
Command 'drbdsetup 0 disk /dev/sda4 /dev/sda4 internal --set-defaults --create-device --on-io-error=detach' terminated with exit code 10
[root@node1 drbd.d]# drbdadm adjust mysql
drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
[root@node1 drbd.d]# drbdadm create-md mysql
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@node1 drbd.d]# ll /dev/drbd0
brw-r----- 1 root disk 147, 0 Feb 7 20:44 /dev/drbd0
在node2上:
[root@node2 ~]# drbdadm create-md mysql
--== Thank you for participating in the global usage survey ==--
The server's response is:
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@node2 ~]# ll /dev/drbd0
brw-rw---- 1 root root 147, 0 Feb 7 20:47 /dev/drbd0
2.5 启动DRBD服务,查看DRBD状态
[root@node1 drbd.d]# service drbd start
Starting DRBD resources: [
mysql
Found valid meta data in the expected location, 1011703808 bytes into /dev/sda4.
d(mysql) s(mysql) n(mysql) ]......
[root@node2 ~]# service drbd start
Starting DRBD resources: [
mysql
Found valid meta data in the expected location, 1011703808 bytes into /dev/sda4.
d(mysql) s(mysql) n(mysql) ].
[root@node1 drbd.d]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res cs ro ds p mounted fstype
0:mysql Connected Secondary/Secondary Inconsistent/Inconsistent C
[root@node1 drbd.d]# drbd-overview
0:mysql Connected Secondary/Secondary Inconsistent/Inconsistent C r----
[root@node2 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res cs ro ds p mounted fstype
0:mysql Connected Secondary/Secondary Inconsistent/Inconsistent C
[root@node2 ~]# drbd-overview
0:mysql Connected Secondary/Secondary Inconsistent/Inconsistent C r----
2.6 设置DRBD的主节点:
从上面的信息中可以看出此时两个节点均处于Secondary状态。于是,我们接下来需要将其中一个节点设置为Primary,这里将node1设置为主节点,故要在node1上执行如下命令:可以看到文件同步过程。
[root@node1 drbd.d]# drbdadm -- --overwrite-data-of-peer primary mysql
[root@node1 drbd.d]# drbd-overview
0:mysql SyncSource Primary/Secondary UpToDate/Inconsistent C r----
[===>................] sync'ed: 23.6% (761048/987928)K delay_probe: 20
[root@node1 drbd.d]# drbd-overview
0:mysql SyncSource Primary/Secondary UpToDate/Inconsistent C r----
[========>...........] sync'ed: 47.6% (522296/987928)K delay_probe: 42
[root@node1 drbd.d]#
[root@node1 drbd.d]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node1 drbd.d]#
[root@node1 drbd.d]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
ns:987928 nr:0 dw:0 dr:987928 al:0 bm:61 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@node1 drbd.d]#
[root@node2 ~]# drbd-overview
0:mysql SyncTarget Secondary/Primary Inconsistent/UpToDate C r----
[=====>..............] sync'ed: 32.7% (670680/987928)K queue_delay: 0.1 ms
[root@node2 ~]# drbd-overview
0:mysql SyncTarget Secondary/Primary Inconsistent/UpToDate C r----
[===========>........] sync'ed: 61.6% (384536/987928)K queue_delay: 11.6 ms
[root@node2 ~]#
[root@node2 ~]# drbd-overview
0:mysql Connected Secondary/Primary UpToDate/UpToDate C r----
[root@node2 ~]#
[root@node2 ~]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r----
ns:0 nr:987928 dw:987928 dr:0 al:0 bm:61 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
注:Primary/Secondary 说明当前节点为主节点;Secondary/Primary 说明当前节点为从节点。使用:watch -n 1 'cat /proc/drbd'查看同步过程!
2.7 创建文件系统(只可以在primary节点上进行,这里在node1上创建)
[root@node1 drbd.d]# mkfs -t ext3 /dev/drbd0
[root@node1 drbd.d]# mkdir -pv /mnt/mysqldata
mkdir: created directory `/mnt/mysqldata'
[root@node1 drbd.d]# ssh node2 'mkdir -pv /mnt/mysqldata'
mkdir: created directory `/mnt/mysqldata'
[root@node1 drbd.d]# mount /dev/drbd0 /mnt/mysqldata/
[root@node1 drbd.d]#
[root@node1 drbd.d]# cd /mnt/mysqldata/
[root@node1 mysqldata]# ll
total 16
drwx------ 2 root root 16384 Feb 7 21:26 lost+found
[root@node1 mysqldata]# echo "123" >f1
[root@node1 mysqldata]# touch f2
[root@node1 mysqldata]# ll
total 20
-rw-r--r-- 1 root root 4 Feb 7 21:28 f1
-rw-r--r-- 1 root root 0 Feb 7 21:28 f2
drwx------ 2 root root 16384 Feb 7 21:26 lost+found
[root@node1 mysqldata]#
2.8将node2设置为primary节点
[root@node1 mysqldata]# cd
[root@node1 ~]# umount /mnt/mysqldata/
[root@node1 ~]# drbdadm secondary mysql
[root@node1 ~]# drbd-overview
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
[root@node1 ~]#
将node2设置为primary节点
[root@node2 ~]# drbd-overview
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]# drbdadm primary mysql
[root@node2 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]# mount /dev/drbd0 /mnt/mysqldata/
[root@node2 ~]# cd /mnt/mysqldata/
[root@node2 mysqldata]# ll
total 20
-rw-r--r-- 1 root root 4 Feb 7 21:28 f1
-rw-r--r-- 1 root root 0 Feb 7 21:28 f2
drwx------ 2 root root 16384 Feb 7 21:26 lost+found
此处看到在node1上创建的文件在这里都显示了,
最后将node2的/mnt/mysqldata/卸载
[root@node2 mysqldata]# cd
[root@node2 ~]# umount /mnt/mysqldata/
至此DRBD配置成功!!!
三、mysql安装与配置
3.1 将node1设为主节点,node2设为备份节点
[root@node2 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]# drbdadm secondary mysql
[root@node2 ~]# drbdadm role mysql
Secondary/Secondary
[root@node2 ~]# drbd-overview
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]#
[root@node1 ~]# drbd-overview
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
[root@node1 ~]# drbdadm primary mysql
[root@node1 ~]# drbdadm role mysql
Primary/Secondary
[root@node1 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node1 ~]#
3.2 在node1.junjie.com上安装配置mysql
[root@node1 ~]# groupadd -r mysql
[root@node1 ~]# useradd -g mysql -r mysql
[root@node1 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node1 ~]# mount /dev/drbd0 /mnt/mysqldata/
[root@node1 ~]# mkdir -pv /mnt/mysqldata/data
mkdir: created directory `/mnt/mysqldata/data'
[root@node1 ~]# chown -R mysql.mysql /mnt/mysqldata/data/
[root@node1 ~]# ll /mnt/mysqldata/
total 24
drwxr-xr-x 2 mysql mysql 4096 Feb 7 21:48 data
-rw-r--r-- 1 root root 4 Feb 7 21:28 f1
-rw-r--r-- 1 root root 0 Feb 7 21:28 f2
drwx------ 2 root root 16384 Feb 7 21:26 lost+found
[root@node1 ~]#cd ha/
[root@node1 ha]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/
[root@node1 ~]# cd /usr/local/
[root@node1 src]# ln -sv mysql-5.5.15-linux2.6-i686/ mysql
create symbolic link `mysql' to `mysql-5.5.15-linux2.6-i686/'
[root@node1 src]# ll
[root@node1 src]# cd mysql
[root@node1 mysql]# chown -R mysql:mysql .
[root@node1 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mnt/mysqldata/data/
[root@node1 mysql]# chown -R root .
[root@node1 mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@node1 mysql]# vim /etc/my.cnf
39 thread_concurrency = 2
40 datadir = /mnt/mysqldata/data/ #指定mysql数据文件的存放位置(添加)
为mysql提供sysv服务脚本,使其能使用service命令:
[root@node1 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@node1 mysql]# scp /etc/my.cnf node2:/etc/
my.cnf 100% 4696 4.6KB/s 00:00
[root@node1 mysql]# scp /etc/rc.d/init.d/mysqld node2:/etc/rc.d/init.d/
mysqld 100% 10KB 10.4KB/s 00:00
[root@node1 mysql]#
[root@node1 mysql]# chkconfig --add mysqld
[root@node1 mysql]# chkconfig mysqld off
[root@node1 mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@node1 mysql]# service mysqld start
Starting MySQL..... [ OK ]
[root@node1 mysql]# l1 /mnt/mysqldata/data/
total 28744
-rw-rw---- 1 mysql mysql 5242880 Feb 7 22:00 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Feb 7 21:59 ib_logfile1
-rw-rw---- 1 mysql mysql 18874368 Feb 7 22:00 ibdata1
drwx------ 2 mysql root 4096 Feb 7 21:53 mysql
-rw-rw---- 1 mysql mysql 126 Feb 7 22:00 mysql-bin.000001
-rw-rw---- 1 mysql mysql 19 Feb 7 21:59 mysql-bin.index
-rw-rw---- 1 mysql root 2127 Feb 7 22:00 node1.junjie.com.err
drwx------ 2 mysql mysql 4096 Feb 7 21:53 performance_schema
drwx------ 2 mysql root 4096 Feb 7 21:53 test
[root@node1 mysql]# service mysqld stop
Shutting down MySQL. [ OK ]
[root@node1 mysql]#
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
输出mysql的man手册至man命令的查找路径:添加如下行即可:
[root@node1 mysql]# vim /etc/man.config
48行添加 MANPATH /usr/local/mysql/man
输出mysql的头文件至系统头文件路径/usr/include,这可以通过简单的创建链接实现:
[root@node1 mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include'
[root@node1 mysql]#
输出mysql的库文件给系统库查找路径:(文件只要是在/etc/ld.so.conf.d/下并且后缀是.conf就可以)而后让系统重新载入系统库
[root@node1 mysql]# echo '/usr/local/mysql/lib' >> /etc/ld.so.conf.d/mysql.conf
[root@node1 mysql]# ldconfig -v |grep mysql
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
修改PATH环境变量,让系统所有用户可以直接使用mysql的相关命令:
[root@node1 mysql]# vim /etc/profile
59 PATH=$PATH:/usr/local/mysql/bin #添加
[root@node1 mysql]# . /etc/profile
[root@node1 mysql]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
卸载drbd设备:
[root@node1 mysql]# umount /mnt/mysqldata/
3.3 将node2设为主节点,node1设为备份节点
[root@node1 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node1 ~]# drbdadm secondary mysql
[root@node1 ~]# drbdadm role mysql
Secondary/Secondary
[root@node1 ~]# drbd-overview
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
[root@node1 ~]#
[root@node2 ~]# drbd-overview
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]# drbdadm primary mysql
[root@node2 ~]# drbdadm role mysql
Primary/Secondary
[root@node2 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]#
3.4 在node2.junjie.com上安装配置mysql
添加用户和组:
[root@node2 ~]# groupadd -r mysql
[root@node2 ~]# useradd -g mysql -r mysql
[root@node2 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]#
挂载drbd设备:
[root@node2 ~]# mount /dev/drbd0 /mnt/mysqldata/
[root@node2 ~]# ll /mnt/mysqldata/
total 24
drwxr-xr-x 5 mysql mysql 4096 Feb 7 22:00 data
-rw-r--r-- 1 root root 4 Feb 7 21:28 f1
-rw-r--r-- 1 root root 0 Feb 7 21:28 f2
drwx------ 2 root root 16384 Feb 7 21:26 lost+found
[root@node2 ~]# ll /mnt/mysqldata/data/
total 28744
-rw-rw---- 1 mysql mysql 5242880 Feb 7 22:00 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Feb 7 21:59 ib_logfile1
-rw-rw---- 1 mysql mysql 18874368 Feb 7 22:00 ibdata1
drwx------ 2 mysql root 4096 Feb 7 21:53 mysql
-rw-rw---- 1 mysql mysql 126 Feb 7 22:00 mysql-bin.000001
-rw-rw---- 1 mysql mysql 19 Feb 7 21:59 mysql-bin.index
-rw-rw---- 1 mysql root 2127 Feb 7 22:00 node1.junjie.com.err
drwx------ 2 mysql mysql 4096 Feb 7 21:53 performance_schema
drwx------ 2 mysql root 4096 Feb 7 21:53 test
[root@node2 ~]#
安装mysql:
[root@node2 ~]# cd ha/
[root@node2 ha]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/
[root@node2 ha]# cd /usr/local/
[root@node2 local]# ln -sv mysql-5.5.15-linux2.6-i686/ mysql
create symbolic link `mysql' to `mysql-5.5.15-linux2.6-i686/'
[root@node2 local]# cd mysql
一定不能对数据库进行初始化,因为我们在node1上已经初始化了:
[root@node2 mysql]# chown -R root:mysql .
mysql主配置文件和sysc服务脚本已经从node1复制过来了,不用在添加。
管理mysql服务:
[root@node2 mysql]# chkconfig --add mysqld
[root@node2 mysql]# chkconfig mysqld off
[root@node2 mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@node2 mysql]#
启动mysql服务:
[root@node2 mysql]# service mysqld start
Starting MySQL....... [ OK ]
[root@node2 mysql]# ll /mnt/mysqldata/data/
total 28756
-rw-rw---- 1 mysql mysql 5242880 Feb 7 22:29 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Feb 7 21:59 ib_logfile1
-rw-rw---- 1 mysql mysql 18874368 Feb 7 22:00 ibdata1
drwx------ 2 mysql root 4096 Feb 7 21:53 mysql
-rw-rw---- 1 mysql mysql 126 Feb 7 22:00 mysql-bin.000001
-rw-rw---- 1 mysql mysql 107 Feb 7 22:29 mysql-bin.000002
-rw-rw---- 1 mysql mysql 38 Feb 7 22:29 mysql-bin.index
-rw-rw---- 1 mysql root 2127 Feb 7 22:00 node1.junjie.com.err
-rw-rw---- 1 mysql root 941 Feb 7 22:29 node2.junjie.com.err
-rw-rw---- 1 mysql mysql 5 Feb 7 22:29 node2.junjie.com.pid
drwx------ 2 mysql mysql 4096 Feb 7 21:53 performance_schema
drwx------ 2 mysql root 4096 Feb 7 21:53 test
测试之后关闭服务:
[root@node2 mysql]# service mysqld stop
Shutting down MySQL. [ OK ]
[root@node2 mysql]#
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
输出mysql的man手册至man命令的查找路径:添加如下行即可:
[root@node2 mysql]# vim /etc/man.config
48行添加 MANPATH /usr/local/mysql/man
输出mysql的头文件至系统头文件路径/usr/include,这可以通过简单的创建链接实现:
[root@node2 mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include'
[root@node2 mysql]#
输出mysql的库文件给系统库查找路径:(文件只要是在/etc/ld.so.conf.d/下并且后缀是.conf就可以)而后让系统重新载入系统库
[root@node2 mysql]# echo '/usr/local/mysql/lib' >> /etc/ld.so.conf.d/mysql.conf
[root@node2 mysql]# ldconfig -v |grep mysql
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
修改PATH环境变量,让系统所有用户可以直接使用mysql的相关命令:
[root@node2 mysql]# vim /etc/profile
59 PATH=$PATH:/usr/local/mysql/bin #添加
[root@node2 mysql]# . /etc/profile
[root@node2 mysql]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
卸载drbd设备:
[root@node2 mysql]# umount /mnt/mysqldata/
四、corosync+pacemaker的安装和配置
4.1安装有关软件
[root@node1 ~]# cd ha/
[root@node1 ha]# yum localinstall -y *.rpm --nogpgcheck
…
Installed:
cluster-glue.i386 0:1.0.6-1.6.el5 cluster-glue-libs.i386 0:1.0.6-1.6.el5
corosync.i386 0:1.2.7-1.1.el5 corosynclib.i386 0:1.2.7-1.1.el5
heartbeat.i386 0:3.0.3-2.3.el5 heartbeat-libs.i386 0:3.0.3-2.3.el5
libesmtp.i386 0:1.0.4-5.el5 openais.i386 0:1.1.3-1.6.el5
openaislib.i386 0:1.1.3-1.6.el5 pacemaker.i386 0:1.1.5-1.1.el5
pacemaker-cts.i386 0:1.1.5-1.1.el5 pacemaker-libs.i386 0:1.1.5-1.1.el5
perl-TimeDate.noarch 1:1.16-5.el5 resource-agents.i386 0:1.0.4-1.1.el5
Dependency Installed:
libibverbs.i386 0:1.1.2-4.el5 librdmacm.i386 0:1.0.8-5.el5
libtool-ltdl.i386 0:1.5.22-6.1 lm_sensors.i386 0:2.10.7-4.el5
openhpi-libs.i386 0:2.14.0-5.el5 openib.noarch 0:1.4.1-3.el5
Complete!
[root@node1 ha]#
[root@node2 ~]# cd ha/
[root@node2 ha]# yum localinstall -y *.rpm --nogpgcheck
…
Installed:
cluster-glue.i386 0:1.0.6-1.6.el5 cluster-glue-libs.i386 0:1.0.6-1.6.el5
corosync.i386 0:1.2.7-1.1.el5 corosynclib.i386 0:1.2.7-1.1.el5
heartbeat.i386 0:3.0.3-2.3.el5 heartbeat-libs.i386 0:3.0.3-2.3.el5
libesmtp.i386 0:1.0.4-5.el5 openais.i386 0:1.1.3-1.6.el5
openaislib.i386 0:1.1.3-1.6.el5 pacemaker.i386 0:1.1.5-1.1.el5
pacemaker-cts.i386 0:1.1.5-1.1.el5 pacemaker-libs.i386 0:1.1.5-1.1.el5
perl-TimeDate.noarch 1:1.16-5.el5 resource-agents.i386 0:1.0.4-1.1.el5
Dependency Installed:
libibverbs.i386 0:1.1.2-4.el5 librdmacm.i386 0:1.0.8-5.el5
libtool-ltdl.i386 0:1.5.22-6.1 lm_sensors.i386 0:2.10.7-4.el5
openhpi-libs.i386 0:2.14.0-5.el5 openib.noarch 0:1.4.1-3.el5
Complete!
[root@node2 ha]#
4.2 对node1和node2节点进行相应的配置
1:切换到主配置文件的目录
[root@node1 ha]# cd /etc/corosync/
[root@node1 corosync]# ll
total 20
-rw-r--r-- 1 root root 5384 Jul 28 2010 amf.conf.example
-rw-r--r-- 1 root root 436 Jul 28 2010 corosync.conf.example
drwxr-xr-x 2 root root 4096 Jul 28 2010 service.d
drwxr-xr-x 2 root root 4096 Jul 28 2010 uidgid.d
[root@node1 corosync]# cp corosync.conf.example corosync.conf
[root@node1 corosync]# vim corosync.conf
10 bindnetaddr: 192.168.101.0 #修改此行
#添加以下几行
33 service {
34 ver: 0
35 name: pacemaker
36 use_mgmtd: yes
37 }
38 aisexec {
39 user: root
40 group: root
41 }
2:创建cluster目录
[root@node1 corosync]# mkdir -pv /var/log/cluster
mkdir: created directory `/var/log/cluster'
3:为了便面其他主机加入该集群,需要认证,生成一authkey
[root@node1 corosync]# corosync-keygen
Corosync Cluster Engine Authentication key generator.
Gathering 1024 bits for key from /dev/random.
Press keys on your keyboard to generate entropy.
Writing corosync key to /etc/corosync/authkey.
[root@node1 corosync]# ll
total 28
-rw-r--r-- 1 root root 5384 Jul 28 2010 amf.conf.example
-r-------- 1 root root 128 Feb 7 22:47 authkey
-rw-r--r-- 1 root root 555 Feb 7 22:45 corosync.conf
-rw-r--r-- 1 root root 436 Jul 28 2010 corosync.conf.example
drwxr-xr-x 2 root root 4096 Jul 28 2010 service.d
drwxr-xr-x 2 root root 4096 Jul 28 2010 uidgid.d
[root@node1 corosync]#
4:将node1节点上的文件拷贝到节点node2上面(记住要带-p)
[root@node1 corosync]# scp -p authkey corosync.conf node2:/etc/corosync/
authkey 100% 128 0.1KB/s 00:00
corosync.conf 100% 561 0.6KB/s 00:00
[root@node1 corosync]# ssh node2 'mkdir -pv /var/log/cluster'
mkdir: created directory `/var/log/cluster'
[root@node1 corosync]#
4.3 在node1和node2节点上检测
1:在node1和node2节点上面启动 corosync 的服务
[root@node1 corosync]# service corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
[root@node1 corosync]# ssh node2 'service corosync start'
Starting Corosync Cluster Engine (corosync): [ OK ]
[root@node1 corosync]#
2:在node1上验证corosync引擎是否正常启动了
[root@node1 ~]# grep -i -e "corosync cluster engine" -e "configuration file" /var/log/messages
Feb 7 22:51:41 node1 corosync[5149]: [MAIN ] Corosync Cluster Engine ('1.2.7'): started and ready to provide service.
Feb 7 22:51:41 node1 corosync[5149]: [MAIN ] Successfully read main configuration file '/etc/corosync/corosync.conf'.
3: 在node1上查看初始化成员节点通知是否发出
[root@node1 ~]# grep -i totem /var/log/messages
Feb 7 22:51:41 node1 corosync[5149]: [TOTEM ] Initializing transport (UDP/IP).
Feb 7 22:51:41 node1 corosync[5149]: [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Feb 7 22:51:42 node1 corosync[5149]: [TOTEM ] The network interface [192.168.101.81] is now up.
Feb 7 22:51:42 node1 corosync[5149]: [TOTEM ] A processor joined or left the membership and a new membership was formed.
4: 在node1上检查过程中是否有错误产生(避免stonith的错误)
[root@node1 ~]# grep -i error: /var/log/messages |grep -v unpack_resources
出现如下1个错误:
Feb 7 22:51:43 node1 corosync[5149]: [pcmk ] ERROR: pcmk_wait_dispatch: Child process mgmtd exited (pid=5161, rc=100)此处
解决方法:
仔细看了/var/log/messages日志,或者使用crm_verify -L检查一下错误,其实没必要卸载重装。这个错误是由于缺少snoith设备引起的,并不会影响corosync的运行。可以忽略这个错误。
[root@node1 corosync]# crm_verify -L
crm_verify[5247]: 2012/02/07_23:09:37 ERROR: unpack_resources: Resource start-up disabled since no STONITH resources have been defined
crm_verify[5247]: 2012/02/07_23:09:37 ERROR: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option
crm_verify[5247]: 2012/02/07_23:09:37 ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
-V may provide more details
[root@node1 corosync]#
5: 在node1上检查pacemaker时候已经启动了?(如下显示正常启动)
[root@node1 ~]# grep -i pcmk_startup /var/log/messages
Feb 7 22:51:42 node1 corosync[5149]: [pcmk ] info: pcmk_startup: CRM: Initialized
Feb 7 22:51:42 node1 corosync[5149]: [pcmk ] Logging: Initialized pcmk_startup
Feb 7 22:51:42 node1 corosync[5149]: [pcmk ] info: pcmk_startup: Maximum core file size is: 4294967295
Feb 7 22:51:42 node1 corosync[5149]: [pcmk ] info: pcmk_startup: Service: 9
Feb 7 22:51:42 node1 corosync[5149]: [pcmk ] info: pcmk_startup: Local hostname: node1.junjie.com
6: 在node2上验证corosync引擎是否正常启动了
[root@node2 ~]# grep -i -e "corosync cluster engine" -e "configuration file" /var/log/messages
Feb 7 22:53:01 node2 corosync[5246]: [MAIN ] Corosync Cluster Engine ('1.2.7'): started and ready to provide service.
Feb 7 22:53:01 node2 corosync[5246]: [MAIN ] Successfully read main configuration file '/etc/corosync/corosync.conf'.
7: 在node2上查看初始化成员节点通知是否发出
[root@node2 ~]# grep -i totem /var/log/messages
Feb 7 22:53:01 node2 corosync[5246]: [TOTEM ] Initializing transport (UDP/IP).
Feb 7 22:53:01 node2 corosync[5246]: [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Feb 7 22:53:02 node2 corosync[5246]: [TOTEM ] The network interface [192.168.101.82] is now up.
Feb 7 22:53:02 node2 corosync[5246]: [TOTEM ] A processor joined or left the membership and a new membership was formed.
Feb 7 22:53:03 node2 corosync[5246]: [TOTEM ] A processor joined or left the membership and a new membership was formed.
8: 在node2上检查过程中是否有错误产生(避免stonith的错误,如下显示只有stonith错误,可忽略)
[root@node2 ~]# grep -i error: /var/log/messages |grep -v unpack_resources
Feb 7 22:53:03 node2 corosync[5246]: [pcmk ] ERROR: pcmk_wait_dispatch: Child process mgmtd exited (pid=5258, rc=100)
9: 在node2上检查pacemaker时候已经启动了?(如下显示正常启动)
[root@node2 ~]# grep -i pcmk_startup /var/log/messages
[root@node2 ~]# grep -i pcmk_startup /var/log/messages
Feb 7 22:53:02 node2 corosync[5246]: [pcmk ] info: pcmk_startup: CRM: Initialized
Feb 7 22:53:02 node2 corosync[5246]: [pcmk ] Logging: Initialized pcmk_startup
Feb 7 22:53:02 node2 corosync[5246]: [pcmk ] info: pcmk_startup: Maximum core file size is: 4294967295
Feb 7 22:53:02 node2 corosync[5246]: [pcmk ] info: pcmk_startup: Service: 9
Feb 7 22:53:02 node2 corosync[5246]: [pcmk ] info: pcmk_startup: Local hostname: node2.junjie.com
10: 在node1和node2上查看群集的状态
[root@node1 corosync]# crm status
============
Last updated: Tue Feb 7 23:18:39 2012
Stack: openais
Current DC: node1.junjie.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
0 Resources configured.
============
Online: [ node2.junjie.com node1.junjie.com ]
[root@node1 corosync]#
[root@node2 corosync]# crm status
============
Last updated: Tue Feb 7 23:20:06 2012
Stack: openais
Current DC: node1.junjie.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
0 Resources configured.
============
Online: [ node2.junjie.com node1.junjie.com ]
[root@node2 corosync]#
五.群集管理
5.1 配置群集的工作属性
未完,请见下篇博文!
下篇地址:
http://xjzhujunjie.blog.51cto.com/3582724/886323
本文转自xjzhujunjie 51CTO博客,原文链接:http://blog.51cto.com/xjzhujunjie/886317