標籤:linux glusterfs 3.5.x 高可用性-叢集
周氏一族,整理技術文檔,給下一代留點教程......
應用情境
項目http採用了高可用性keepalive,雙入口接入,那麼就存在一個問題,每台伺服器的web檔案或者介面,需要兩台都同時同步,所以,就想到了檔案分享權限設定。
glusterfs 是在nfs的前提下,進行了升級,而且最近還共用給了apache基金會,發展得很快,最新的版本3.5.x 是比較成熟了,修複了很多bug,很多知名電訊廠商都在用它,特別是搞網盤的,就我所知搜狗是用它最多的營運商之一。
網路結構
192.168.1.202 glusterfs-server 後端儲存
192.168.1.203 glusterfs-server 後端儲存
192.168.1.203 glusterfs-client 前端調用(掛載)
伺服器系統
CentOS release 6.3 (Final) x64bit
安裝步驟:
-------------下面是兩台後端儲存的配置,配置一樣的,不一樣會單獨說明-----------
1、加入gluster yum 源,這樣可以擷取最新的version
|
cd /etc/yum.repos.d/
wget http://download.gluster.org/pub/gluster/glusterfs/3.5/3.5.1/EPEL.repo/glusterfs-epel.repo |
如果這個連結不行,則自己搞一個,也是很簡單的事情,如下
|
[[email protected] yum.repos.d]# cat glusterfs-epel.repo
# Place this file in your /etc/yum.repos.d/ directory
[glusterfs-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/$basearch/
enabled=1
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/pub.key
[glusterfs-noarch-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/noarch
enabled=1
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/pub.key
[glusterfs-source-epel]
name=GlusterFS is a clustered file-system capable of scaling to several petabytes. - Source
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/SRPMS
enabled=0
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/pub.key |
2、查看一下yum源載入是否成功
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/44/7C/wKiom1Ph0BrwbnDpAAJvxDXWqXo984.jpg" title="QQ圖片20140806143925.jpg" alt="wKiom1Ph0BrwbnDpAAJvxDXWqXo984.jpg" />很明顯,已經載入成功。
3、那就開始yum吧,非常簡單
yum -y install glusterfs-server
4、yum完之後,安裝好glusterfs,會在/etc/init.d/下面有兩個配置開機檔案
glusterd glusterfsd // 一一啟動它便可
[[email protected] ~]# /etc/init.d/glusterd start && /etc/init.d/glusterfsd start
5、接下來,在hosts下面,添加兩個後端儲存的ip/hostname 對應關係
|
[[email protected]_server ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.202 server202
192.168.1.203 server203 |
6、分別從兩台機器,添加對方節點,例如202添加203,203添加202
|
前面是202添加203
[[email protected]_server ~]# gluster peer probe server203
peer probe: success.
[[email protected]_server ~]# gluster peer status
Number of Peers: 1
Hostname: server203
Uuid: 04aa2530-379b-40ff-9fc1-66552b1defe7
State: Peer in Cluster (Connected)
下面是203添加202的
[[email protected] ~]# gluster peer probe server202
peer probe: success.
[[email protected] ~]# gluster peer status
Number of Peers: 1
Hostname: server202
Uuid: 05b8fede-9576-4ffa-b525-40c1218d8bac
State: Peer in Cluster (Connected)
[[email protected] ~]#
|
//gluster peer status 是查看節點狀態
7、建立一個主目錄,用來作為後端儲存的根目錄,我們就在/data下面吧
|
mkdir /data
chmod -R 1777 /data |
8、隨便找一個後端儲存節點,202也好,203也罷,隨便你,然後兩條命令,邊可以建立volume
|
gluster volume create zhou replica 2 transport tcp server202:/data server203:/data force
gluster volume start zhou |
注意:8.1隻需要一台建立即可,不能兩台都建立,否則會提示volume zhou 已經存在
| volume create: zhou: failed: Volume zhou already exists |
8.2"replica 2",他的意思,是指我要把建立冗餘資料,也就是說,前端寫入的資料,會同時寫到202和203,如果不加這個參數,前端掛載,只會寫入其中一台,不會同步
8.3在後面,必須加上 force,否則它會提示你,必須加,同樣道理,移除的時候,也得加force
9、假如,我們剛剛8的步驟,是在202上面建立的,那麼,我們來203看一下情況
|
[[email protected] ~]# gluster volume status
Status of volume: zhou
Gluster process Port Online Pid
------------------------------------------------------------------------------
Brick server202:/data 49153 Y 45883
Brick server203:/data 49153 Y 45012
NFS Server on localhost 2049 Y 45026
Self-heal Daemon on localhost N/A Y 45030
NFS Server on server202 2049 Y 45897
Self-heal Daemon on server202 N/A Y 45901
Task Status of Volume zhou
------------------------------------------------------------------------------
There are no active volume tasks |
很明顯,已經開始叢集了。
-----------------------------下面是前端掛載的配置-----------------
10、同樣道理,要載入yum 源,這裡不多說
11、開始安裝 glusterfs-client
yum -y install glusterfs-client
12、yum完之後,就可以使用這條命令來掛載了
mount -t glusterfs server202:/zhou /data/
注意:掛載之前,先要編輯host對應ip,否則怎麼知道你這個server202是什麼飛機來的,而且還要先建立/data檔案,這樣才能掛載,完全命令如下:
|
mkidr /data
chmod -R 1777 /data
mount -t glusterfs server202:/zhou /data/ |
----------------------------下面是前端測試效果----------------
13、在204,建立檔案到/data,為了保障起見,連續建立兩個
14、在202,ll /data,正常情況下會看到 13 步驟所建立的檔案,看不到就是你的問題了
15、在203,ll /data,正常情況下會看到 13 步驟所建立的檔案,看不到就是你的問題了
16、把202關機,在204,建立檔案,此時你會發現建立會有點緩慢,但是沒關係,一樣會建立成功
17、到203,ll /data,正常情況下會看到 16 步驟所建立的檔案,看不到就是你的問題了
18、在17步驟,當202死機,在204建立檔案有點慢,不急,再建立幾個檔案試試,你會發現,這下子會很快,這是正常情況的,因為202掛了,你在204建立的檔案,它會自動建立到203當中
19、把202開機,你會發現,202掛掉的這一個期間,203所建立的檔案,202已經同步過來了
20、同樣道理,你把203關機試一下,效果一樣的
21、高可用性設定組群搭建成功
--------------------------下面是前端配合hhtp測試下載-------------------------
22、yum安裝httpd,這裡不多說了
yum -y install httpd
23、修改httpd預設目錄
vi /etc/httpd/conf/httpd.conf
修改 DocumentRoot "/data"
重啟 httpd restart
24、隨便在204建立一個檔案
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/44/81/wKioL1Ph2YvQdHEhAAFwiBim7eI352.jpg" title="QQ圖片20140806151508.jpg" alt="wKioL1Ph2YvQdHEhAAFwiBim7eI352.jpg" />
25、網頁開啟一下 http://192.168.1.204/good.html
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/44/81/wKiom1Ph2MSB60cQAAD8mg7yVfM447.jpg" title="QQ圖片20140806151620.jpg" alt="wKiom1Ph2MSB60cQAAD8mg7yVfM447.jpg" />
你會發現,成功了,換句話說,以後apache檔案,直接放在 後端儲存即可,不需要兩台都同時放一樣的html檔案,省了很多無用功。
當然,除了存放 html檔案外,也可以放其他你自己想要的東西,例如mp3,電影,等等亂七八糟...
---------------------------下面是常見問題彙集--------------------------------------
[[email protected] ~]# gluster peer status
Connection failed. Please check if gluster daemon is operational.
麻煩,您把進程先開起來 /etc/init.d/glusterd start && /etc/init.d/glusterfsd start
[[email protected] ~]# gluster peer probe server202
peer probe: failed: Probe returned with unknown errno 107
帥鍋,請關閉iptables防火牆,謝謝
[[email protected]_server ~]# gluster volume remove-brick zhou server202:/data
WARNING: running remove-brick commands without an explicit option is deprecated, and will be removed in the next version of GlusterFS.
To forcibly remove a brick in the next version of GlusterFS, you will need to use "remove-brick force".
不管是建立volume還是移除,全部在後面加一個force
---------------------------下面是常見問題彙集--------------------------------------
help一下,看看有那些管理工具
[[email protected]_server ~]# gluster volume help
volume info [all|<VOLNAME>] - list information of all volumes
volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT>] [transport <tcp|rdma|tcp,rdma>] <NEW-BRICK>?<vg_name>... [force] - create a new volume of specified type with mentioned bricks
volume delete <VOLNAME> - delete volume specified by <VOLNAME>
volume start <VOLNAME> [force] - start volume specified by <VOLNAME>
volume stop <VOLNAME> [force] - stop volume specified by <VOLNAME>
volume add-brick <VOLNAME> [<stripe|replica> <COUNT>] <NEW-BRICK> ... [force] - add brick to volume <VOLNAME>
volume remove-brick <VOLNAME> [replica <COUNT>] <BRICK> ... [start|stop|status|commit|force] - remove brick from volume <VOLNAME>
volume rebalance <VOLNAME> [fix-layout] {start|stop|status} [force] - rebalance operations
volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> {start [force]|pause|abort|status|commit [force]} - replace-brick operations
volume set <VOLNAME> <KEY> <VALUE> - set options for volume <VOLNAME>
volume help - display help for the volume command
volume log rotate <VOLNAME> [BRICK] - rotate the log file for corresponding volume/brick
volume sync <HOSTNAME> [all|<VOLNAME>] - sync the volume information from a peer
volume reset <VOLNAME> [option] [force] - reset all the reconfigured options
volume profile <VOLNAME> {start|stop|info [nfs]} - volume profile operations
volume quota <VOLNAME> {enable|disable|list [<path> ...]|remove <path>| default-soft-limit <percent>} |
volume quota <VOLNAME> {limit-usage <path> <size> [<percent>]} |
volume quota <VOLNAME> {alert-time|soft-timeout|hard-timeout} {<time>} - quota translator specific operations
volume top <VOLNAME> {open|read|write|opendir|readdir|clear} [nfs|brick <brick>] [list-cnt <value>] |
volume top <VOLNAME> {read-perf|write-perf} [bs <size> count <count>] [brick <brick>] [list-cnt <value>] - volume top operations
volume status [all | <VOLNAME> [nfs|shd|<BRICK>|quotad]] [detail|clients|mem|inode|fd|callpool|tasks] - display status of all or specified volume(s)/brick
volume heal <VOLNAME> [{full | statistics {heal-count {replica <hostname:brickname>}} |info {healed | heal-failed | split-brain}}] - self-heal commands on volume specified by <VOLNAME>
volume statedump <VOLNAME> [nfs|quotad] [all|mem|iobuf|callpool|priv|fd|inode|history]... - perform statedump on bricks
volume list - list all volumes in cluster
volume clear-locks <VOLNAME> <path> kind {blocked|granted|all}{inode [range]|entry [basename]|posix [range]} - Clear locks held on path
各個參數的作用個,一目瞭然,大家不用我解釋了吧
本文出自 “周氏一族” 部落格,謝絕轉載!