iscsi(tgt)+librbd使用


title: iscsi(tgt)+librbd使用

1、前言

因?yàn)橐{(diào)試看下librbd的一個(gè)功能。然后準(zhǔn)備在自己的測(cè)試環(huán)境配置下iscsi+librbd,然后方便調(diào)試,這里記錄下大概過程。

這里是使用的tgt作為iscsi的target。具體什么是iscsi和iscsi有哪幾種target類型,google下就好。

1、ceph集群準(zhǔn)備

準(zhǔn)備一個(gè)標(biāo)準(zhǔn)三節(jié)點(diǎn)ceph集群:

[root@ceph01 ~]# ceph -v
ceph version 12.2.12 (1436006594665279fe734b4c15d7e08c13ebd777) luminous (stable)
[root@ceph01 ~]# 
[root@ceph01 ~]# 
[root@ceph01 ~]# ceph osd tree
ID CLASS WEIGHT  TYPE NAME       STATUS REWEIGHT PRI-AFF 
-1       0.08455 root default                            
-3       0.02917     host ceph01                         
 0   hdd 0.01459         osd.0       up  1.00000 1.00000 
 1   hdd 0.01459         osd.1       up  1.00000 1.00000 
-5       0.02818     host ceph02                         
 2   hdd 0.01459         osd.2       up  1.00000 1.00000 
 4   hdd 0.01360         osd.4       up  1.00000 1.00000 
-7       0.02719     host ceph03                         
 3   hdd 0.01360         osd.3       up  1.00000 1.00000 
 5   hdd 0.01360         osd.5       up  1.00000 1.00000

2、編譯tgtd

為啥要自己編譯,不直接使用yum install?因?yàn)橹苯觵um安裝的tgtd服務(wù)可能不包含rbd的功能模塊,也就不能使用librbd了。所以要自己編譯,在編譯的時(shí)候加入rbd的功能到tgtd服務(wù)里面。

2.1、獲取tgtd源碼包

下載地址:https://github.com/fujita/tgt/releases, 下載當(dāng)前最新的版本v1.0.76,并解壓:

[root@ceph01 ~]# tar -zxvf tgt-1.0.76.tar.gz

2.2、修改相關(guān)文件

為了把rbd功能編入tgtd服務(wù)里面,還要一些相關(guān)文件才行。

2.2.1、修改spec文件的如下內(nèi)容

[root@ceph01 ~]# vim tgt-1.0.76/scripts/tgtd.spec

...

Version:        1.0.76  # 修改版本為你下載的包的版本

...

%install
...
%{__install} -d %{buildroot}/etc/tgt
%{__install} -d %{buildroot}/usr/lib/tgt/backing-store  # 增加存放bs_rbd.so庫(kù)的目錄

...
%{__install} -p -m 0600 conf/targets.conf %{buildroot}/etc/tgt
%{__install} -p -m 0600 usr/bs_rbd.so %{buildroot}/usr/lib/tgt/backing-store    # 放置usr/bs_rbd.so到/usr/lib/tgt/backing-store目錄下

...

%files
...
/usr/lib/tgt/backing-store/bs_rbd.so    # 在該rpm包釋放的文件列表中增加bs_rbd.so文件
...

如果不加上面有關(guān)bs_rbd.so相關(guān)的文件,那制作出來的tgt包就不會(huì)包含bs_rbd.so文件,最后安裝的tgt包的后端存儲(chǔ)就不會(huì)支持rbd。

2.2.2、修改build-pkg.sh里面相關(guān)信息

下面的幾個(gè)信息,根據(jù)你下載的源碼版本而定:

[root@ceph01 ~]# vim tgt-1.0.76/scripts/build-pkg.sh
...
branch="master"
version="1.0.76"
release="1"
...

2.3、編譯tgtd

安裝依賴包(注意下面列出的依賴包,在我們編譯出tgtd的rpm包后,待安裝tgtd服務(wù)的目標(biāo)機(jī)器上也需要安裝這些依賴包)

[root@ceph01 ~]# yum install  librbd1-devel librados2-devel -y
[root@ceph01 ~]# yum install libxslt docbook-style-xsl libibverbs-devel librdmacm-devel libaio-devel -y

開始編譯,要設(shè)置CEPH_RBD變量為1,表示編譯時(shí)加入rbd的功能模塊

[root@ceph01 ~]# cd tgt-1.0.76
[root@ceph01 tgt-1.0.76]# make CEPH_RBD=1
make -C usr
make[1]: Entering directory `/root/tgt-1.0.76/usr'
cc -c -DUSE_SIGNALFD -DUSE_TIMERFD -DUSE_EVENTFD -D_GNU_SOURCE -I. -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -Werror -fPIC -DTGT_VERSION=\"1.0.76\" -DBSDIR=\"/usr/lib/tgt/backing-store\" iscsi/conn.c -o iscsi/conn.o
cc -c -DUSE_SIGNALFD -DUSE_TIMERFD -DUSE_EVENTFD -D_GNU_SOURCE -I. -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -Werror -fPIC -DTGT_VERSION=\"1.0.76\" -DBSDIR=\"/usr/lib/tgt/backing-store\" iscsi/param.c -o iscsi/param.o
cc -c -DUSE_SIGNALFD -DUSE_TIMERFD -DUSE_EVENTFD -D_GNU_SOURCE -I. -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -Werror -fPIC -DTGT_VERSION=\"1.0.76\" -DBSDIR=\"/usr/lib/tgt/backing-store\" iscsi/session.c -o iscsi/session.o
cc -c -DUSE_SIGNALFD -DUSE_TIMERFD -DUSE_EVENTFD -D_GNU_SOURCE -I. -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -Werror -fPIC -DTGT_VERSION=\"1.0.76\" -DBSDIR=\"/usr/lib/tgt/backing-store\" iscsi/iscsid.c -o iscsi/iscsid.o
cc -c -DUSE_SIGNALFD -DUSE_TIMERFD -DUSE_EVENTFD -D_GNU_SOURCE -I. -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -Werror -fPIC -DTGT_VERSION=\"1.0.76\" -DBSDIR=\"/usr/lib/tgt/backing-store\" iscsi/target.c -o iscsi/target.o
...

上面編譯過程沒有報(bào)錯(cuò)的話,繼續(xù)制作rpm安裝包,因?yàn)槭褂胷pm包來安裝,后期管理相關(guān)包時(shí)會(huì)方便很多:

[root@ceph01 tgt-1.0.76]# make rpm
Building version: 1.0.76-1
Creating rpm build dirs under /root/tgt-1.0.76/pkg
Creating tgz scsi-target-utils-1.0.76-1.tgz
Creating rpm
Wrote: /root/tgt-1.0.76/pkg/SRPMS/scsi-target-utils-1.0.76-1.src.rpm
Wrote: /root/tgt-1.0.76/pkg/RPMS/x86_64/scsi-target-utils-1.0.76-1.x86_64.rpm
Wrote: /root/tgt-1.0.76/pkg/RPMS/x86_64/scsi-target-utils-debuginfo-1.0.76-1.x86_64.rpm
Done.

3、安裝配置tgtd

安裝下上面編譯出來的rpm包:

[root@ceph01 tgt-1.0.76]# rpm -ivh /root/tgt-1.0.76/pkg/RPMS/x86_64/scsi-target-utils-1.0.76-1.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:scsi-target-utils-1.0.76-1       ################################# [100%]

啟動(dòng)tgtd服務(wù):

[root@ceph01 ~]# systemctl restart tgtd

檢查是否支持rbd:

[root@ceph01 ~]# tgtadm --lld iscsi --mode system --op show | grep rbd
    rbd (bsoflags sync:direct)

如果沒有rbd相關(guān)信息輸出,表示不支持rbd,請(qǐng)檢查相關(guān)編譯過程是否都正確。

準(zhǔn)備一個(gè)rbd:

[root@ceph01 ~]# rbd create img02 --size 10G

配置target:

[root@ceph01 ~]# cat /etc/tgt/conf.d/librbd.conf 
<target iqn.2019-04.com.example:cephrbd.img02>
    bs-type rbd
    backing-store rbd/img02
    initiator-address 192.168.0.0/16
</target>

重啟tgtd服務(wù):

systemctl restart tgtd

查看target是否正確啟用:

[root@ceph01 conf.d]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2019-04.com.example:cephrbd.img02
    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
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: rbd
            Backing store path: rbd/img02
            Backing store flags: 
    Account information:
    ACL information:
        192.168.0.0/16

好了,看到一切都正常,然后就可以到客戶端去發(fā)現(xiàn)、登陸和使用這個(gè)rbd設(shè)備了。

4、使用

來到另外一個(gè)節(jié)點(diǎn)client01,把我們剛剛配置的img02這個(gè)rbd設(shè)備掛載到我們的client01節(jié)點(diǎn)本地來使用。

4.1、安裝iscsi客戶端軟件

安裝并啟動(dòng)iscsi-initiator-utils服務(wù):

[root@client01 ~]# yum install iscsi-initiator-utils -y
[root@client01 ~]# systemctl start iscsid

4.2、發(fā)現(xiàn)目標(biāo)設(shè)備

有個(gè)小口訣就是先發(fā)現(xiàn)再登陸,最后再使用:

[root@client01 ~]# iscsiadm -m discovery -t st -p 192.168.10.20
192.168.10.20:3260,1 iqn.2019-04.com.example:cephrbd.img02

上面-m discovery參數(shù)是掃描iscsi服務(wù)端可用的存儲(chǔ)設(shè)備,-t st參數(shù)是執(zhí)行掃描操作的類型,-p 192.168.10.20參數(shù)為iscsi服務(wù)端的ip地址。

可以看到上面已經(jīng)發(fā)現(xiàn)了iqn.2019-04.com.example:cephrbd.img02這個(gè)設(shè)備,我們下面就開始登陸:

[root@client01 ~]# iscsiadm -m node -T iqn.2019-04.com.example:cephrbd.img02 -p 192.168.10.20 --login
Logging in to [iface: default, target: iqn.2019-04.com.example:cephrbd.img02, portal: 192.168.10.20,3260] (multiple)
Login to [iface: default, target: iqn.2019-04.com.example:cephrbd.img02, portal: 192.168.10.20,3260] successful.

登陸成功之后,就可以在本地看到這個(gè)設(shè)備了,也就是下面的sdd這個(gè)設(shè)備:

[root@client01 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 19.5G  0 part 
  ├─centos-root 253:0    0 17.5G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
sdc               8:32   0   20G  0 disk 
sdd               8:48   0   10G  0 disk 
sr0              11:0    1    4G  0 rom

好了,現(xiàn)在就可以像使用本地設(shè)備一樣使用這個(gè)sdd設(shè)備了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容