รวมพื้นที่ Storage จาก 4 Server เข้าด้วยกันด้วย GlusterFS


จากคราวที่แล้วไดเขียนถึงเรื่องการสร้าง HA Storage ด้วย GlusterFS ไปแล้ว ในครั้งที่แล้วเรานำเอาพื้นที่จาก 2 Server มาทำ Replication กัน ซึ่งก็จะได้พื้นที่เท่าเดิมเพราะเสียพื้นที่ในการทำ Mirroring และ Replication ครั้งนี้จะมารวมพื้นที่จาก Server 4 เครื่องเพื่อสร้าง Distributed Storage กันในแบบจริงๆ จังๆ ครับ และที่สำคัญใน How-to นี้ไม่ได้ทำ HA หรือ fault tolerance นะครับ หากต้องการทำ HA และ Replication ให้อ่านจากบทความในตอนที่แล้ว ก่อนลงมือทำมาทำความเข้าใจกันก่อน ครั้งนี้จะเป็นการนำเอา พื้นที่ Storage ทั้ง 4 Server มารวมกัน โดยนัยคือการแบ่งไฟล์ออกเป็นส่วนๆ กระจายเก็บลงไปใน Server ในเครือข่าย ซึ่งถ้าเครื่องใดเครื่องหนึ่งตาย ข้อมูลก็จะมีไม่ครบครับ สำหรับงานจริงควรใช้เน็ตเวิร์คขนาด 10 GigE ขึ้นไป ใช้ฮาร์ดแวร์แบบ x86_64 servers พร้อม SATA-II RAID และ Infiniband HBA. จึงจะได้ประสิทธิภาพสูง :)

มาดูโครงสร้างกัน เรามีเครื่อง Server ทั้งหมด 4 เครื่อง และเครื่อง Client 1 เครื่องดังนี้

Server 1 IP Address : 172.16.16.10 Domain Name : server1.example.com
Server 2 IP Address : 172.16.16.11 Domain Name : server2.example.com
Server 3 IP Address : 172.16.16.12 Domain Name : server3.example.com
Server 4 IP Address : 172.16.16.13 Domain Name : server4.example.com
Client 1 IP Address : 172.16.16.14 Domain Name : client1.example.com

เครื่องทุกเครื่องเชื่อมต่อกันในเครือข่ายอ้างอิงผ่าน hostname/domain name ได้ถูกต้อง Linux Distribution ที่ใช้เป็น Ubuntu 10.10 ใครใช้ Debian ก็จะสามารถใช้วิธีการเดียวกันได้ครับ :) เมื่อเตรียมทุกอย่างครบแล้วลงมากันได้!

เครื่อง Server 1-4 ให้ติดตั้ง GlusterFS Server ดังนี้

แปลงร่างเป็น root กันก่อน

sudo -s

จากนั้นติดตั้ง glusterfs-server ดังนี้

aptitude install glusterfs-server

จากนั้นสร้างไดเรคทอรีสำหรับเก็บข้อมูลดังนี้

mkdir /data/export
mkdir /data/export-ns

กรณีที่แบ่งพาร์ทิชั่นสำหรับเก็บข้อมูลให้ mout เป็น /data แล้วสร้างไดเรคทอรี /export แบะ /export-ns ขึ้นมา จากนั้นแก้ไข config ในส่วน glusterfs deamon ในไฟล์ /etc/glusterfs/glusterfsd.vol ดังนี้

volume posix
type storage/posix
option directory /data/export
end-volume

volume locks
type features/locks
subvolumes posix
end-volume

volume brick
type performance/io-threads
option thread-count 8
subvolumes locks
end-volume

volume server
type protocol/server
option transport-type tcp/server
option auth.addr.brick.allow 172.16.*
subvolumes brick
end-volume

ในส่วน option auth.addr.brick.allow 172.16.* หมายถึงให้เครื่องที่อยู่ในเครือข่าย 172.16.* สามารถ mount มายังเครื่องนี้ได้ เมื่อตั้งค่าได้แล้วให้ start services ของ glusterfs ดังนี้

/etc/init.d/glusterfs-server start

เมื่อติดตั้ง GlusterFS ได้ครบทุกเครื่องแล้ว มาดูต่อที่เครื่อง Client เพื่อใช้ในการ mount ใช้งานพื้นที่ Storage กันครับ เริ่มต้นด้วการติดตั้ง glusterfs srever และ gluster client ดังนี้

แปลงร่างเป็น root ก่อน

sudo -s

จากนั้นติดตั้ง package ดังนี้

aptitude install glusterfs-client glusterfs-server

สร้างไดเรดทอรีที่กำหนดจุด mount ดังนี้

mkdir /mnt/glusterfs

แก้ไขไฟล์ /etc/glusterfs/glusterfs.vol เพื่อกำหนดรูปแบบในการทำงานของ glusterfs client ดังนี้

volume remote1
type protocol/client
option transport-type tcp/client
option remote-host server1.example.com
option remote-subvolume brick
end-volume

volume remote2
type protocol/client
option transport-type tcp/client
option remote-host server2.example.com
option remote-subvolume brick
end-volume

volume remote3
type protocol/client
option transport-type tcp/client
option remote-host server3.example.com
option remote-subvolume brick
end-volume

volume remote4
type protocol/client
option transport-type tcp/client
option remote-host server4.example.com
option remote-subvolume brick
end-volume

volume stripe
type cluster/stripe
option block-size 1MB
subvolumes remote1 remote2 remote3 remote4
end-volume

volume writebehind
type performance/write-behind
option window-size 1MB
subvolumes stripe
end-volume

volume cache
type performance/io-cache
option cache-size 512MB
subvolumes writebehind
end-volume

เมื่อได้ config แล้วเราสามารถ mount เจ้า GlusterFS ได้ 2 วิธีครับ คือ

glusterfs -f /etc/glusterfs/glusterfs.vol /mnt/glusterfs

หรือ

mount -t glusterfs /etc/glusterfs/glusterfs.vol /mnt/glusterfs

เมื่อ mount ได้แล้วจะพบว่า เรามีพื้นที่เพิ่มเข้ามาในระบบดังนี้

/etc/glusterfs/glusterfs.vol 103G 3.2G 95G 4% /mnt/glusterfs

จาก config ข้างต้นผมมีพื้นที่เอาไว้สำหรับ GlusterFS อยู่ 26GB ทั้ง 4 Server ดังนั้นผมลัพท์การรวมพื้นที่จึงเป็น 26GB x 4

ทีนี้ให้ลองทดสอบ สร้างไฟล์เปล่าๆ ขึ้นมาสัก 1 ไฟล์ใหญ่ๆ ดังนี้

dd if=/dev/zero of=/mnt/glusterfs/test.img bs=1024k count=1000

จากคำสั่งข้างต้นเราสร้างไฟล์ขนาด 1 GB ขึ้นมา ให้ดุที่เครื่อง Server 1, 2, 3 และ 4 จะพบว่ามีไฟล์ test.img ในทุกเครื่องแต่ขนาดไฟล์ไม่เท่ากัน ซึ่งขึ้นอยู่กับการ strip ของ GlusterFS เอง ในครั้งหน้าเราจะมาใช้งาน Gluster Platform กันครับ ;)

คำสำคัญ (Tags): #glusterfs
หมายเลขบันทึก: 410007เขียนเมื่อ 24 พฤศจิกายน 2010 09:28 น. ()แก้ไขเมื่อ 12 มิถุนายน 2012 13:45 น. ()สัญญาอนุญาต: ครีเอทีฟคอมมอนส์แบบ แสดงที่มา-ไม่ใช้เพื่อการค้า-อนุญาตแบบเดียวกันจำนวนที่อ่านจำนวนที่อ่าน:


ความเห็น (0)

ไม่มีความเห็น

พบปัญหาการใช้งานกรุณาแจ้ง LINE ID @gotoknow
ClassStart
ระบบจัดการการเรียนการสอนผ่านอินเทอร์เน็ต
ทั้งเว็บทั้งแอปใช้งานฟรี
ClassStart Books
โครงการหนังสือจากคลาสสตาร์ท