sheepdog是一个专门为qemu设计的虚拟机分布式文件系统,采用彻底对称的结构,没有元数据服务的中心节点,所以免除了单点故障的隐患.本文基于最新的0.7.0版本测试,介绍sheepdog的安装配置和使用.node
sheepdog的后端集群管理用于管理节点间的成员关系和消息通信.目前可以使用四种模式,分别是local driver(用于单机测试),corosync (默认), zookeeper and Accord.git
分为两种模型: github
– 全对称 (依赖 Corosync ,运行于 Sheepdog 的地址空间)后端
● 缺点:规模小 [<100]centos
● 优势:无需配置分布式
– 单独的控制集群 (依赖 Accord* 或者 Zookeeper ,运行于独立地址空间)oop
● 缺点:须要配置控制集群测试
● 优势:规模大 [>1000]spa
本测试使用的就是默认的Corosync模式.debug
先作一些系统设置
echo " * soft nofile 65533 " >> / etc / security / limits . conf echo " * hard nofile 65533 " >> / etc / security / limits . conf yum install -y make automake autoconf gcc nss-devel wget git glib2
安装epel源
rpm -ivh http: // dl . fedoraproject . org / pub / epel / 6 / x86_64 / epel-release- 6 - 8 . noarch . rpm
centos6自带的版本过旧,咱们须要安装新版
yum remove corosync corosynclib corosynclib-devel -y git clone git: // github . com / corosync / corosync . git cd corosync git checkout -b flatiron origin / flatiron ./ autogen . sh ./ configure --enable-nss make install
cd / home2 / install git clone git: // github . com / collie / sheepdog . git cd sheepdog ./ autogen . sh ./ configure make install
cd / etc / corosync cp corosync . conf . example corosync . conf
编辑corosync.conf修改bindnetaddr成你的网段如192.168.1.0
# Please read the corosync . conf 5 manual page compatibility: whitetank totem { version: 2 secauth: off threads : 0 # Note , fail_recv_const is only needed if you're # having problems with corosync crashing under # heavy sheepdog traffic . This crash is due to # delayed / resent / misordered multicast packets . # fail_recv_const: 5000 interface { ringnumber: 0 bindnetaddr: 192.168 . 1.0 mcastaddr: 226.94 . 1.1 mcastport: 5405 } } logging { fileline: off to_stderr: no to_logfile: yes to_syslog: yes # the pathname of the log file logfile: / var / log / cluster / corosync . log debug : off timestamp: on logger_subsys { subsys: AMF debug : off } } amf { mode : disabled }
启动服务
/ etc / init . d / corosync start # 或经过命令启动 (/ var / lib / sheepdog是sheepdog使用的数据目录 , 你能够更改到其余 ) # sheep / var / lib / sheepdog
sheepdog要求/var/lib/sheepdog目录所在的分区支持xattr
mount -o remount , user_xattr /
以上操做须要在每一台sheepdog节点执行
格式化sheepdog集群并设置3个副本,只须要在其中一台节点执行
collie cluster format --copies = 3
查看节点状态
collie node list
至此sheepdog集群已经配置完毕
因为centos6自带的qemu1.2版本并不支持sheepdog,这里要编译新版的qemu.
安装依赖的包
yum install zlib-devel glib2-devel -y
编译qemu
wget http: // wiki . qemu-project . org / download / qemu- 1.5 . 2 . tar . bz2 tar jxvf qemu- 1.5 . 2 . tar . bz2 cd qemu- 1.5 . 2 ./ configure make ; make install
建立磁盘
/ usr / local / bin / qemu-img create -f qcow2 sheepdog :MyFirstDisk 10G
若是sheepdog运行在其余机器上,须要指定IP和端口
/ usr / local / bin / qemu-img create -f qcow2 sheepdog: 192.168 . 1.100 : 7000 :MyFirstDisk 10G
列出sheepdog里的镜像
collie vdi list
将现有的镜像转换到sheepdog里
qemu-img convert ./ mysystem . raw sheepdog :mysystem
qemu-system-x86_64 --enable-kvm -m 1024 -drive file = sheepdog :MyFirstDisk , cache = writeback -vnc : 15 -cdrom / data / CentOS- 6.4 -i386-minimal . iso
qemu-img snapshot -c name sheepdog :MyFirstDisk
快照建立后查看镜像列表
collie vdi list name id size used shared creation time object id -------------------------------------------------------------------- Bob 0 2.0 GB 1.6 GB 0.0 MB 2010 - 03 - 23 16 : 16 80000 MyFirstDisk 0 256 GB 0.0 MB 0.0 MB 2010 - 03 - 23 16 : 21 c0000 s MyFirstDisk 1 256 GB 0.0 MB 0.0 MB 2010 - 03 - 23 16 : 16 40000
用快照启动虚拟机
qemu-system-x86_64 sheepdog :MyFirstDisk : 1
qemu-img create -b sheepdog :MyFirstDisk sheepdog :Disk2
collie cluster shutdown
此命令会关闭全部节点的进程
首先创建一个名为my_volume的卷
echo my_volume > / var / lib / sheepdog / vdi / mount
格式化为ext4并挂载
mkfs . ext4 / var / lib / sheepdog / volume / my_volume mount -o loop / var / lib / sheepdog / volume / my_volume / mnt
当链接的sheepdog机器宕机咱们能够在线切换到另外一台sheepdog
echo ip :port > / var / lib / sheepdog / config / sheep_info