{"id":1619,"date":"2014-01-27T17:55:10","date_gmt":"2014-01-28T00:55:10","guid":{"rendered":"http:\/\/xiehang.com\/blog\/?p=1619"},"modified":"2014-09-17T19:30:11","modified_gmt":"2014-09-18T02:30:11","slug":"virtualization-glusterfs-and-automation","status":"publish","type":"post","link":"https:\/\/xiehang.com\/blog\/2014\/01\/27\/virtualization-glusterfs-and-automation\/","title":{"rendered":"Virtualization, GlusterFS, and automation"},"content":{"rendered":"

Finally I got some time playing with GlusterFS and libvirt.<\/p>\n

I’m not going to step into GlusterFS setup as it’s really easy and straight forward, I did CentOS kickstart (non-attendance) installation as well since it may help me in future deployment. Note that I assume you have glusterd running the host node, other all localhost below should be replaced by the hostname that is running glusterd.<\/p>\n

First, create the kickstart file somewhere accessible through HTTP, assuming it is http:\/\/192.168.0.1\/kickstart.txt:
\n[raw]
\ninstall
\ncdrom
\ntext
\nlang en_US.UTF-8
\nkeyboard us
\nnetwork –onboot yes –device eth0 –bootproto dhcp –noipv6
\ntimezone –utc America\/Los_Angeles
\nrootpw –iscrypted SOMETHING-COPIED-FROM-\/ETC\/SHADDOW
\nselinux –disabled
\nauthconfig –enableshadow –passalgo=sha512
\nfirewall –service=ssh
\npoweroff<\/p>\n

zerombr yes
\nclearpart –linux –drives=vda
\npart \/boot –fstype ext4 –size 512
\npart swap –recommended
\npart \/ –fstype ext4 –size 4096 –grow<\/p>\n

bootloader –location=mbr –timeout=5 –append=”rhgb quiet console=ttyS0″<\/p>\n

%packages –nobase
\nsudo
\nypbind
\nnfs-utils
\nntp
\nbind-utils
\n%end
\n[\/raw]<\/p>\n

I’m not going to explain configuration options one by one as you can get more detailed explanation from CentOS’s kickstart documentation site<\/a>.<\/p>\n

Then, create the image file (raw format) on GlusterFS volume, you can do it on fuse mounted place at this moment since there won’t be any significant amount data to be written:
\n[shell]
\nsudo truncate -s 100G \/mnt\/glusterfs\/VM\/test-vm\/disk.img
\n[\/shell]<\/p>\n

Or you prefer qemu-img way:
\n[shell]
\nsudo qemu-img create -f raw gluster:\/\/localhost:24007\/glusterfs_vol_name\/VM\/test-vm\/disk.img 100G
\n[\/shell]<\/p>\n

Either one will create a sparsed file size 100G.<\/p>\n

Now, if you’ve downloaded the installation ISO to somewhere, do this:
\n[shell]
\nsudo virt-install –name test-vm –ram 1024 –vcpus 2 –disk path=\/mnt\/glusterfs\/VM\/test-vm\/disk.img,size=100 –network bridge=br1 –os-variant rhel6 –accelerate –location \/path\/to\/CentOS-6.2-x86_64-bin-DVD1.iso –graphics none -x “ks=http:\/\/192.168.0.1\/kickstart.txt console=ttyS0”
\n[\/shell]<\/p>\n

or if you prefer do a network installation:
\n[shell]
\nsudo virt-install –name test-vm –ram 1024 –vcpus 2 –disk path=\/mnt\/glusterfs\/VM\/test-vm\/disk.img,size=100 –network bridge=br1 –os-variant rhel6 –accelerate –location http:\/\/mirror.stanford.edu\/yum\/pub\/centos\/6\/os\/x86_64\/ –graphics none -x “ks=http:\/\/192.168.0.1\/kickstart.txt console=ttyS0”
\n[\/shell]<\/p>\n

After the installation, the machine should be powered-off, if for whatever reason it does not, do a poweroff, then do:
\n
\nsudo virsh list --all
\n<\/code><\/p>\n

to make sure test-vm is not running, then edit the VM’s configuration by:
\n[shell]
\nsudo virsh edit test-vm
\n[\/shell]<\/p>\n

The only thing needs to be changed is the location of the disk image, it should be:
\n[xml]
\n
\n <\/p>\n

\n <\/disk>
\n[\/xml]<\/p>\n

and need to be changed to:<\/p>\n

[xml]
\n
\n
\n <\/source>
\n <\/p>\n

\n <\/disk>
\n[\/xml]<\/p>\n

Remember double check ownership of the disk.img file – it should be owned by qemu:qemu, otherwise you are going to run into disk IO problem (in VM).<\/p>\n

Now, start the VM:
\n[shell]
\nsudo virsh start –console test-vm
\n[\/shell]<\/p>\n

and everything should be there \ud83d\ude42 .<\/p>\n

If you have problem with the VM and want to start over, you can:
\n[shell]sudo virsh reset test-vm[\/shell]
\nto power-cycle the VM,
\n[shell]sudo virsh destroy test-vm[\/shell],
\nto power-off the VM
\n[shell]sudo virsh undefine test-vm[\/shell],
\nto remove the VM from libvirt’s repository.<\/p>\n

I did some performance test on disk, putting the disk image on GlusterFS makes disk I\/O slow for sure, but I think it is still acceptable:
\n[shell]
\nglusterfs-fuse 1048576000 bytes (1.0 GB) copied, 192.922 s, 5.4 MB\/s
\nglusterfs-api 1048576000 bytes (1.0 GB) copied, 33.0347 s, 31.7 MB\/s
\nlocal-filesystem 1048576000 bytes (1.0 GB) copied, 5.70798 s, 184 MB\/s
\n[\/shell]<\/p>\n

The test command was:
\n[shell]
\ndd if=\/dev\/zero of=\/tmp\/dd-test bs=1M count=1000
\n[\/shell]<\/p>\n","protected":false},"excerpt":{"rendered":"

Finally I got some time playing with GlusterFS and libvirt. I’m not going to step into GlusterFS setup as it’s really easy and straight forward, I did CentOS kickstart (non-attendance) installation as well since it may help me in future deployment. Note that I assume you have glusterd running the host node, other all localhost […]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[456,355,439,437,471,469,470],"_links":{"self":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts\/1619"}],"collection":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/comments?post=1619"}],"version-history":[{"count":20,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts\/1619\/revisions"}],"predecessor-version":[{"id":1713,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/posts\/1619\/revisions\/1713"}],"wp:attachment":[{"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/media?parent=1619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/categories?post=1619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xiehang.com\/blog\/wp-json\/wp\/v2\/tags?post=1619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}