Jimmy 的文檔: sheepdog安裝使用

前言

sheepdog是一個專門爲qemu設計的虛擬機分佈式文件系統,採用完全對稱的結構,沒有元數據服務的中心節點,因此免除了單點故障的隱患.本文基於最新的0.8.2版本測試,介紹sheepdog的安裝配置和使用,測試過的,應該是可以使用的,有什麼問題,隨時聯繫[email protected]

sheepdog的後端集羣管理

sheepdog的後端集羣管理用於管理節點間的成員關係和消息通訊.目前可使用四種模式,分別是local driver(用於單機測試),corosync (默認), zookeeper and Accord.

分爲兩種模型:

– 全對稱 (依賴 Corosync ,運行於 Sheepdog 的地址空間)

● 缺點:規模小 [<100]

● 優點:無需配置

– 單獨的控制集羣 (依賴 Accord* 或者 Zookeeper ,運行於獨立地址空間)

● 缺點:需要配置控制集羣

● 優點:規模大 [>1000]

本測試使用的就是默認的Corosync模式.

 

安裝前準備:

先做一些系統設置

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

 

安裝sheepdog

1).安裝corosync

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

 

2).安裝sheepdog

cd /home2/install git clone git://github.com/collie/sheepdog.git cd sheepdog ./autogen.sh ./configure make install

 

配置corosync和sheepdog

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個副本,只需要在其中一臺節點執行,看看使用幾個節點,如果只有一個節點的話,就將--copies=1,否則會出錯。

collie cluster format --copies=3

查看節點狀態

collie node list

至此sheepdog集羣已經配置完畢

使用qemu-img創建sheepdog磁盤鏡像

由於centos6自帶的qemu1.2版本並不支持sheepdog,這裏要編譯新版的qemu.

安裝依賴的包

yum install zlib-devel glib2-devel -y

編譯qemu,最好用最新的,make的時間可能比較長。

git clone git://git.qemu.org/qemu.git cd qemu ./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.102: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

 

其他用法

1)創建快照

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

2)磁盤克隆

qemu-img create -b sheepdog:MyFirstDisk sheepdog:Disk2

3)關閉sheepdog集羣

collie cluster shutdown

此命令會關閉所有節點的進程


4) 在libvirt文件中使用

提供一個完成的配置文件,qxl,spice,virtio的:

我的有兩個node 分別是: 10.1.82.113 和10.1.82.119

有一個vdi文件是:MyFirstDisk3(虛擬機鏡像)

通過下面的配置文件即可運行。

<domain type='kvm'>
	<name>win7-32</name>
	<vcpu>2</vcpu>
	<cpu>
		<topology sockets='1' cores='2' threads='1'/>
	</cpu>
	<clock offset='localtime'/>
	<on_poweroff>destroy</on_poweroff>
	<on_reboot>restart</on_reboot>
	<on_crash>restart</on_crash>
	<memory>2048576</memory>
	<os>
		<smbios mode='sysinfo'/>
		<type arch='x86_64'>hvm</type>
		<boot dev='hd'/>
	</os>
	<sysinfo type='smbios'>
		<bios>
			<entry name='vendor'>XXXX</entry>
			<entry name='version'>6.2</entry>
			<entry name='date'>2011-12</entry>
			<entry name='release'>10</entry>
		</bios>
		<system>
			<entry name='manufacturer'>XXXX</entry>
			<entry name='version'>6.2</entry>
			<entry name='product'>NKVS</entry>
			<entry name='family'>NKSCLOUD</entry>
		</system>
	</sysinfo>
	<devices>
		<emulator>/usr/libexec/qemu-kvm</emulator>
<span style="color:#FF0000;">                   
      <disk type="network" device="disk">
          <driver name="qemu" type="raw" />
          <source protocol='sheepdog' name="MyFirstDisk3">
              <host name="10.1.82.113" port="7000"/>
              <host name="10.1.82.119" port="7000"/>
          </source>
          <target dev="vdb" bus="virtio" />
      </disk> </span>

	       <interface type='bridge'>
			<source bridge='virbr0'/>
			<mac address='02:00:0a:01:53:a9'/>
			<model type='virtio'/>
		</interface>
		<graphics type='spice' listen='0.0.0.0' port='30006'>
			<mouse mode='server'/>
		</graphics>
		<video>
			<model type='qxl' vram='65536' heads='1'/>
		</video>
		<controller type='virtio-serial' index='0'/>
		<channel type='spicevmc'>
			<target type='virtio' name='com.redhat.spice.0'/>
		</channel>
		<sound model='ich6'/>
		<input type='tablet' bus='usb'/>
	</devices>
	<features>
		<pae/>
		<acpi/>
		<apic/>
	</features>
</domain>


a. 因爲qemu-kvm 的關係可能會造成下面的錯誤:

  qemu-kvm: -drive file=sheepdog:10.1.82.113:7000:myFirstDisk3,if=none,id=drive-virtio-disk1,format=qcow2: could not open disk image sheepdog:10.1.82.113:7000:myFirstDisk3: No such file or directory

可以通過下面步驟來修復,直接運行ln -s /usr/local/bin/qemu-system-x86_64 /usr/libexec/qemu-kvm 大家可以嘗試下能不能成功。

wget http://sourceforge.net/projects/kvm/files/qemu-kvm/1.0/qemu-kvm-1.0.tar.gz/download tar zxvf qemu-kvm-1.0.tar.gz cd qemu-kvm-1.0 ./configure --enable-spice make&&make install modprobe kvm-intel modinfo kvm ln -s /usr/local/bin/qemu-img /usr/bin/qemu-img ln -s /usr/local/bin/qemu-io /usr/bin/qemu-io ln -s /usr/local/bin/qemu-nbd /usr/bin/qemu-nbd ln -s /usr/local/bin/qemu-system-x86_64 /usr/bin/qemu ln -s /usr/local/bin/qemu-system-x86_64 /usr/bin/kvm ln -s /usr/local/bin/qemu-system-x86_64 /usr/libexec/qemu-kvm

b. 有的系統還會出現如下錯誤:

libvir:  error : cannot execute binary /usr/libexec/qemu-kvm: Permission denied

這是selinux搗的鬼,運行setenforce = 0即可。

c. <driver name="qemu" type="qcow2" /> 

qcow2 出現如下錯誤:

qemu-kvm: -drive file=sheepdog:10.1.82.113:7000:MyFirstDisk3,if=none,id=drive-virtio-disk1,format=qcow2: could not open disk image sheepdog:10.1.82.113:7000:MyFirstDisk3: Invalid argument

暫時發現在配置文件中只能用raw,還在研究中。








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章