環(huán)境準備
1.操作系統(tǒng)
CentOS?6
2.軟件版本
scsi-target-utils-1.0.24-3.el6_4.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- 網絡存儲服務端
iscsi-initiator-utils-6.2.0.873-2.el6.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- 網絡存儲客戶端
cman-3.0.12.1-49.el6_4.1.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- 分布式集群管理工具
rgmanager-3.0.12.1-17.el6.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- 實現(xiàn)集群高可用晌姚,故障轉移
gfs2-utils-3.0.12.1-49.el6_4.1.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- 全局文件系統(tǒng)
lvm2-cluster-2.02.98-9.el6.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- 集群邏輯卷
3.集群環(huán)境
(1).配置各節(jié)點名稱
node1:
[root@node1?~]#?uname?-n
node1.test.com
[root@node1?~]#?cat?/etc/hosts
127.0.0.1??localhost?localhost.localdomain?localhost4?localhost4.localdomain4
::1????????localhost?localhost.localdomain?localhost6?localhost6.localdomain6
192.168.66.146 ? ?node1.test.com????node1
192.168.66.147 ? ?node2.test.com????node2
192.168.66.148 ? ?node3.test.com????node3
192.168.66.149 ? ?target.test.com ? ?target
PS:其他各個節(jié)點主機突想,依次 修改主機名和域名,不再贅述
(2).配置各節(jié)點與跳板機ssh互信
node1:
[root@node1?~]#?ssh-keygen??-t?rsa
[root@node1?~]#?ssh-copy-id?-itarget
PS:節(jié)點主機依次和target端進行密鑰對同步并扇;而target端也依次向節(jié)點主機同步密鑰對
(3).配置各節(jié)點時間同步
node1(時間服務器):
[root@node1?~]#?vim ?/etc/ntp.conf
restrict 192.168.66.0 mask 255.255.255.0 nomodify notrap noquery
server 127.127.1.0
fudge 127.127.1.0 startum10
PS:其他主機時間服務器指向node1
(4).設置別名變量
[root@target?~]#?alias han='for O? in?{1..3}; do'?#設置一個別名蛉加,因為每次都得用到時
[root@target?~]#han ssh?node$O 'ntpdate -u node1';?done?#各節(jié)點都在時間同步
[root@target?~]#han ssh?node$O 'service?iptables?stop';?done ? ?#關閉防火墻
[root@target?~]#han ssh?node$O 'setenforce 0';?done ? ? ? ? ? ?#關閉selinux
iscsi安裝與配置
1.安裝target
[root@target?~]#?yum?install?-y?scsi-target-utils
2.配置target
[root@target?~]#?vim?/etc/tgt/targets.conf
#配置target名稱
#配置共享磁盤
vendor_id Janni#配置發(fā)行商(任意)
lun?6#配置LUN號
incominguser iscsiuser?iscsiuser?#配置認證的用戶名和密碼
initiator-address192.168.66.0/24?#配置允許訪問共享存儲的網段
3.啟動target并設置為開機自啟動
[root@target?~]#?service?tgtd?start
[root@target?~]#?chkconfig?tgtd?on
[root@target?~]#?chkconfig?tgtd?--list
tgtd??????????????0:關閉1:關閉2:啟用3:啟用4:啟用5:啟用6:關閉
4.查看配置的target
[root@target?~]#?tgtadm -L iscsi -o show -m target
5.在各節(jié)點上安裝initiator
[root@target?~]#han ssh?node$O?'yum?install?-yiscsi-initiator-utils';?done
6.配置initiator
node1:
[root@node1?~]#?vim?/etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2016-03-02.com.xdl.www:node1
[root@node1?~]#?vim?/etc/iscsi/iscsid.conf
node.session.auth.authmethod?=?CHAP ? ? #開啟CHAP認證
node.session.auth.username?=iscsiuser ?#配置認證用戶名
node.session.auth.password?=iscsiuser ?#配置認證密碼
PS:node2和node3依次類推
7.各節(jié)點啟動initiator并設置為開機自啟動
[root@target?~]#han ssh?node$O?'service?iscsi?start';?done
[root@target?~]#han ssh?node$O 'chkconfig?iscsi?on';?done
[root@target?~]#han ssh?node$O 'chkconfig?iscsi?--list';?done
8.在各節(jié)點上發(fā)現(xiàn)一下target
[root@target?~]#han ssh?node$O 'iscsiadm?-m?discovery?-t?st?-ptarget';?done
9.各節(jié)點登錄一下target并查看一下磁盤
[root@target?~]#?han ssh?node$O? 'iscsiadm?-m?node?-T iqn.2016-03-02.com.xdl.www:disk ?--login';?done
cman與rgmanager集群安裝與配置
1.各節(jié)點安裝cman與rgmanager
[root@target?~]#?han ssh?node$O 'yum?install?-ycman?rgmanager';?done
2.配置集群
(1).配置集群名稱
[root@node1?~]#?ccs_tool?create testcluster
(2).配置fencing設備
1234?[root@node1?~]#?ccs_tool?add fence meatware ?fence_manual-名稱-模式為手動
[root@node1?~]#?ccs_tool?lsfence ? ? ? ? -- 查看fence設備
Name????????????Agent
meatware????????fence_manual
(3).配置集群節(jié)點--要知道管理哪些服務器
[root@node1?~]#?ccs_tool?addnode?-n 1 -f ?meatware node1.xdl.com-- 添加節(jié)點? ? --第幾個? ? --指定名稱 ? ?--指定主機
[root@node1?~]#?ccs_tool?addnode?-n 2 -f ?meatware?node2.xdl.com
[root@node1?~]#?ccs_tool?addnode?-n 3 -f ?meatware?node3.xdl.com
[root@node1?~]#?ccs_tool?lsnode--查詢節(jié)點
3.同步配置文件到各節(jié)點
cd?/etc/cluster
[root@node1?cluster]#?scp?cluster.conf ?node2:/etc/cluster/
[root@node1?cluster]#?scp?cluster.conf ?node3:/etc/cluster/
4.啟動各節(jié)點集群
node1:
[root@node1?cluster]#?service?cman?start
PS:啟動如果報錯關閉NetworkManager:
service NetworkManager stop
chkconfig NetworkManager off
如果關閉還報錯,則修改超時時間:
echo“CMAN_QUORUM_TIMEOUT=0”>>?/etc/sysconfig/cman
node2和node3不再贅述
CLVM安裝與配置(集群邏輯卷)
1.安裝cLVM
[root@target?~]#?han?ssh?node$O 'yum?install?-y lvm2-cluster';?done
2.啟用集群LVM
[root@target?~]#?han ssh?node$O 'lvmconf ?--enable-cluster';?done
3.查看一下啟用的集群LVM
PS:節(jié)點數(shù)最小不小于3個
[root@target?~]#?han ssh?node$O 'grep?"locking_type?=?3"?/etc/lvm/lvm.conf';?done
locking_type?=?3
locking_type?=?3
locking_type?=?3
4.啟動cLVM服務
[root@target?~]#?han ssh?node$O 'service?clvmd?start';?done
Starting?clvmd:
Activating?VG(s):??No?volume?groups?found
[確定]
Starting?clvmd:
Activating?VG(s):??No?volume?groups?found
[確定]
Starting?clvmd:
Activating?VG(s):??No?volume?groups?found
[確定]
5.將各節(jié)點的cman?rgmanger?clvmd設置為開機自啟動
[root@target?~]#?han ssh?node$O 'chkconfigclvmdon';?done
[root@target?~]#?han ssh?node$O 'chkconfig?cman?on';?done
[root@target?~]#?han ssh?node$O 'chkconfigrgmanageron';?done
6.在集群節(jié)點上創(chuàng)建lvm
node1:
(1).查看一下共享存儲
[root@node1?~]#?fdisk?-l ? ? #查看一下共享存儲
(2).創(chuàng)建集群邏輯卷
[root@node1?~]#?pvcreate?/dev/sdd#創(chuàng)建物理卷
[root@node1?~]#?vgcreate clustervg /dev/sdd ? ? #創(chuàng)建卷組
[root@node1?~]#?lvcreate?-L 10G -n clusterlv?clustervg#創(chuàng)建邏輯卷
7.在node2與node3上查看一下創(chuàng)建的邏輯卷
node2:
[root@node2?~]#?lvs
node3:
[root@node3?~]#?lvs
gfs2安裝與配置(全局文件系統(tǒng))執(zhí)行格式化操作等等
1.安裝gfs2
[root@target?~]#?han ssh?node$O ?'yum?install?-ygfs2-utils';?done
2.查看一下幫助文件
[root@node1?~]#?mkfs.gfs2?-h
注:對于用到的參數(shù)進行說明
-j?#指定日志區(qū)域的個數(shù),有幾個就能夠被幾個節(jié)點掛載
-J?#指定日志區(qū)域的大小,默認為128MB
-p?{lock_dlm|lock_nolock}
-t?:鎖表的名稱舒裤,格式為clustername: locktablename
3.格式化為集群文件系統(tǒng)
[root@node1?~]#?mkfs.gfs2?-j 2 -p lock_dlm -t testcluster:sharedstorage /dev/clustervg/clusterlv
注:testcluster是集群名稱,sharedstorage為鎖表名稱
4.創(chuàng)建掛載目錄并掛載
[root@node1?~]#?mkdir /mydata
[root@node1?~]#?mount?-t?gfs2?/dev/clustervg/clusterlv /mydata
5.將node2與node3進行掛載
node2:
[root@node2?~]#?mkdir/mydata
[root@node2?~]#?mount?-t?gfs2?/dev/clustervg/clusterlv?/mydata
注:node2成功掛載而node3沒有功功掛載觉吭,Too?many?nodes?mounting?filesystem,?no?free?journals腾供,沒有多于的日志空間。因為我們在格式化時只創(chuàng)建了2個日志文件鲜滩,所以node1與node2可以掛載伴鳖,而node3無法掛載
6.測試
1.查看是否能快速同步文件
node1:
[root@node1?mydata]#?touch123.txt
node2:
[root@node2?mydata]#?touch456.txt
2.查看掛載目錄的屬性
[root@node1?mydata]#?gfs2_tool?gettune /mydata
new_files_jdata?=?0 ? ? #最常用,設置是否立刻同步到磁盤的徙硅,一般設置為1榜聂,下面我們就來設置一下
[root@node1?mydata]#gfs2_tool?settune /mydata new_files_jdata1
[root@node1?mydata]#?gfs2_tool?gettune /mydata
3.查看一下日志文件
[root@node1?mydata]#?gfs2_tool?journals /mydata
journal1?-?128MB
journal0?-?128MB
2?journal(s)?found.
4.新增日志文件并掛載
[root@node1?~]#?gfs2_jadd?-j 1 /dev/clustervg/clusterlv
5.擴展集群邏輯卷
(1).先查看一下大小
[root@node3?~]#?lvs
LV????????VG????????Attr??????LSize??Pool?Origin?Data%??Move?Log?Cpy%Sync?Convert
clusterlv?clustervg?-wi-ao---?10.00g
注,現(xiàn)在是10個G嗓蘑,下面我們將其擴展到15G须肆。
(2).擴展物理邊界
[root@node3?~]#?lvextend?-L 15G /dev/clustervg/clusterlv
Extending?logical?volume?clusterlv?to?15.00?GiB
Logical?volume?clusterlv?successfully?resized
3).擴展邏輯邊界
[root@node3?~]#?gfs2_grow?/dev/clustervg/clusterlv