来源: Linux论坛 日期: 2009.12.07 22:53
一、概述
Moose通过DNBD提供磁盘及时同步,通过HeartBeat提供Failover,来达到高可用。
二、系统环境,软件版本及所需要的包1、系统环境:
System:RHEL5U3
Kernel:2.6.18-128.el5
2、软件版本:
HeartBeat heartbeat-3.0.0-33.2
DRBD:drbd-8.3.2
MooseFS:mfs-1.5.12
3、所需包:
Kernel-devel
Flex
Gcc
三、安装Heartbeat1.
我这人比较懒,直接用Yum装的,
# vim /etc/yum.repos.d/rhel-debuginfo.repo
[ha]
name=Heartbeat
baseurl=http://download.opensuse.org/repositories/server:/ha-clustering/RHEL_5/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
# yum install heartbeat.i386 heartbeat-devel.i38
2、编辑HeartBeat配置文件
# cp /usr/share/doc/heartbeat-3.0.0/ha.cf /etc/ha.d/.
# vim /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2 //设定heartbeat之间的时间间隔为2秒.
deadtime 30 //在30秒后宣布节点死亡。
warntime 10 //在日志中发出“late heartbeat“警告之前等待的时间,单位为秒。
initdead 120 //
udpport 694 //使用端口694进行bcast和ucast通信。
mcast eth0 225.0.0.1 694 1 0 //组播地址
ucast eth0 192.168.1.234 //使用的网卡及ip
auto_failback on //on是主机故障后,是否自动切回
node oss1 //节点1
node oss2 //节点2
ping 192.168.1.46 // ping 地址
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
3、编辑HA验证文件
# cp /usr/share/doc/heartbeat-3.0.0/authkeys /etc/ha.d/authkeys
# vim /etc/ha.d/authkeys
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
我选择的是Md5的验证方式,
最后记得将authkeys 权限给为600
# chmod 600 authkeys
4、编辑haresources
oss1 192.168.1.230 drbddisk::r0 Filesystem::/dev/drbd0::/mnt/mfs::ext3 mfsmaster
四、安装DRBD1、安装Drbd
# tar zxvf drbd-8.3.2.tar.gz
# cd drbd-8.3.2
# make KERNVER=2.6.18-128.el5 KDIR=/usr/src/kernels/2.6.18-128.el5-i686
# make install
# vim /etc/drbd.conf
global {
usage-count yes; //是否参加使用者统计
2、启动DRbd
首先要创建Drbd所需要的数据块
# drbdadm create-md r0 //创建数据块,R0是上面配置文件中指定的
# mknod /dev/drbd0 b 147 0 //创建设备名称drbd0
# service drbd start //启动drbd 记得启动另外一台。
# [root@oss2 ~]# cat /proc/drbd //查看proc中DRBD的状态
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by root@oss2, 2009-09-16 19:09:26
0: cs:Connected ro:Secondary/ Secondary ds:UpToDate/UpToDate C r----
ns:4494 nr:14497 dw:18335 dr:2510 al:4 bm:12 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
DRBD启动后2台机器都是备用状态,它无法判断哪边是主机,以哪边的磁盘为依据,后面需要初始化
# drbdsetup /dev/drbd0 primary –o
# cat /proc/drbd
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
发现执行完,当前的机器已经变为Primary
# mkdir /mnt/mfs
# chown -R mfs.mfs /mnt/mfs
# mkfs.ext3 /dev/drbd0
# mount /dev/drbd0 /mnt/mfs
五、安装MooseFS1、安装元服务器
# tar zxvf mfs-1.5.12.tar.gz
# cd mfs-1.5.12
# useradd -s /sbin/nologin mfs
# ./configure --prefix=/mnt/mfs --with-default-user=mfs --with-default-group=mfs
# make
# make install
Ps: 我们把mfs安装在drbd的目录/mnt/mfs中,这样Failover 的时候会切换到backup ,这样mfs的数据信息会保持同步
2、配置元服务器
[root@oss1 opt]# cat /mnt/mfs/mfs/etc/mfsmaster.cfg
WORKING_USER = mfs
WORKING_GROUP = mfs
LOCK_FILE = /var/run/mfs/mfsmaster.pid
DATA_PATH = /mnt/mfs/mfs/var/mfs (这个地方一定要在drbd中,否则切换后找到不原来的文件)
SYSLOG_IDENT = mfsmaster
BACK_LOGS = 50
REPLICATIONS_DELAY_INIT = 300
REPLICATIONS_DELAY_DISCONNECT = 3600
MATOCS_LISTEN_HOST = *
MATOCS_LISTEN_PORT = 9420
MATOCU_LISTEN_HOST = *
MATOCU_LISTEN_PORT = 9421
CHUNKS_LOOP_TIME = 300
CHUNKS_DEL_LIMIT = 100
CHUNKS_REP_LIMIT = 15
3、启动元服务器
# mkdir –p /mnt/mfs/mfs/var/mfs
# chown –R mfs.mfs /mnt/mfs/mfs/var/mfs
# mkfs.ext3 /dev/drbd0
# /mnt/mfs/mfs/sbin/mfsmaster
# 查看 netstat –ant
tcp 0 0 0.0.0.0:9420 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9421 0.0.0.0:* LISTEN
可以看到mfs已经在9420与9421上监听了
4、安装chunkserver
# tar zxvf mfs-1.5.12.tar.gz
# cd mfs-1.5.12
# useradd -s /sbin/nologin mfs
# ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --disable-mfsmaster --disable-mfsmount
# make
# make install
5、配置chunkserver
# [root@wenba ~]# cat /usr/local/mfs/etc/mfschunkserver.cfg
WORKING_USER = mfs
WORKING_GROUP = mfs
DATA_PATH = /usr/local/mfs/var/mfs
LOCK_FILE = /var/run/mfs/mfschunkserver.pid
SYSLOG_IDENT = mfschunkserver
BACK_LOGS = 50
MASTER_RECONNECTION_DELAY = 30
MASTER_HOST = 192.168.1.230 (这里面要写HA的virtual ip)
MASTER_PORT = 9420
MASTER_TIMEOUT = 60
CSSERV_LISTEN_HOST = *
CSSERV_LISTEN_PORT = 9422
CSSERV_TIMEOUT = 60
CSTOCS_TIMEOUT = 60
HDD_CONF_FILENAME = /usr/local/mfs/etc/mfshdd.cfg
6、配置存放数据的目录(chunkserver)
# [root@wenba ~]# cat /usr/local/mfs/etc/mfshdd.cfg
/data
然后要让/mfs有能读写data目录的权限
# mkdir /data
# chown mfs.mfs /data
7、Chunkserver启动
# /usr/local/mfs/sbin/mfschunkserver
这时候你可以再元服务器的/var/log/messages中看到chunkserver注册的信息,从下面可以看出有2台chunkserver,总空间75G.
Sep 17 13:38:00 oss1 mfsmaster[4988]: chunkservers status:
Sep 17 13:38:00 oss1 mfsmaster[4988]: server 1 (192.168.1.48): usedspace: 7156297728 (6 GB), totalspace: 40628744192 (37 GB), usage:
17.61%
Sep 17 13:38:00 oss1 mfsmaster[4988]: server 2 (192.168.1.47): usedspace: 6781362176 (6 GB), totalspace: 40628744192 (37 GB), usage:
16.69%
Sep 17 13:38:00 oss1 mfsmaster[4988]: total: usedspace: 13937659904 (12 GB), totalspace: 81257488384 (75 GB), usage:
8、Client的安装,应用
a)、首先要安装Fuse, Linux从2.6.14版本开始通过FUSE模块支持在用户空间实现文件系统
# Tar zxvf fuse-2.7.4.tar.gz
# Cd fuse-2.7.4
# ./configure
# Make
# Make install
编辑 /etc/ld.so.config 加入
include /usr/local/lib
# depmod –a
b)、安装Mfs
# tar zxvf mfs-1.5.12.tar.gz
# cd mfs-1.5.12
# useradd -s /sbin/nologin mfs
# ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --disable-mfsmaster –enable-mfsmount
# make
# make install
载入fuse模块
# modprobe fuse
创建mfs挂接目录,默认在/mnt/mfs下,可以使用-w挂在别的目录下
# mkdir /mnt/mfs
挂接目录
# /usr/local/mfs/bin/mfsmount -h 192.168.1.230
9、测试
[root@localhost test]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
72G 2.7G 66G 4% /
/dev/hdc1 76G 930M 71G 2% /back
/dev/hda1 99M 17M 77M 19% /boot
tmpfs 490M 0 490M 0% /dev/shm
MFS 76G 14G 62G 19% /mnt/mfs
现在可以向/mnt/mfs 中写入数据测试了
六、安 装过程中遇到的一些问题1、create-md的时候总是出现下面的问题
注:mds1在create-md的时候总是出现下面的问题,
[root@mds1 ~]# drbdadm create-md r0
md_offset 2023411712
al_offset 2023378944
bm_offset 2023313408
Found ext3 filesystem which uses 1975992 kB
current configuration leaves usable 1975892 kB
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.
Command 'drbdmeta 0 v08 /dev/sda3 internal create-md' terminated with exit code 40
drbdadm create-md r0: exited with code 40
解决方法:dd if=/dev/zero bs=1M count=1 of=/dev/sda3 然后再执行drbdadm create-md r0
2、mfs编译过程中的问题
如果configure过程中出现” checking for fuse .....no configure” 要配置个环境变量 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH
3、安装moose客户端遇到的问题
checking pkg-config is at least version 0.9.0... yes
checking for FUSE... no
configure: error: mfsmount build was forced, but fuse development package is not installed
解决方法: vim /etc/profile
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH