您好,欢迎来到刀刀网。
搜索
您的当前位置:首页DRBD+HEARTBEAT+MYSQL安装配置及测试 V 1.0

DRBD+HEARTBEAT+MYSQL安装配置及测试 V 1.0

来源:刀刀网


DRBD+HEARTBEAT+MYSQL安装配置及测试 V 1.0

测试环境:

OS:CentOS 5.4 i386 (vmware下运行) 内核版本:2.6.18-1.el5

(uname -a 查看现运行的内核版本)

内核源码路径:/usr/src/kernels/2.6.18-1.el5-i686/ Mysql 5.1.34

heartbeat-3.0.3-2.3 drbd-8.2.5

(现运行内核版本和系统原带内核路径必须一致) Server01 : eth0 192.168.0.136 eth1 10.0.0.10 Server02 : eth0 192.168.0.137 eth1 10.0.0.11 VIP : 192.168.0.141

一.下载源代码,推荐使用源代码。

因为使用yum 安装时 在安装kmod-drbd组件是会升级内核,这会导致无法加载drbd模块到内核,(此问题我还没解决)

Yum 安装命令 # yum install drbd kmod-drbd 源码下载地址:http://oss.linbit.com/drbd/

# wget http://oss.linbit.com/drbd/8.2/drbd-8.2.5.tar.gz # tar xvf drbd-8.2.5.tar.gz # cd drbd-8.2.5

# make KDIR=/usr/src/kernels/2.6.18-1.el5-i686/

# make install KDIR=/usr/src/kernels/2.6.18-1.el5-i686/ 这样就算安装完毕了。

检查一下需要有drbd 、drbdadm、drbdmeta 、drbdsetup这四个命令、以及启动脚本:/etc/init.d/drbd

并保证drbd模块已经加载到内核中了 #lsmod | grep drbd󰀀

drbd 193796 3 主配置文件在:/etc/drbd.conf 将drbd服务加入到启动项中 # chkconfig drbd on 二.配置环境

以上操作在server01 和 server02中进行,

2个主机都预留一个空白的分区,不需要创建任何文件系统。 在server01中 vim /etc/hosts

127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.0.136 server01 192.168.0.137 server02

并保证 vim /etc/sysconfig/network NETWORKING=yes

NETWORKING_IPV6=no HOSTNAME=server01 在server02中 vim /etc/hosts

127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.0.136 server01 192.168.0.137 server02

并保证 vim /etc/sysconfig/network NETWORKING=yes

NETWORKING_IPV6=no HOSTNAME=server02 主配置文件内容: # vim /etc/drbd.conf

# 是否参加DRBD使用者统计.默认是yes global { usage-count yes;}

# 设置主备节点同步时的网络速率最大值,单位是字节. common { syncer { rate 10M; } }

# 一个DRBD设备(即:/dev/drbdX),叫做一个\"资源\".里面包含一个DRBD设备的主备节点的

# 相关信息. #

resource r0 {

# 使用协议C.表示收到远程主机的写入确认后,则认为写入完成. protocol C;

#startup { wfc-timeout 0; degr-wfc-timeout 120; } disk { on-io-error detach; } syncer { rate 10M; } net {

# 设置主备机之间通信使用的信息算法. cram-hmac-alg sha1;

shared-secret \"FooFunFactory\"; }

# 每个主机的说明以\"on\"开头,后面是主机名.在后面的{}中为这个主机的配置. on server01{

# /dev/drbd1使用的磁盘分区是/dev/hdb1 device /dev/drbd1; disk /dev/sdc5;

# 设置DRBD的监听端口,用于与另一台主机通信 address 192.168.0.136:78; #address 10.0.0.194:78;

#meta-disk /dev/xvdb5[0]; meta-disk internal;

#flexible-meta-disk internal; }

on server02 {

device /dev/drbd1; disk /dev/sdb5;

address 192.168.0.137:78; #address 10.0.0.195:78; meta-disk internal;

#meta-disk /dev/xvdb5[0]; #flexible-meta-disk internal; }

}

准备启动之前,需要分别在2个主机上的 空白分区上创建相应的元数据保存的数据块: 常见之前现将两块空白分区彻底清除数据 分别在两个主机上执行

#dd if=/dev/zero of=/dev/sdbX bs=1M count=128 否则下一步会出现 .........

Device size would be truncated, which would corrupt data and result in 'access beyond end of device' errors. You need to either

* use external meta data (recommended) * shrink that filesystem first

* zero out the device (destroy the filesystem) Operation refused. ..........

分别在server01和server02上面执行 #drbdadm create-md r0

确保成功后,接下来就可以启动drbd进程了(在server01和server02同时启用): 在server02中

[root@server01 ~]# /etc/init.d/drbd start

Starting DRBD resources: [ d(r0) s(r0) n(r0) ].

[root@server01 ~]# ps aux | grep drbd

root 5777 0.0 0.0 0 0 ? S 11:12 0:00 [drbd1_worker]

root 5780 0.0 0.0 0 0 ? S 11:12 0:00 [drbd1_receiver] root 5790 0.0 0.0 0 0 ? S 11:12 0:00 [drbd1_asender]

[root@server01 ~]# cat /proc/drbd version: 8.2.5 (api:88/proto:86-88)

GIT-hash: 9faf052fdae5ef0c61b4d030e2d2eab550610c build by root@server01, 2011-12-02 10:00:19

1: cs:Connected st:Secondary/Secondary ds:Inconsistent/UpToDate C r--- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0

resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0 act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0 在server02上

[root@server02 /]# /etc/init.d/drbd start

Starting DRBD resources: [ d(r0) s(r0) n(r0) ].

[root@server02 ~]# ps aux |grep drbd

root 4465 0.0 0.0 0 0 ? S 10:45 0:00 [drbd1_worker] root 4466 0.0 0.0 0 0 ? S 10:45 0:00 [drbd1_receiver] root 5284 0.0 0.0 0 0 ? S 11:12 0:00 [drbd1_asender]

[root@server02 ~]# cat /proc/drbd version: 8.2.5 (api:88/proto:86-88)

GIT-hash: 9faf052fdae5ef0c61b4d030e2d2eab550610c build by root@server02, 2011-12-02 09:56:19

1: cs:Connected st:Primary/Secondary ds:UpToDate/Inconsistent C r--- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0

resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0 act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0 三.启动server01为主节点

#drbdadm primary r0 这一步可能会报错误 如果保持执行

drbdsetup /dev/drbd1 primary –o󰀀

可以看到,第一次设置主节点时用 drbdadm 命令会失败,所以先用drbdsetup 来做,以后就可以用 drbdadm 了 成功后,就可以使用

#cat /proc/drbd 查看同步的进度了

[root@server01 ~]# cat /proc/drbd version: 8.2.5 (api:88/proto:86-88)

GIT-hash: 9faf052fdae5ef0c61b4d030e2d2eab550610c build by root@server01, 2011-12-02 10:00:19

1: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r--- ns:1830912 nr:0 dw:0 dr:1830912 al:0 bm:111 lo:0 pe:0 ua:0 ap:0 [======>.............] sync'ed: 35.1% (3326/5114)M finish: 0:04:43 speed: 11,940 (10,344) K/sec

resync: used:0/31 hits:114320 misses:112 starving:0 dirty:0 changed:112 act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0

同步完毕:

此过程有点慢,(我测试的 512M内存,intel E2220 vmware 7.14 环境,5G的磁盘同步了16分钟)

同步完毕之后,就可以对空白磁盘格式化了 (注意此操作只对primary节点格式化) [root@server01 ~]# mkfs.ext3 /dev/drbd1 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux

Block size=4096 (log=2) Fragment size=4096 (log=2) 655360 inodes, 1309232 blocks

65461 blocks (5.00%) reserved for the super user First data block=0

Maximum filesystem blocks=1342177280 40 block groups

32768 blocks per group, 32768 fragments per group 16384 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

然后将格式化好的磁盘挂在到 /drbd 下

测试:

现在演示一下主节点挂掉,然后重新恢复连接的情况,通过以上的设置我们知道 server01(192.168.0.136)为primary节点 [root@server01 ~]# ifdown eth0

可以看到,在primary节点上找不到secondary节点了。再来看看secondary节点上的状态:

在secondary节点上也找不到primary了 现在,让prmary节点的网卡启动

还是未连接状态。

在刚才关闭网卡的primary节点上执行如下命令:

可以看到主节点已经连接到了 secondary节点

同样去secondary节点server02上使用cat命令查看一下连接情况

查看连接情况可以直接使用

[root@server01 ~]# drbdadm state r0 Primary/Secondary

[root@server01 ~]# drbdadm cstate r0 Connected

[root@server01 ~]# drbdadm dstate r0 UpToDate/UpToDate 同样可以使用常用命令

[root@server01 ~]# service drbd status drbd driver loaded OK; device status: version: 8.2.5 (api:88/proto:86-88)

GIT-hash: 9faf052fdae5ef0c61b4d030e2d2eab550610c build by root@server01, 2011-12-02 10:00:19

m:res cs st ds p mounted fstype 1:r0 Connected Primary/Secondary UpToDate/UpToDate C /drbd ext3

如果是secondary节点挂掉了,它恢复正常后,想要再次连接primary节点的话,考虑到可能会有数据丢失,可以采用以下方式来连接:

[root@server02 ~]# drbdadmin -- --discard-my-data connect 󰀀 r0

它告诉drbd,secondary节点上的数据可能是不正确的,要以primary节点上的为准。这个命令只能在secondary节点上使用,毕竟数据是以primary节点为准的,而非secondry节点。 不过,如果是primary节点挂掉了,这个时候就应该把原来的secondary节点提升为primary的角色,等原来的primary恢复之后,只能先降级成为secondary节点了,否则是无法再次正确连接另一个节点的。 同步结果测试

在server01上做如下操作;

[root@server01 home]# cp mysql-5.1.60.tar.gz /drbd/ [root@server01 home]# ls /drbd/ lost+found mysql-5.1.60.tar.gz

然后,我们把primary降级成secondary,把secondary提升成primary 注意:把primary降级前,一定要先umount设备才行。

然后提升secondary:

可以看在server01上写入的文件mysql-5.1.60.tar.gz已经同步到server02上。 测试成功!

切换回到之前的server01为primary server02为secondary 操作为: 首先在server02上

接着在server01上

需要注意的是切换回来后检查一下drbd的状态:

四.Dual-primary mode (双主模式)(测试中) 多主模式

To enable dual-primary mode, set the allow-two-primaries option to yes in the net section of your resource configuration:

resource net {

allow-two-primaries yes; }

...secondary }

五.DRBD脑裂后的处理:

DRBD脑裂:双节点都无法探测到彼此了,都认为自己可以读写了。如果两节点都写数据,会产生覆盖。 解决思路:

谁改的少,丢弃谁的

把修改的 合并到没有修改的,这是drbd内置的脑裂出现的解决方法

脑裂后,两个节点间数据不同步,主从关系失效,需要按下面的步骤修复: a.在从节点如下操作: #drbdadm secondary r0

#drbdadm -- --discard-my-data connect r0

b.在主节点上,通过cat /proc/drbd查看状态,如果不是WFConnection状态,需要再手动连接:

#drbdadm connect r0

六.整合heartbeat+rdbd+mysql 1.安装heartbeat: 主节点server01

[root@server01 ~]# vim /etc/hosts

127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.0.136 server01 HA01 10.0.0.10 HA01 10.0.0.11 HA02 192.168.0.137 server02 从节点server02

[root@server02 ~]# vim /etc/hosts

127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.0.137 server02 HA02 10.0.0.10 HA01 10.0.0.11 HA02 192.168.0.136 server01

使用yum安装 Heartbeat(主从都需安装) yum install libnet -y

yum install heartbeat-devel -y yum install heartbeat-ldirectord -y yum install heartbeat -y

cp /usr/share/doc/heartbeat-2.1.4/ha.cf /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.4/authkeys /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.4/haresources /etc/ha.d/

配置心跳的加密方式:authkeys (主从相同) vi /etc/ha.d/authkeys auth 1

1 sha1 dhTVvXdPKlajFFwsdxkvmtiP95mjvRCw #1 sha1 sha1_any_password #2 crc

#3 md5 md5_any_password

#authkeys文件用于设定Heartbeat的认证方式,共有3种可用的认证方式,即crc、md5和sha1。

#3种认证方式的安全性依次提高,但是占用的系统资源也依次增加。如果Heartbeat集群运行在安全的网络上,

#可以使用crc方式;如果HA每个节点的硬件配置很高,建议使用sha1,这种认证方式安全级别最高;

#如果是处于网络安全和系统资源之间,可以使用md5认证方式。

##需要说明的一点是:无论auth后面指定的是什么数字,在下一行必须作为关键字再次出现,

##例如指定了\"auth 6\",下面一定要有一行\"6 认证类型

配置心跳的监控(主从相同) vi /etc/ha.d/haresources

server01 IPaddr::192.168.0.141/24/eth0 drbddisk::r0 Filesystem::/dev/drbd1::/drbd::ext3 mysqld

配置心跳的配置文件:ha.cf (主从相同)

logfile /var/log/ha-log.log #heartbeat的日志文件

#logfacility local0 #设置heartbeat的日志,这里采用系统日志 keepalive 2 #每两次检测之间的时间间隔

warntime 20 #连续多久联系不上后开始报警提示 deadtime 30 #连续多久联系不上后认为对方挂掉了 initdead 240 #给系统重启预留的忽略时间,就是系统重启后多久进行检测心跳

udpport 694 #使用udp端口694 进行心跳监测 auto_failback on #是否恢复到它的primary节点

#ubast eth1 #采用eth1的udp广播来发送心跳信息 ucast eth1 10.0.0.11

node server01 node server02

ping 192.168.0.9 #通过ping网关检测心跳是否正常

hopfudge 1

udpport 694 #使用udp端口694 进行心跳监测 auto_failback on #是否恢复到它的primary节点

#crm respawn #compression bz2

#compression_threshold 20 #traditional_compression on

#respawn hacluster /usr/lib/heartbeat/dopd

#apiauth dopd gid=haclient uid=hacluster #respawn root /usr/lib/heartbeat/mgmtd -v #apiauth mgmtd uid=root

注意:主节点为ucast eth1 10.0.0.11 从节点为ucast eth1 10.0.0.11

开机自启动

chkconfig --levels 345 heartbeat on

2.安装mysql 5.1.34

wget ftp://software:xiazai123@60.190.217.59/mysql/mysql-5.1.43.tar.gz tar zxvf mysql-5.1.43.tar.gz cd mysql-5.1.43

#cp BUILD/compile-pentium-icc ./compile #sh BUILD/autorun.sh

./configure --prefix=/usr/local/mysql \\ --localstatedir=/home/mysql \\ --with-comment=Source \\ --with-server-suffix=-Community-Server \\ --with-mysqld-user=mysql \\ --without-debug \\ --with-big-tables \\ --with-charset=utf8 \\ --with-extra-charsets=all \\ --with-pthread \\ --enable-static \\ --enable-thread-safe-client \\ --with-client-ldflags=-all-static \\ --with-mysqld-ldflags=-all-static \\ --enable-assembler \\ make&&make install groupadd mysql

useradd -g mysql -s /sbin/nologin mysql chown -R root /usr/local/mysql chgrp -R mysql /usr/local/mysql

./scripts/mysql_install_db --user=mysql --datadir=/home/mysql chgrp -R mysql /usr/local/mysql chown -R mysql /home/mysql chgrp -R mysql /home/mysql/

wget ftp://software:xiazai123@60.191.217.59/mysql/my.txt

cp /root/my.txt /drbd/mysql/my.cnf #为了保证IP漂移后,接管mysql服务的在线服务 ln -s /drbd/mysql/my.cnf /etc/my.cnf #器可以作为mysql主从模式为从机提供服务, #mysql的配置文件必须唯一 cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld

chmod +x /etc/rc.d/init.d/mysqld service mysqld start

ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql mysql

mysql>show engines;

mysql>update mysql.user set password=password(\"123456\") where user='root'; mysql> flush privileges; mysql> \\q

停掉mysql服务

cp -pr /home/mysql/ /drbd/

更改mysqlserver的数据库文件所在的目录为/drbd/mysql 在/etc/my.cnf 增加datadir =/drbd/mysql

# vim /etc/my.cnf

[client]

port = 3306

socket = /tmp/mysql.sock

# The MySQL server [mysqld]

port = 3306

datadir = /drbd/mysql socket = /tmp/mysql.sock

key_buffer = 16M

max_allowed_packet = 1M table_cache =

sort_buffer_size = 512K net_buffer_length = 8K

myisam_sort_buffer_size = 8M

skip-locking skip-networking #skip-bdb

set-variable = max_connections=10000 set-variable = max_connect_errors=99999 long_query_time=1

log_slow_queries=/var/tmp/mysql_slow.log

[mysqldump] quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[isamchk]

key_buffer = 8M

sort_buffer_size = 8M

[myisamchk] key_buffer = 8M

对于主节点可将mysql加入开机启动中,从节点不可加入开机启动

七.测试heartbeat+drbd+mysql 在server01查看一下服务器状态 [root@server01 ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:FF:51:07

inet addr:192.168.0.136 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feff:5107/ Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:825280 errors:157 dropped:0 overruns:0 frame:0 TX packets:850237 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000

RX bytes:270828284 (258.2 MiB) TX bytes:155779682 (148.5 MiB) Interrupt:193 Base address:0x2024

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:FF:51:07

inet addr:192.168.0.141 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:193 Base address:0x2024

eth1 Link encap:Ethernet HWaddr 00:0C:29:FF:51:11

inet addr:10.0.0.10 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::20c:29ff:feff:5111/ Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6176 errors:0 dropped:0 overruns:0 frame:0 TX packets:10 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000

RX bytes:1461161 (1.3 MiB) TX bytes:1514970 (1.4 MiB) Interrupt:193 Base address:0x20a4

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:136 Metric:1 RX packets:23485 errors:0 dropped:0 overruns:0 frame:0 TX packets:23485 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0

RX bytes:6286591 (5.9 MiB) TX bytes:6286591 (5.9 MiB)

[root@server01 ~]# /etc/init.d/heartbeat status

heartbeat OK [pid 31582 et al] is running on server01 [server01]... [root@server01 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.2.5 (api:88/proto:86-88)

GIT-hash: 9faf052fdae5ef0c61b4d030e2d2eab550610c build by root@server01, 2011-12-02 10:00:19

m:res cs st ds p mounted fstype 1:r0 Connected Primary/Secondary Diskless/UpToDate C /drbd ext3 [root@server01 ~]# /etc/init.d/mysqld status

MySQL running (32390) [确定] 在server02上查看服务状态 [root@server02 ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:EC:DA:E9

inet addr:192.168.0.137 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feec:dae9/ Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:17099 errors:0 dropped:0 overruns:0 frame:0 TX packets:1466704 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000

RX bytes:512954705 (4.1 MiB) TX bytes:293106034 (279.5 MiB) Interrupt:193 Base address:0x2024

eth1 Link encap:Ethernet HWaddr 00:0C:29:EC:DA:F3

inet addr:10.0.0.11 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::20c:29ff:feec:daf3/ Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:24851 errors:0 dropped:0 overruns:0 frame:0 TX packets:69140 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000

RX bytes:5955549 (5.6 MiB) TX bytes:8631444 (8.2 MiB) Interrupt:193 Base address:0x20a4

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:136 Metric:1 RX packets:28494 errors:0 dropped:0 overruns:0 frame:0

TX packets:28494 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0

RX bytes:7611211 (7.2 MiB) TX bytes:7611211 (7.2 MiB)

[root@server02 ~]# /etc/init.d/heartbeat status

heartbeat OK [pid 9081 et al] is running on server02 [server02]... [root@server02 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.2.5 (api:88/proto:86-88)

GIT-hash: 9faf052fdae5ef0c61b4d030e2d2eab550610c build by root@server02, 2011-12-02 09:56:19

m:res cs st ds p mounted fstype 1:r0 Connected Secondary/Primary UpToDate/Diskless C [root@server02 ~]# /etc/init.d/mysqld status

MySQL is not running [失败]

现将server01上用来做心跳检测的网卡eth1宕掉

[root@server01 ~]# ifconfig eth1 down

查看一下server02上面的heartbeat日志可以看到

Dec 08 11:25:03 server02 heartbeat: [9081]: WARN: node server01: is dead

Dec 08 11:25:03 server02 heartbeat: [9081]: WARN: No STONITH device configured. Dec 08 11:25:03 server02 heartbeat: [9081]: WARN: Shared disks are not protected.

Dec 08 11:25:03 server02 heartbeat: [9081]: info: Resources being acquired from server01. Dec 08 11:25:03 server02 heartbeat: [9081]: info: Link server01:eth1 dead.

harc[11130]: 2011/12/08_11:25:03 info: Running /etc/ha.d//rc.d/status status

Dec 08 11:25:03 server02 heartbeat: [11131]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys server02] to acquire.

mach_down[11159]: 2011/12/08_11:25:03 info: Taking over resource group IPaddr::192.168.0.141/24/eth0

ResourceManager[11185]: 2011/12/08_11:25:03 info: Acquiring resource group: server01 IPaddr::192.168.0.141/24/eth0 drbddisk::r0 Filesystem::/dev/drbd1::/drbd::ext3 mysqld IPaddr[11212]: 2011/12/08_11:25:04 INFO: Resource is stopped

ResourceManager[11185]: 2011/12/08_11:25:04 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.141/24/eth0 start

IPaddr[11295]: 2011/12/08_11:25:04 INFO: Using calculated netmask for 192.168.0.141: 255.255.255.0

IPaddr[11295]: 2011/12/08_11:25:04 INFO: eval ifconfig eth0:0 192.168.0.141 netmask 255.255.255.0 broadcast 192.168.0.255

IPaddr[11269]: 2011/12/08_11:25:04 INFO: Success

ResourceManager[11185]: 2011/12/08_11:25:04 info: Running /etc/ha.d/resource.d/drbddisk r0 start

Filesystem[11425]: 2011/12/08_11:25:04 INFO: Resource is stopped

ResourceManager[11185]: 2011/12/08_11:25:04 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd1 /drbd ext3 start

Filesystem[11502]: 2011/12/08_11:25:04 INFO: Running start for /dev/drbd1 on /drbd Filesystem[11494]: 2011/12/08_11:25:05 INFO: Success

ResourceManager[11185]: 2011/12/08_11:25:05 info: Running /etc/init.d/mysqld start

mach_down[11159]: 2011/12/08_11:25:06 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired

mach_down[11159]: 2011/12/08_11:25:06 info: mach_down takeover complete for node server01.

Dec 08 11:25:06 server02 heartbeat: [9081]: info: mach_down takeover complete.

这说明虚拟IP:192.168.0.141已经从server01上漂移动了server02上,并且将原本为secondary节点的drbd升级为primary节点并且/dev/drbd1 挂在到了/drbd,随后mysql服务启动

现在看看server02上面的服务状态:

[root@server02 ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:EC:DA:E9

inet addr:192.168.0.137 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feec:dae9/ Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1713123 errors:0 dropped:0 overruns:0 frame:0 TX packets:1467134 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000

RX bytes:513271117 (4.4 MiB) TX bytes:293162961 (279.5 MiB) Interrupt:193 Base address:0x2024

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:EC:DA:E9

inet addr:192.168.0.141 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:193 Base address:0x2024

eth1 Link encap:Ethernet HWaddr 00:0C:29:EC:DA:F3

inet addr:10.0.0.11 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::20c:29ff:feec:daf3/ Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:24907 errors:0 dropped:0 overruns:0 frame:0 TX packets:69425 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000

RX bytes:59636 (5.6 MiB) TX bytes:8659478 (8.2 MiB) Interrupt:193 Base address:0x20a4

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:136 Metric:1 RX packets:282 errors:0 dropped:0 overruns:0 frame:0 TX packets:282 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0

RX bytes:7650713 (7.2 MiB) TX bytes:7650713 (7.2 MiB)

[root@server02 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.2.5 (api:88/proto:86-88)

GIT-hash: 9faf052fdae5ef0c61b4d030e2d2eab550610c build by root@server02, 2011-12-02 09:56:19

m:res cs st ds p mounted fstype 1:r0 Connected Primary/Primary UpToDate/Diskless C /drbd ext3 [root@server02 ~]# /etc/init.d/mysqld status

MySQL running (11718) [确定]

由于这是测试环境并没有将server01的网卡宕掉,所以升级为primary节点的server02与server01通过eth0还是互通的,这就成了Primary/Primary module 了

下就可以配置mysql的一主多从了 可以参考如下设置(在wiki中有) 条件:

mysql主库:master (IP:192.168.0.193)

mysql从库:slave01(IP:192.168.0.194)、slave02(IP:192.168.0.195)

需求:

主库master中有test01数据库和test02数据库,只将test01同步到slave01中,只将test02同步到slave02中

配置主库master(192.168.0.193): 在主库上的操作:在my.cnf中增加 server-id = 1

log-bin=mysql-bin # 保证binlog可读 read-only = 0 # master读写都可以

binlog-do-db = test01 # 需要备份数据,多个写多行,不写全部都备份 binlog-do-db = test02

binlog-ignore-db = mysql # 不需要备份的数据库,多个写多行 binlog-ignore-db = mysar binlog-ignore-db = test

binlog-ignore-db = dede

binlog-ignore-db = information_schema

保存,并重启mysqld服务 mysql> show master status;

+------------------+----------+---------------+------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+---------------+------------------------------------------+

| mysql-bin.000021 | 611 | test01,test02 | mysql,mysar,test,dede,information_schema | +------------------+----------+---------------+------------------------------------------+ 1 row in set (0.00 sec)

为slave01从库设置复制用户权限 复制对象为主库上的test01

mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT,RELOAD,SUPER ON *.* TO 'slave01'@'192.168.0.194' IDENTIFIED BY '123456';

mysql> Grant ALL PRIVILEGES ON test01.* TO slave01@'%' IDENTIFIED BY '123456';

为slave02从库设置复制用户权限 复制对象为主库上的test02

mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT,RELOAD,SUPER ON *.* TO 'slave02'@'192.168.0.195' IDENTIFIED BY '123456';

mysql> Grant ALL PRIVILEGES ON test02.* TO slave02@'%' IDENTIFIED BY '123456';

配置从库

在slave01(IP:192.168.0.194)上的my.cnf中添加

server-id = 2 #server-id 不要和主库重复 log-bin = mysql-bin log_slave_update expire_logs_days = 7

log-err = /home/mysql/mysql.err

master-host = 192.168.0.193 #对应主库所在的IP地址 master-user = slave01 #slave在主库用户中的账号 master-password = 123456 #slave用户的密码 master-port =3306 #主库的端口号 replicate-do-db = test01 #同步的库

replicate-ignore-db = mysql #跳过不复制的库,多库多行 replicate-ignore-db = test replicate-ignore-db = test02 replicate-ignore-db = mysar replicate-ignore-db = dede

replicate-ignore-db =information_schema

保存,并重启mysqld服务

mysql> slave stop;

mysql> change master to master_host = '192.168.0.193', master_user = 'slave01', master_password = '123456', master_log_file = 'mysql-bin.000021', master_log_pos = 106; mysql> slave start;

mysql> show slave status\\G; 确保Slave_IO_Running: Yes Slave_SQL_Running: Yes

在slave02(IP:192.168.0.195)上的my.cnf中添加

server-id = 3 #server-id 不要和主库重复 log-bin = mysql-bin log_slave_update expire_logs_days = 7

log-err = /home/mysql/mysql.err

master-host = 192.168.0.193 #对应主库所在的IP地址 master-user = slave02 #slave在主库用户中的账号 master-password = 123456 #slave用户的密码 master-port =3306 #主库的端口号 replicate-do-db = test02 #复制的库

replicate-ignore-db = mysql #跳过不复制的库,多库多行 replicate-ignore-db = test replicate-ignore-db = test01 replicate-ignore-db = mysar replicate-ignore-db = dede

replicate-ignore-db =information_schema

保存,并重启mysqld服务

mysql> slave stop;

mysql> change master to master_host = '192.168.0.193', master_user = 'slave02', master_password = '123456', master_log_file = 'mysql-bin.000021', master_log_pos = 106; mysql> slave start;

mysql> show slave status\\G; 确保 Slave_IO_Running: Yes Slave_SQL_Running: Yes

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务