精品国产一级在线观看,国产成人综合久久精品亚洲,免费一级欧美大片在线观看

通過HA實現服務器的高可用性-上篇

責任編輯:vivian

2012-06-06 09:36:38

摘自:服務器在線

輸出mysql的庫文件給系統庫查找路徑:(文件只要是在/etc/ld.so.conf.d/下并且后綴是.conf就可以)而后讓系統重新載入系統庫 

案例應用企業需求:

某公司需要通過HA實現服務器的高可用性,即通過corosync+drbd+pacemaker實現mysql服務器的高可用集群。

案例應用拓撲圖:

案例應用實現步驟:

一.準備工作:

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 [email protected]

1.3.4 在node2上配置ssh密鑰信息

[root@node2 ~]# ssh-keygen -t rsa #一直輸入空格

[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]

[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

1.4 下載相關軟件包:(這里我將下載的軟件包放在/root/ha/下面了,共18個)

資源的下載地址: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 ~]#

二、DRBD安裝配置步驟

在node1和node2做以下操作:

我下載的軟件包是:(我放在/root/ha/下了)

drbd83-8.3.8-1.el5.centos.i386.rpm

kmod-drbd83-8.3.8-1.el5.centos.i686.rpm

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 [email protected], 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 [email protected], 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 [email protected], 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 [email protected], 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 配置群集的工作屬性

鏈接已復制,快去分享吧

企業網版權所有?2010-2024 京ICP備09108050號-6京公網安備 11010502049343號

  • <menuitem id="jw4sk"></menuitem>

    1. <form id="jw4sk"><tbody id="jw4sk"><dfn id="jw4sk"></dfn></tbody></form>
      主站蜘蛛池模板: 中江县| 鄱阳县| 荔浦县| 包头市| 方山县| 临沧市| 汝州市| 柏乡县| 和林格尔县| 磴口县| 特克斯县| 龙游县| 昆山市| 武乡县| 吴堡县| 若尔盖县| 聂拉木县| 连云港市| 麻栗坡县| 江西省| 比如县| 高密市| 定州市| 南康市| 岑溪市| 沾益县| 娄烦县| 曲阜市| 海原县| 黄平县| 阜康市| 尚义县| 沈阳市| 海安县| 北安市| 石渠县| 绩溪县| 日喀则市| 榆树市| 盐边县| 合肥市|