安裝、配置和啟用Ceph iSCSI gateway
本文介紹如何安裝、配置和啟用Ceph iSCSI gateway
要求:
-
已經有一套Luminous的Ceph叢集(Ceph 12.2.x)
-
建議使用 2-4 臺機器作為 iSCSI gateway nodes,目的是為了 Ceph iSCSI gateway HA.
-
關於 iSCSI gateway node:
1> iSCSI gateway node 既是一個 iSCSI target node,也是一個 Ceph client node.
2> iSCSI gateway node 可以是一個單獨的機器,也可以是一個 Ceph OSD node
3> 如果 iSCSI gateway node 是單獨的機器,那麼推薦配置下,它需要2個網路:
一個獨立的網路,為了gateway HA;另一個是 Ceph public network(因為 iSCSI gateway node 也是一個Ceph client node).
注意:
如果選擇獨立的機器作為iSCSI gateway node,那麼該機器不能是虛擬機器;否則難以將rbd-target-gw服務啟動起來,即使enable了一些iSCSI的核心模組,也不能保證rbd-target-gw服務一定能起來。
- iSCSI gateway node 的要求:
RHEL/CentOS 7.5; Linux kernel v4.16 or newer; 或者是 Ceph iSCSI client test kernel
實驗環境
基於以上的要求,在本實驗中:
a. Ceph cluster由3個節點組成,且是Monitor與OSD共存的collocated模式。
這種模式不是Red Hat的推薦配置,但是也可以work,社群對此並無特別要求。
RHCS的要求是:只能是容器化的Ceph部署才能夠讓monitor和OSD collocate;否則只推薦將monitor和OSD分別部署在不同的node上。
b. Ceph 版本是 Red Hat Ceph Storage 3.0 , 即 Ceph 12.2.4-42
作業系統選用的是 RHEL 7.5
核心是 3.10.0-862.2.3
c. 選取3臺機器作為 iSCSI gateway node, 即上述的3臺組成Ceph叢集的nodes.
Part 1. 配置Ceph叢集
在一個Ceph monitor node上,執行如下命令,目的是:延長檢測down掉的OSD的預設定時器時間,以減小nitiator的超時時間。
-
線上更改配置
ceph tell osd.* injectargs ‘–osd_heartbeat_interval 5’
ceph tell osd.* injectargs ‘–osd_heartbeat_grace 20’
ceph tell osd.* injectargs ‘–osd_client_watch_timeout 15’ -
更改配置檔案 /etc/ceph/ceph.conf
[osd]
osd heartbeat grace = 20
osd heartbeat interval = 5
Part 2. 配置所有的 iSCSI gateway nodes
2.1 安裝如下軟體
yum install -y tcmu-runner targetcli ceph-iscsi-config ceph-iscsi-tools ceph-iscsi-cli python-rtslib
注意:
這裡的一個坑是,不要安裝initiator上需要裝的軟體(見Part 3);否則的話,會導致在gateway node上也會有 iscsid 被啟動,進而導致:如果在gwcli中配置的target名稱和 /etc/iscsi/initiatorname.iscsi 中儲存的名稱不一致的話,就會引起initiator登入失敗。
2.2 建立名為 rbd 的 pool (如沒有)
官方文件中說這個pool是給iSCSI的配置存放類似metadata的資訊的;但是實際測下來,發現給initiator用的disk也是建立在這裡的。
ceph osd pool create rbd 32
ceph osd pool stats
ceph -s # 檢查是否所有PG都是active+clean的
2.3 建立一個新檔案 /etc/ceph/iscsi-gateway.cfg 並新增如下內容到其中:
[config]
# Name of the Ceph storage cluster. A suitable Ceph configuration file allowing
# access to the Ceph storage cluster from the gateway node is required, if not
# colocated on an OSD node.
cluster_name = ceph
# Place a copy of the ceph cluster's admin keyring in the gateway's /etc/ceph
# drectory and reference the filename here
gateway_keyring = ceph.client.admin.keyring
# API settings.
# The API supports a number of options that allow you to tailor it to your
# local environment. If you want to run the API under https, you will need to
# create cert/key files that are compatible for each iSCSI gateway node, that is
# not locked to a specific node. SSL cert and key files *must* be called
# 'iscsi-gateway.crt' and 'iscsi-gateway.key' and placed in the '/etc/ceph/' directory
# on *each* gateway node. With the SSL files in place, you can use 'api_secure = true'
# to switch to https mode.
# To support the API, the bear minimum settings are:
api_secure = false
# Additional API configuration options are as follows, defaults shown.
# api_user = admin
# api_password = admin
# api_port = 5001
trusted_ip_list = 10.240.41.182,10.240.41.183,10.240.41.184
這裡的 trusted_ip_list 裡面羅列的是各個iSCSI gateway node在 gateway 網路中的地址。
2.4 Enable並start API service
systemctl daemon-reload
systemctl enable rbd-target-api
systemctl start rbd-target-api
systemctl status rbd-target-api
systemctl status rbd-target-gw # 檢查 gateway service
這裡的rbd-target-api service是依賴於rbd-target-gw service. 但不需要先啟動後者,再啟動前者;而是在前者啟動的過程中,後者會被前者啟動。
2.5 使用 gwcli 工具進行配置
gwcli 可以配置 iSCSI target 和建立 RBD images,並能在gateway node之間同步配置。
底層的工具,如 targetcli 和 rbd,可以被用來查詢當前的配置,但不應該被用來改變配置。所有的配置改動都必須通過gwcli來做。
接下來演示如何建立一個 iSCSI target 並匯出一個 RBD image 作為 LUN 0.
a. 執行命令 gwcli
b. 執行命令 “ls /”, 你會看到一個目錄結構,可以使用 cd、pwd、info等命令進行操作或檢視。下圖是最終結果時的“ls /”的展示效果:
c. 建立 target
> /> cd /iscsi-target
> /iscsi-target> create iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw
d. 建立 gateway
> /iscsi-target> cd iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw/gateways
> /iscsi-target...-igw/gateways> create <node name of gateway node 1> 10.240.41.182
> /iscsi-target...-igw/gateways> create <node name of gateway node 2> 10.240.41.183
> /iscsi-target...-igw/gateways> create <node name of gateway node 3> 10.240.41.184
注意,如果你作業系統不是 RHEL或CentOS,又或者你使用的是測試版核心,那麼在上述命令末尾還要加上 skipchecks=true
e. 在 pool rbd 中建立一個disk
> /iscsi-target...-igw/gateways> cd /disks
> /disks> create pool=rbd image=disk_1 size=20G
auth chap=lenovo_finix/lenovo_finix
f. 在hosts目錄下建立一個目錄,代表initiator,其目錄名就是initiator的名字
注:在Initiator Node的 /etc/iscsi/initiatorname.iscsi 檔案中,可以查到initiator的名字
> /disks> cd /iscsi-target/iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw/hosts
> /iscsi-target...eph-igw/hosts> create iqn.2018-10.com.redhat:rh7-client
注意:
1> 在建立gateway的時候,填寫的是node name
2> 若本機的 /etc/hosts 檔案中的node name所對應的IP和建立gateway時候指定的IP不同,則下次執行 gwcli 命令的時候,會報錯“Key ERROR 403”
3> 若本機的 /etc/hosts 檔案中沒有其他gateway node的對應項,則在其他gateway node上執行 gwcli ls 命令的時候,不會顯示為 UP,因此建立disk也不會成功。
g. 設定initiator的 CHAP 的 usrename和password,如下:
> /iscsi-target...at:rh7-client> auth [email protected]/[email protected]
注意:
CHAP的使用者名稱和密碼的設定有其規則,必須符合該規則
h. 將磁碟加給該initiator
> /iscsi-target...at:rh7-client> disk add rbd.disk_1
Part 3. 配置iSCSI initiator node(s)
3.1 在initiator node上安裝如下軟體
yum install -y iscsi-initiator-utils device-mapper-multipath
3.2 啟動 multipathd service
mpathconf --enable --with_multipathd y
3.3 填寫 /etc/multipath.conf
devices {
device {
vendor "LIO-ORG"
hardware_handler "1 alua"
path_grouping_policy "failover"
path_selector "queue-length 0"
failback 60
path_checker tur
prio alua
prio_args exclusive_pref_bit
fast_io_fail_tmo 25
no_path_retry queue
}
}
3.4 reload multipathd
systemctl reload multipathd
3.5 配置 initiator 的檔案 /etc/iscsi/iscsi.conf
將在2.5節g中設定的CHAP的使用者名稱和密碼寫到該檔案的合適的位置,見下:
[[email protected] ~]# grep 'node.session.auth' /etc/iscsi/iscsid.conf
# To enable CHAP authentication set node.session.auth.authmethod
node.session.auth.authmethod = CHAP
node.session.auth.username = [email protected]
node.session.auth.password = [email protected]
# node.session.auth.username_in = xxx
# node.session.auth.password_in = xxx
3.6 iSCSI discovery and login
首先,iSCSI initiator需要發現target:
iscsiadm -m discovery -t st -p 10.240.41.182
在發現成功之後,就進行登入:
iscsiadm -m node -T iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw -l
然後,執行下列命令,可檢查到是否增加了新disk
[[email protected] ~]# iscsiadm -m session
tcp: [61] 10.240.41.182:3260,1 iqn.2018-10.com.lenovo.iscsi-gw:iscsi-gw (non-flash)
tcp: [62] 10.240.41.183:3260,2 iqn.2018-10.com.lenovo.iscsi-gw:iscsi-gw (non-flash)
tcp: [63] 10.240.41.184:3260,3 iqn.2018-10.com.lenovo.iscsi-gw:iscsi-gw (non-flash)
[[email protected] ~]# multipath -ll
3600140596193b663e504831a1bdfa8b5 dm-12 LIO-ORG ,TCMU device
size=10G features='1 queue_if_no_path' hwhandler='1 alua' wp=rw
|-+- policy='queue-length 0' prio=50 status=active
| `- 63:0:0:0 sdf 8:80 active ready running
|-+- policy='queue-length 0' prio=10 status=enabled
| `- 62:0:0:0 sde 8:64 active ready running
`-+- policy='queue-length 0' prio=10 status=enabled
`- 61:0:0:0 sdg 8:96 active ready running
[[email protected] ~]# fdisk -l
......
......
Disk /dev/mapper/3600140596193b663e504831a1bdfa8b5: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 65536 bytes