歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux管理 >> Linux配置

基於RHCS+iscsi+glvm構建IP SAN共享存儲配置

目的:
四台主機,rs1、rs2、rs3、target,rs1,rs2,rs3提供http服務,target主機把自己的磁盤做成IP SAN 的target供rs1,rs2,rs3使用

規劃:
rs1 172.16.1.11 hostname rs1.laoguang.me
rs2 172.16.1.12 hostname rs2.laoguang.me
rs3 172.16.1.13 hostname rs3.laoguang.me
target 172.16.1.14 hostname target.laoguang.me
VIP 172.16.1.1
  

一.先構建我們的RHCS高可用集群

准備工作:hostname設置,/etc/hosts下做好解析,ssh 互信,date統一,這是所有集群必須具備的。

1.1 配置准備工作.在rs1上演示,target不是高可用集群中的一個節點,可不配置,不過建議配置
配置hostname
hostname rs1.laoguang.me
vim /etc/hosts
172.16.1.11     rs1.laoguang.me rs1  
172.16.1.12     rs2.laoguang.me rs2  
172.16.1.13     rs3.laoguang.me rs3
172.16.1.14     target.laoguang.me      target

配置互信
ssh-keygen -t rsa -P ""    ##會生成密鑰在/root/.ssh下,公鑰拷貝到rs2的/root/.ssh/authorized_keys
ssh-copy-id -i /root/.ssh/id_rsa.pub rs2    ##rs1登錄rs2不再需要密碼
ssh-copy-id -i /root/.ssh/id_rsa.pub target

時間同步:(如果有NTP就同步NTP的時間)
date -s 20121127;ssh rs2 'date -s 20121127';ssh rs3 'date -s 20121127';\
ssh target 'date -s 20121127'

1.2 rs1,rs2,rs3安裝httpd
yum -y install httpd

建立測試頁面rs1,rs2,rs3上分別為
echo "<h1>RS1</h1>" > /var/www/html/index.html
echo "<h1>RS2</h1>" > /var/www/html/index.html
echo "<h1>RS3</h1>" > /var/www/html/index.html

啟動服務測試各各網站是否運行正常,如果正常繼續。
service httpd start

關閉httpd,並關閉的開機自啟動
service httpd stop
chkconfig httpd off

1.3 安裝RHCS套件需要的openais,cman,rgmanager,gfs2-utils(集群文件系統),system-config-cluster(此為GUI配置工具)
yum -y install cman rgmanager gfs2-utils

1.4 建立集群WebCluster
ccs_tool create WebCluster   ##會在/etc/cluster中生成cluster.conf集群的配置文件(xml格式)

1.5 加入node到WebCluster集群
ccs_tool addfence Manual fence_manual  ##RHCS需要先定義隔離設備
ccs_tool addnode -v 1 -n 1 -f Manual rs1.laoguang.me  ##加入rs1
ccs_tool addnode -v 1 -n 2 -f Manual rs2.laoguang.me  ##加入rs2
ccs_tool addnode -v 1 -n 3 -f Manual rs3.laoguang.me  ##加入rs3
-v 指定每個節點的票數
-n 指定節點ID
-f 指定fence設備

1.6 rs1,rs2,rs3上啟動cman
service cman start;     
##注:如果局域網內多台機器玩cman的話cman可能啟動不成功,其它機器可能是同步的其它主機的CIB
service rgmanager start; ##啟動rgmanager

1.7 啟動system-config-cluster 配置cluster ##由於cman的配置文件為xml格式,筆者還不會用
system-config-cluster

1.7.1 定義故障轉移域


1.7.2 定義IP資源與httpd資源                                                                     


 

httpd資源                                                                                    

                                                                               
1.7.3 定義服務                                                                                  

                                                                                   
查看集群狀態
clustat 
Cluster Status for WebCluster @ Wed Nov 28 18:38:19 2012                                    
Member Status: Quorate                                                                      
                                                                                            
Member Name                                     ID   Status                                 
------ ----                                     ---- ------                                 
rs1.laoguang.me                                     1 Online, rgmanager                     
rs2.laoguang.me                                     2 Online, rgmanager                     
rs3.laoguang.me                                     3 Online, Local, rgmanager              
                                                                                            
Service Name                           Owner (Last)                State                    
------- ----                           ----- ------                    -----                
service:WebService                     rs1.laoguang.me                 started
                                       
由此可知WebService在rs1上運行,訪問http://172.16.1.1測試                                        
                                                                   

二,target中安裝scsi-target-utils                                                                                                                                                            

2.1 安裝rpm包                                                                                                                                                                                   
yum -y install scsi-target-utils 
                                                         
                                                                                                
2.2 建立一2G分區,我建的是/dev/sda5  ##不要格式化,記得partprobe                                
                                                                                                
2.3 編輯配置文件/etc/tgt/targets.conf,添加一個target,如下
<target iqn.2012-11.me.laoguang.target:sda5>                                                
    backing-store /dev/sda5           ##後備存儲,一般指一個分區,或lvm設備             
    initiator-address 172.16.0.0/16   ##指定intiaor只能是這個地址范圍                   
    #direct-store /dev/sdb          ##直接存儲,通常指一個磁盤如/dev/sda5               
    #incominguser hadoop redhat    ##定義基於賬戶認證Initiator,後面的是賬號與密碼       
    #outgoinguser userA secretpassA  ##Initiator也可以驗證target,這個target的賬號密碼  
</target>                                                                               
##targetname 格式 iqn-name: iqn.yyyy-mm.<reversed domain name>[identifer]
我們也可以有命令行來配置,只不過重啟後會失效哦                                          
用法:tgtadm --lld [driver] --op [operation] --mode [mode] [OPTION]..                    
新增target:                                                                            
tgtadm --lld iscsi --op new --mode target --tid 1 --targetname iqn.2012-11.me.laoguang.target:sda5
tgtadm --lld iscsi --op show --mode target                                              
新增一localunit:                                                                        
tgtadm --lld -iscsi --op new --mode localunit --tid 1 --lun 1 --backing-store /dev/sda5
新增ACL允許172.16.0.0/16網段使用:                                                      
tgtadm --lld iscsi --op bind --tid 1 --initiator-address 172.16.0.0/16                  
新增賬戶認證:                                                                           
建立賬戶:                                                                              
tgtadm --lld iscsi --op new --mode account  --user hadoop --password redhat             
查看新建賬戶:                                                                           
tgtadm --lld iscsi --op show --mode account                                             
綁定賬戶到target:                                                                      
tgtadm --lld iscsi --op bind --mode account --tid 1 --user hadoop                       
查看target信息:                                                                         
tgtadm --lld iscsi --op show --mode target 
                                                                                    
2.4 啟動tgtd服務,驗證target是否分享出去
service tgtd start                                                                          
tgtadm --lld iscsi --op show --mode target                                                  
                                                                                            
    Target 1: iqn.2012-11.me.laoguang.target:sda5                                           
    System information:                                                                     
        Driver: iscsi                                                                       
        State: ready                                                                        
    I_T nexus information:                                                                  
    LUN information:                                                                        
        LUN: 0                                                                              
            Type: controller                                                                
            SCSI ID: IET     00010000                                                       
            SCSI SN: beaf10                                                                 
            Size: 0 MB, Block size: 1                                                       
            Online: Yes                                                                     
            Removable media: No                                                             
            Readonly: No                                                                    
            Backing store type: null                                                        
            Backing store path: None                                                        
            Backing store flags:                                                            
        LUN: 1                                                                              
            Type: disk                                                                      
            SCSI ID: IET     00010001                                                       
            SCSI SN: beaf11                                                                 
            Size: 1012 MB, Block size: 512                                                  
            Online: Yes                                                                     
            Removable media: No                                                             
            Readonly: No                                                                    
            Backing store type: rdwr                                                        
            Backing store path: /dev/sda5                                                   
            Backing store flags:                                                            
    Account information:                                                                    
    ACL information:                                                                        
        172.16.0.0/16
                                                                   
驗證正常,禁止tgt開機啟動
chkconfig tgtd off
                                                 

三,在rs1,rs2,rs3上安裝iscsi-initiator-utils

yum -y install iscsi-initator-utils ##很可能已經安裝了                                      
echo "InitiatorAlias=rs1" >> /etc/iscsi/initiatorname.iscsi  ##分別給個別名                 
echo "InitiatorAlias=rs2" >> /etc/iscsi/initiatorname.iscsi                                 
echo "InitiatorAlias=rs3" >> /etc/iscsi/initiatorname.iscsi 


3.1 啟動iscsi,發現共享磁盤target

service iscsi start                                                                         
iscsiadm -m discovery -t sendtargets -p 172.16.1.14   ##發現target                          
172.16.1.14:3260,1 iqn.2012-11.me.laoguang.target:sda5
                                                  
3.2 掛載(登錄)共享磁盤
iscsiadm -m node -T  iqn.2012-11.me.laoguang.target:sda5 -p 172.16.1.14 -l                  
-m 指定模式 man 一下                                                                        
-t sendtargets 在discovery模式下使用                                                        
-p portal 指定target的IP與端口,如果是默認端口3260可省略                                    
-l login  登錄                                                                              
-u logout 個為登出
fdisk -l   ##查看新磁盤我的是sda5
                                                                                           
rs1,rs2,rs3同樣登錄                                                                             
                                                                                                
禁止它們開機啟動
chkconfig iscsi off;chkconfig iscsid off

3.3 安裝lvm2-cluster,讓gfs2支持卷組
lvmconf --enable-cluster                                                                    
service clvmd start 

3.4 rs1上對/data/sdb創建lvm卷組
pvcreate /dev/sdb                                                                           
vgcreate myvg /dev/sdb                                                                      
lvcreate -L 800M --name mydata myvg

查看其它節點中是否生成了lvm
ls /dev/myvg/mydata

3.5 rs1,rs2,rs3啟動gfs2,在rs1中格式化gfs格式的磁盤
mkfs.gfs2 -p lock_dlm -t WebCluster:mylvm -j 3 /dev/myvg/mydata

3.6 rs1,rs2,rs3掛載/dev/myvg/mydata到/var/www/html中,建立測試文件
mount /dev/myvg/mydata /var/www/html                                                        
echo "GFS Storage" > /var/www/html/index.html

rs1,rs2同時打開/var/www/html/index.html 查看是否有上鎖警告                                                                                                                                     
訪問http://172.16.1.1查看是否能顯示新主頁
Copyright © Linux教程網 All Rights Reserved