前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux 高可用存储环境搭建(DRBD+Heartbeat+NFS)

Linux 高可用存储环境搭建(DRBD+Heartbeat+NFS)

作者头像
SuperDream
发布2019-02-28 10:03:42
1.7K0
发布2019-02-28 10:03:42
举报
文章被收录于专栏:云计算-私有云云计算-私有云

DRBD+Heartbeat+NFS安装

实验拓扑

系统环境

1. 系统:Centos5.6X64位

2. 软件:DRBD,Heartbeat,NFS

3. 服务器:三台

4. IP分配:

心跳线:Stronge1:172.16.10.1                      Stronge2:172.16.10.2

Stronge1:192.168.1.31         Stronge2:192.168.1.32          VIP:192.168.1.35

测试机:192.168.1.254  网关:192.168.1.1

实验步骤

一.DRBD的安装与配置

配置两台主机的主机名,修改hosts文件

vi /etc/hosts 127.0.0.1               stronge1 localhost ::1             localhost6.localdomain6 localhost6 192.168.1.31    stronge1 192.168.1.32    stronge2

1. 选择所要使用的磁盘

fdisk /dev/hda [root@stronge1 /]# fdisk /dev/hda   The number of cylinders for this disk is set to 1305. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs    (e.g., DOS FDISK, OS/2 FDISK)   Command (m for help): n Command action    e   extended    p   primary partition (1-4) p Partition number (1-4): 1 Command (m for help): w [root@stronge1 /]# partprobe   //分好区后同步磁盘

3.安装DRBD

yum -y install kmod-drbd drbd

我Centos5.6X64同时安装两个会报错,安装完第一个第二个被作为依赖就安装上了。

4.加载DRBD模块

  modprobe drbd

通过ls mod查看是否加载成功

[root@stronge1 ~]# lsmod | grep drbd

drbd                  238664  4

5. 更改DRBD配置文件

# 是否参加DRBD使用者统计.默认是yes global { usage-count yes; } # 设置主备节点同步时的网络速率最大值,单位是字节. common { syncer { rate 10M; } } # 一个DRBD设备(即:/dev/drbdX),叫做一个"资源".里面包含一个DRBD设备的主备节点的 # 相关信息. # resource r0 { # 使用协议C.表示收到远程主机的写入确认后,则认为写入完成. protocol C; net { # 设置主备机之间通信使用的信息算法. cram-hmac-alg sha1; shared-secret "FooFunFactory"; } # 每个主机的说明以"on"开头,后面是主机名.在后面的{}中为这个主机的配置. on stronge1 { # /dev/drbd1使用的磁盘分区是/dev/hdb1 device    /dev/drbd0; disk      /dev/hda1; # 设置DRBD的监听端口,用于与另一台主机通信 address   192.168.1.31:7788; meta-disk  internal; } on stronge2 { device    /dev/drbd0; disk      /dev/hda1; address   192.168.1.32:7788; meta-disk  internal; } }

两台主机的配置文件一样。

6. 初始化DRBD资源

a) 创建metadata;

dd if=/dev/zero of=/dev/hda1 bs=1M count=10

drbdadm create-md all

b) 启动drbd: service drbd start    主副都启动

c) 设置为主节点: drbdadm primary all                 //主服务器

如果报错 执行drbdsetup /dev/drbd0 primary –o

然后如果有多个共享磁盘,可以再次执行drbdadm primary all

d) 在新设备上面创建文件系统 mkfs.ext3 /dev/drbd0    //主服务器

e)挂载文件系统

e) 挂载文件系统

mkdir /share              //两服务器都要有此文件夹

mount /dev/drbd0 /share    //主服务器

主的格式化文件系统后,副的不用任何操作,会自动同步过去。

7. primary和secondary节点都配置好并且启动成功后,开始检查配置是否成功。

a) 检查进程:

Primary:

[root@localhost /]# ps -aux | grep drbd Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ root      5471  0.0  0.2  74496  1388 pts/0    T    15:57   0:00 vi /etc/drbd.conf root      5559  0.0  0.0      0     0 ?        S    16:04   0:00 [drbd0_worker] root      5562  0.0  0.0      0     0 ?        S    16:04   0:00 [drbd0_receiver] root      5569  0.0  0.0      0     0 ?        S    16:04   0:00 [drbd0_asender] root      5635  0.0  0.1  61184   788 pts/0    S+   16:23   0:00 grep drbd

 Secondary:

[root@stronge2 /]# ps -aux | grep drbd Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ root      3719  0.0  0.0      0     0 ?        S    16:04   0:00 [drbd0_worker] root      3720  0.0  0.0      0     0 ?        S    16:04   0:00 [drbd0_receiver] root      3727  0.0  0.0      0     0 ?        S    16:04   0:00 [drbd0_asender] root      3813  0.0  0.1  61180   792 pts/0    S+   16:28   0:00 grep drbd

可以看到两个节点的进程都起来了,每个drbd设备会有三个进程:drbd0_worker是drbd0的主要进程,drbd0_asender是primary上drbd0的数据发送进程,drbd0_receiver是secondary上drbd0的数据接收进程。

b) 查看DRBD状态:

[root@localhost /]# cat /proc/drbd version: 8.0.16 (api:86/proto:86) GIT-hash: d30881451c988619e243d6294a899139eed1183d build by mockbuild@v20z-x86-64.home.local, 2009-08-22 13:26:57  0: cs:Connected st:Primary/Secondary ds:UpToDate/Diskless C r---     ns:109 nr:128 dw:298776 dr:467 al:123 bm:179 lo:0 pe:0 ua:0 ap:0         resync: used:0/61 hits:0 misses:0 starving:0 dirty:0 changed:0         act_log: used:0/127 hits:74571 misses:271 starving:0 dirty:148 changed:123

输出文件上面最开始是drbd的版本信息,然后就是数据同步的一些状态信息,从mysql的文档上介绍了每一个状态的意思如下: cs — connection state  st — node state (local/remote)  ld — local data consistency  ds — data consistency  ns — network send  nr — network receive  dw — disk write  dr — disk read  pe — pending (waiting for ack)  ua — unack’d (still need to send ack)  al — access log write count

c) 进一步验证数据同步是否正常

在主服务器创建几个文件,然后将文件系统umount掉,然后将主服务器改为secondary模式

cd /share    touch 1.txt    cd ..    umount /dev/drbd0    drbdadm secondary all

将副服务器改为primary模式,然后挂载文件系统,查看文件是否同步过来

drbdadm primary all    mount /dev/drbd0 /share    cd /share    ls    1.txt

经验证,数据已经同步好了,将模式还原,然后进行下面的操作。

二.配置NFS

1.安装NFS

yum –y install nfs-utils nfs4-acl-tools

2.配置NFS共享目录

 vi /etc/exports [root@localhost ha.d]# more /etc/exports

/share          192.168.1.254(rw,no_root_squash,sync anonuid=502,anongid=502)

anonuid=502,anongid=502:这个表示客户端上任何用户进入到挂载目录都以uid=502和gid=502身份,我这里这个代表的是nfs用户

两台服务器配置一样

1. 启动NFS服务

service portmap  start

service nfs   start

切记,必须先启动portmap服务

2. 加载开启启动

Chkconfig nfs off

Chkconfig portmap on

Portmap服务必须随服务器开机启动,且不受heartbeat管理;而nfs必须要用heartbeat来管理他的启动和关闭,所以这里要关闭nfs开机自动启动

3. 启动锁机制

/sbin/rpc.lockd

echo “/sbin/rpc.lockd” >> /etc/rc.local

要启动锁机制,因为同时有两个节点要使用同一份数据,比如两台mysql负载均衡服务器都要同时读取一个数据库,所以要有仲裁。如果没有这种情况,建议不要启动,启动了会降低NFS的性能

4. 开机自动挂载

echo “sleep 20” >> /etc/rc.local

echo “/bin/mount –t nfs 192.168.1.35:/share /mnt” >> /etc/rc.local

这里是针对nfs客户端的,为什么为延迟20秒再挂载nfs?因为如果不等待立即挂载,会发现挂载不上,这是由于heartbeat启动用的vip还没设置好的原因

三.安装Heartbeat实现故障自动转移

两服务器对外IP

Stronge1:192.168.1.31

Stronge2:192.168.1.32

集群虚拟IP:192.168.1.35

5. 安装heartbeat

yum -y inistall heartbeat

此命令需要执行两次,第一次是安装的heartbeat的一些组件,第二次是安装的heartbeat

6. 同步两台服务器的时间

rm –rf /etc/localtime cp –f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime yum install –y ntp ntpdate –d cn.pool.ntp.org

3.将heartbeat的配置文件拷入至etc目录

rpm –ql heartbeat  //找到文件所在位置

# cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/

# cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/

# cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/

4.配置集群认证文件

Vi /etc/ha.d/authkeys

auth 1

1 crc

chmod 600 authenkeys   //此操作必须要

5.配置集群节点文件

debugfile /var/log/ha-debug                             #打开错误日志报告 keepalive 2                                             #两秒检测一次心跳线连接 deadtime 10                                             #10 秒测试不到主服务器心跳线为有问题出现 warntime 6                                              #警告时间(最好在 2 ~ 10 之间) initdead 120                                            #初始化启动时 120 秒无连接视为正常,或指定heartbeat                                                         #在启动时,需要等待120秒才去启动任何资源。   udpport 694                                             #用 udp 的 694 端口连接 ucast eth1 172.16.10.2                                #单播方式连接(主从都写对方的 ip 进行连接,数据复制和心跳检测尽量不要使用同一块网卡) node   node1                                           #声明主服(注意是主机名uname -n不是域名) node   node2                                           #声明备服(注意是主机名uname -n不是域名) auto_failback on                                        #自动切换(主服恢复后可自动切换回来)这个不要开启 respawn hacluster /usr/lib/heartbeat/ipfail           #监控ipfail进程是否挂掉,如果挂掉就重启它

6.配置集群资源文件

vi  /etc/ha.d/hareresources

stronge1 IPaddr::192.168.1.35/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/share::ext3 portmap nfs

此配置两台主机配置一模一样,stronge2前面也写stronge1.

7. 创建NFS管理脚本

vi /etc/ha.d/resource.d/nfs

#!/bin/bash   NFSD=/etc/rc.d/init.d/nfs NFSDPID=`/sbin/pidof nfsd` case $1 in start) $NFSD start; ;; stop) $NFSD stop;         if [ "$NFSDPID" != " " ];then                 for NFSPID in $NFSDPID                 do /bin/kill -9 $NFSPID;                 done         fi ;; *) echo "Syntax incorrect. You need one of {start|stop }" ;; esac

8. 启动测试

先启动stronge1的heartbeat,再启动stronge2的heartbeat

启动成功后,这里有几项需要检查

Stronge1: 执行ip a,检查是否已经设置有虚拟ip 192.168.1.35

9. 将heartbeat加入开机启动

chkconfig heartbeat on

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2012-03-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • DRBD+Heartbeat+NFS安装
    • 实验拓扑
      • 系统环境
        • 实验步骤
        相关产品与服务
        负载均衡
        负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档