DRBD+Heratbeat+NFS高可用文件共享存储
1 | [root@masternfs ~] # yum install -y gcc gcc-c++ make perl kernel-devel kernel-headers flex drbd84-utils kmod-drbd84 |
1 2 3 4 5 6 7 8 9 10 11 12 | [root@masternfs ~] # tar zxvf drbd-8.4.4.tar.gz [root@masternfs ~] # cd drbd-8.4.4 [root@masternfs ~] # ./configure --prefix=/usr/local/drbd --with-km #--with-km,启用内核模块 [root@masternfs ~] # make KDIR=/usr/src/kernels/2.6.32-358.23.2.el6.x86_64/ #指定内核源码路径 [root@masternfs ~] # make install [root@masternfs ~] # chkconfig --add drbd [root@masternfs ~] # chkconfig drbd on [root@masternfs ~] # cp drbd/drbd.ko /lib/modules/`uname -r`/kernel/lib/ #加载DRBD模块到内核中 [root@masternfs ~] # modprobe drbd [root@masternfs ~] # lsmod |grep drbd #由此查看drbd模块已经加载 drbd 333755 0 libcrc32c 1246 1 drbd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | [root@masternfs ~] # cd /usr/local/drbd/ [root@masternfs ~] # vi /usr/local/drbd/etc/drbd.d/global_common.conf global { usage-count yes ; } common { protocol C; disk { on-io-error detach; } syncer { rate 100M; } } resource web { on masternfs { device /dev/drbd0 ; disk /dev/sdb1 ; address 192.168.0.202:7899; meta-disk internal; } on backupnfs { device /dev/drbd0 ; disk /dev/sdb1 ; address 192.168.0.203:7899; meta-disk internal; } } |
1 2 3 4 5 6 7 8 | [root@masternfs ~] # drbd admcreate-md web Writing meta data... initializing activity log NOT initializing bitmap New drbd meta data blocksuccessfully created. success [root@masternfs ~] # mkdir -p /usr/local/drbd/var/run/drbd #创建资源目录 [root@masternfs ~] # service drbd start |
1 2 3 4 5 | [root@masternfs ~] # cat /proc/drbd version: 8.4.4(api:1 /proto :86-101) GIT- hash :599f286440bd633d15d5ff985204aff4bccffadd build by phil@Build64R6, 2013-10-1415:33:06 0: cs:Connected ro:Secondary /Secondaryds :UpToDate /UpToDate C r----- ns:64 nr:112 dw:176 dr:6088 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1wo:f oos:0 |
1 2 | [root@masternfs ~] # drbdadm -- --overwrite-data-of-peer primary web [root@db-backup ~] # drbdadm secondary web #backupnfs服务器设置从节点 |
1 2 | [root@masternfs ~] # drbd-overview 0:mysql /0 Connected Primary /Secondary UpToDate /UpToDate C r----- |
1 2 3 | [root@masternfs ~] # mkfs.ext4 /dev/drbd0 [root@masternfs ~] # mkdir /web [root@masternfs ~] # mount /dev/drbd0 /web |
1 2 3 4 5 6 7 | [root@masternfs ~] # yum install -y nfs-utils [root@masternfs ~] # vi /etc/exports /web 192.168.0.0 /24 (rw,no_root_squash) [root@masternfs ~] # service rpcbind start [root@masternfs ~] # service nfs start [root@masternfs ~] # chkconfig rpcbind on [root@masternfs ~] # chkconfig nfs on |
1 2 3 4 | [root@masternfs ~] # yum install heartbeat* -y [root@masternfs ~] # cd /usr/share/doc/heartbeat-3.0.4/ [root@masternfsheartbeat-3.0.4] # cp ha.cf authkeys haresources /etc/ha.d/ [root@masternfsheartbeat-3.0.4] # cd /etc/ha.d/ |
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@masternfs ha.d] # vi ha.cf logfile /var/log/ha-log logfacility local0 #如果未定义上述日志,默认写入/var/log/message keepalive 2 #心跳间隔 deadtime 30 #死亡阀值 warntime 10 #警告时间 initdead 120 #首次启动heartbeat,等待多久才启动主服务资源 udpport 694 #连接端口 bcast eth0 #使用什么方式组织心跳,最好用ucast方式 auto_failback off #当主节点故障恢复后,自动获取资源并取代从节点 node masternfs #主节点主机名 node backupnfs #备份节点主机名 ping 192.168.0.1 #选择ping节点,ping的越好对HA集群越稳定,建议使用网关 |
1 2 3 | [root@masternfs ~] # vi /etc/ha.d/authkeys auth 2 2 sha1 HI! |
1 | [root@masternfs ~] # masternfs IPaddr::192.168.0.204/24/eth0 drbddisk::web Filesystem::/dev/drbd0::/web::ext4 killnfsd |
1 2 | [root@masternfs ~] # echo "killall -9 nfsd ; /etc/init.d/nfs restart ; exit 0" >>/etc/ha.d/resource.d/killnfsd [root@masternfs ~] # chmod +x /etc/ha.d/resource.d/killnfsd |
1 2 3 | [root@masternfs ~] # chmod 600 /etc/ha.d/authkeys #不修改权限会报错 [root@masternfs ~] # service heartbeat start [root@masternfs ~] # chkconfig heartbeat on |