标签:
DRBD (Distributed Replicated Block Device)分布式复制块设备,它是 Linux 平台上的分散式储存系统,通常用于高可用性(high availability, HA)集群中。DRBD 类似磁盘阵列的RAID 1(镜像),只不过 RAID 1 一般配置在一台服务器内,而 DRBD 是通过网络。192.168.8.39 node2.chinasoft.com node2 192.168.8.42 node3.chinasoft.com node4# cat /etc/sysconfig/network 如果这个与web1或2不一致就改一下,这个改配置文件保证下次系统重启时主机名依然有效,
# ssh-keygen -t rsa -P '' 这个生成一个密码为空的公钥和一个密钥,把公钥复制到对方节点上即可 # ssh-copy-id -i .ssh/id_rsa.pub root@node4.chinasoft.com 对方主机名用登录用户名 node4 8.42执行: # ssh-keygen -t rsa -P '' # ssh-copy-id -i .ssh/id_rsa.pub root@node2.chinasoft.com
# ssh node4.chinasoft.com 'date';date Wed Apr 27 17:41:51 CST 2016 Wed Apr 27 17:41:51 CST 2016
[base] name=localyum baseurl=http://192.168.8.20 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 [updates] name=localyum baseurl=http://192.168.8.20 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# 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 warning: drbd-8.4.3-33.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 66534c2b: NOKEY Preparing... ########################################### [100%] 1:drbd-kmdl-2.6.32-431.el########################################### [ 50%] 2:drbd ########################################### [100%] # scp drbd-8.4.3-33.el6.x86_64.rpm drbd-kmdl-2.6.32-431.el6-8.4.3-33.el6.x86_64.rpm node4.chinasoft.com:/root
# vim /etc/drbd.conf 主配置文件 # vim /etc/drbd.d/global_common.conf 全局和common的配置 global { #全局配置 usage-count no; #这个为yes表示如果你本机可以连接互联网时drbd会通过互联网收集到你安装drbd的信息,官方统计说又多了一个人使用drbd实例,不用可以改为no # minor-count dialog-refresh disable-ip-verification } common { 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. 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"; 定义了一旦本地节点发生IO错误时应该怎么处理 # 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 { on-io-error detach; # 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 } net { protocol C; cram-hmac-alg "sha1"; shared-secret "drbd.tanxw.com"; # 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 } syncer { rate 1000M; } }
# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x831a7283. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sdb: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x831a7283 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-5221, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): +5G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@node2 ~]# kpartx -af /dev/sdb [root@node2 ~]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 [root@node2 ~]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 [root@node2 ~]# cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 512000 sda1 8 2 125316096 sda2 8 16 41943040 sdb 8 17 5253223 sdb1 253 0 30720000 dm-0 253 1 4096000 dm-1 253 2 25600000 dm-2 253 3 30720000 dm-3 253 4 10240000 dm-4 253 5 5253223 dm-5
# cd /etc/drbd.d/ # vim mystore.res resource mystore { #定义一个资源,用关键字resource; on node2.chinasoft.com { #on说明在哪个节点上,跟uname -n保持一致,有多少个节点就定义多少个; device /dev/drbd0; #在磁盘上表现的drbd叫什么名; disk /dev/sdb1; #所使用的磁盘设备是哪个; address 192.168.8.39:7789; #在node2这个节点上监听的套接字,默认监听在7789端口上; meta-disk internal; #保存drbd元数据信息的,表示就放在自己的磁盘区分上,也可以放在外部的磁盘上; } on node4.chinasoft.com { device /dev/drbd0; disk /dev/sdb1; address 192.168.8.42:7789; meta-disk internal; } }
# drbdadm create-md mystore 在各自的节点上初始化资源 Writing meta data... initializing activity log NOT initializing bitmap lk_bdev_save(/var/lib/drbd/drbd-minor-0.lkbd) failed: No such file or directory New drbd meta data block successfully created. lk_bdev_save(/var/lib/drbd/drbd-minor-0.lkbd) failed: No such file or directory # service drbd start 启动drbd # watch -n 1 'cat /proc/drbd' 实现查看磁盘信息 # drbdadm primary --force mystore 在节点上把其中一个提升为主的 # watch -n 1 'cat /proc/drbd' 提升为主的之后再实现查看磁盘信息
# mke2fs -t ext4 /dev/drbd0 格式化drbd0 # mkdir /drbd 创建一个测试目录 # mount /dev/drbd0 /drbd 把创建好的drbd目录挂载到/dev/drbd0上 # cd /drbd # cp /etc/fstab ./ 复制一个文件过来 # vim fstab 编辑这个文件,在里面随便修改修改 # cd # umount /dev/drbd0 卸载刚编辑的这个节点上的drbd0设备 # drbdadm secondary mystore 降级这个节点 切换到另一个节点上: # drbdadm primary mystore 提升为主的 # mkdir /drbd 创建目录用来挂载 # mount /dev/drbd0 /drbd 挂载 # cd /drbd # vim /fstab 再查看刚才编辑的这个文件,内容被修改了
# cd # umount /dev/drbd0 # drbdadm secondary mystore 哪个是主的就在哪个节点上降级 # service drbd stop 两个节点都需要停止服务 # chkconfig drbd off 禁止开机启动 # chkconfig --list drbd 验证是否关闭成功 drbd 0:off1:off2:off3:off4:off5:off6:off
# yum install -y corosync pacemaker # yum install -y crmsh-1.2.6-4.el6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm # cd /etc/corosync/ # cp corosync.conf.example corosync.conf # vim /etc/corosync/corosync.conf compatibility: whitetank totem { version: 2 secauth: on threads: 0 interface { ringnumber: 0 bindnetaddr: 192.168.8.0 mcastaddr: 226.99.11.199 mcastport: 5405 ttl: 1 } } logging { fileline: off to_stderr: no to_logfile: yes to_syslog: no logfile: /var/log/cluster/corosync.log debug: off timestamp: on logger_subsys { subsys: AMF debug: off } } amf { mode: disabled } service { name: pacemaker ver: 0 } aisexce { user: root group: root }
另外开启一个窗口安装lftp命令,并且通过ftp获取一个较大文件 # yum install -y lftp # lftp 192.168.8.53 -uadmin,pass > get bigdata.zip # corosync-keygen Corosync Cluster Engine Authentication key generator. Gathering 1024 bits for key from /dev/random. Press keys on your keyboard to generate entropy. Press keys on your keyboard to generate entropy (bits = 152). Press keys on your keyboard to generate entropy (bits = 224). Press keys on your keyboard to generate entropy (bits = 288). Press keys on your keyboard to generate entropy (bits = 352). Press keys on your keyboard to generate entropy (bits = 416). Press keys on your keyboard to generate entropy (bits = 480). Press keys on your keyboard to generate entropy (bits = 544). Press keys on your keyboard to generate entropy (bits = 608). Press keys on your keyboard to generate entropy (bits = 672). Press keys on your keyboard to generate entropy (bits = 736). Press keys on your keyboard to generate entropy (bits = 800). Press keys on your keyboard to generate entropy (bits = 864). Press keys on your keyboard to generate entropy (bits = 928). Press keys on your keyboard to generate entropy (bits = 992). Writing corosync key to /etc/corosync/authkey.
[root@node2 corosync]# crm configure crm(live)configure# property stonith-enabled=false crm(live)configure# property no-quorum-policy=ignore crm(live)configure# rsc_defaults resource-stickiness=100 crm(live)configure# verify crm(live)configure# commit crm(live)configure# show node node2.chinasoft.com node node4.chinasoft.com property $id="cib-bootstrap-options" dc-version="1.1.10-14.el6-368c726" cluster-infrastructure="classic openais (with plugin)" expected-quorum-votes="2" stonith-enabled="false" no-quorum-policy="ignore" rsc_defaults $id="rsc-options" resource-stickiness="100" crm(live)configure# cd crm(live)# ra crm(live)ra# classes lsb ocf / heartbeat linbit pacemaker service stonith crm(live)ra# meta ocf:linbit:drbd 查看drbd的详细信息
crm(live)ra# cd crm(live)# configure crm(live)configure# primitive mysqlstore ocf:linbit:drbd params drbd_resource=mystore op monitor role=Master interval=30s timeout=20s op monitoer role=Slave interval=60s timeout=20s op start timeout=240s op stop timeout=100s crm(live)configure# verify WARNING: mysqlstore: action monitoer not advertised in meta-data, it may not be supported by the RA crm(live)configure# delete mysqlstore crm(live)configure# primitive mysqlstore ocf:linbit:drbd params drbd_resource=mystore op monitor role=Master interval=30s timeout=20s op monitor role=Slave interval=60s timeout=20s op start timeout=240s op stop timeout=100s crm(live)configure# verify 检查语法
crm(live)# node standby node2.chinasoft.com 把node2改为备用的 crm(live)# node online node2.chinasoft.com 让node2上线 crm(live)# node standby node4.chinasoft.com 把node4改为备用的 crm(live)# node online node4.chinasoft.com 让node4上线,都可以随意切换一下再检测一下挂载的效果
CentOS 6.5环境实现corosync+pacemaker实现DRBD高可用
标签:
原文地址:http://blog.csdn.net/reblue520/article/details/51271281