Ceph iscsi方案及环境搭建




方案1:Ceph iscsi gateway及tcmu-runner部署流程

本部署流程文档基于Centos 7.5云主机验证。

TCMU原理介绍:Linux LIO 与 TCMU 用户空间透传 – Lixiubo_Liuyuan.pdf

环境准备

  1. Ceph L版本可用集群
  2. 至少两台Centos7.5版本主机(云主机或物理机)作为iscsi gateway节点,可以与Ceph集群public网络互通,或者其他发行版,但内核版本需要4.16以上

 

RHEL/CentOS 7.5; Linux kernel v4.16 or newer; or the Ceph iSCSI client test kernel

If not using a distro kernel that contains the required Ceph iSCSI patches, then Linux kernel v4.16 or newer or the ceph-client ceph-iscsi-test branch must be used.

Warning: ceph-iscsi-test is not for production use. It should only be used for proof of concept setups and testing. The kernel is only updated with Ceph iSCSI patches. General security and bug fixes from upstream are not applied.

 

部署过程

小提示:两台iscsi gateway节点,如果是使用的云主机,可以先只部署一台,部署ok之后做个自定义镜像,再用自定义镜像创建一台,修改主机名和/etc/hosts文件及iscsi gateway配置即可复制出新的gateway节点。

整体步骤:

  1. 配置两台Centos7.5云主机的主机名,修改/etc/hosts,保证两边可通过主机名互通,本次部署主机名分别为tcmu、tcmu2,ip分别为192.168.0.6、192.168.0.7
  2. 在gateway节点安装ceph包(使用ceph-deploy或手工安装),参考:http://docs.ceph.com/docs/master/start/quick-rbd/#install-ceph
  3. 下载tcmu-runner源码并编译安装
  4. 下载并安装ceph-iscsi-config(rbdtargetgw)、cephiscsicli(rbdtargetapi及gwcli命令),以及相关依赖包

安装ceph包

# 在gateway节点添加Ceph公司内部源,或者添加官方源:yum install centos-release-ceph-luminous.noarch -y
$ ceph-deploy install --release luminous tcmu  # 及tcmu2,ceph-deploy节点需要修改/etc/hosts文件
$ ceph-deploy admin tcmu   # 及tcmu2,或者手工copy /etc/ceph目录到gateway节点
# 验证ceph命令是否正常,如ceph -s

安装tcmu-runner

$ git clone https://github.com/open-iscsi/tcmu-runner.git
$ yum -y install epel-release python-pip python-rbd python-devel python-crypto # 安装依赖包
cd tcmu-runner
$ cmake -Dwith-glfs=false -Dwith-qcow=false -DSUPPORT_SYSTEMD=ON -DCMAKE_INSTALL_PREFIX=/usr
make make install
$ systemctl daemon-reload
$ systemctl enable tcmu-runner   # 如报错,则手工copy service:cp tcmu-runner.service /lib/systemd/system,参考:https://github.com/open-iscsi/tcmu-runner#running-tcmu-runner
$ systemctl start tcmu-runner

安装ceph-iscsi-config

$ git clone https://github.com/open-iscsi/targetcli-fb; git clone https://github.com/open-iscsi/configshell-fb; git clone https://github.com/open-iscsi/rtslib-fb  ## 下载依赖包,targetcli可不装,用ceph-iscsi-cli代替
$ python setup.py install  # 在上述3个依赖包目录下执行安装命令,如有提示缺少相关包则手工pip install安装
$ git clone https://github.com/ceph/ceph-iscsi-config.git
$ python setup.py install # 在ceph-iscsi-config目录执行安装命令,如有提示缺少相关包则手工pip install安装
$ systemctl daemon-reload
$ systemctl enable rbd-target-gw  # 如提示错误,则手工copy service文件到/lib/systemd/system
$ systemctl start rbd-target-gw  # 注意需要先创建配置文件,否则配置文件创建完需要重启该服务

在所有gateway节点创建配置文件:

[root@tcmu ~]# cat /etc/ceph/iscsi-gateway.cfg
[config]
# name of the *.conf file. A suitable conf file allowing access to the ceph
# cluster from the gateway node is required.
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 crt/key files that are compatible for each gateway node (i.e. not
# locked to a specific node). SSL crt and key files *must* be called
# iscsi-gateway.crt and iscsi-gateway.key and placed in /etc/ceph 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 = 192.168.0.6, 192.168.0.7

安装ceph-iscsi-cli

$ git clone https://github.com/ceph/ceph-iscsi-cli.git
cd ceph-iscsi-cli
$ python setup.py install --install-scripts=/usr/bin # 在ceph-iscsi-cli目录执行安装命令,如有提示缺少相关包则手工pip install安装
cp usr/lib/systemd/system/rbd-target-api.service /lib/systemd/system
$ systemctl daemon-reload
$ systemctl enable rbd-target-api
$ systemctl start rbd-target-api

iscsi target配置

通过gwcli命令即可配置,过程请参考:http://www.zphj1987.com/2018/04/11/ceph-ISCSI-GATEWAY/

iscsi initiator配置

为了简化部署,可使用gateway节点作为initiator节点来测试功能,相关软件的安装及配置,iscsiadm操作过程请参考:http://www.zphj1987.com/2018/04/11/ceph-ISCSI-GATEWAY/

参考:

  1. http://docs.ceph.com/docs/master/rbd/iscsi-requirements/
  2. http://docs.ceph.com/docs/master/rbd/iscsi-target-cli-manual-install/
  3. http://docs.ceph.com/docs/master/rbd/iscsi-target-cli/
  4. http://www.zphj1987.com/2018/04/11/ceph-ISCSI-GATEWAY/

 

方案2:TGT+rbd backing store部署流程

本次测试在两台Centos7.5云主机上完成,分别为tcmu(192.168.0.6)、tcmu2(192.168.0.7)。

前提:一个可以正常创建卷的ceph L版本集群,TGT节点可以访问该集群。

安装TGT服务(target端)

Centos 7.5添加epel源,可以直接安装scsi-target-utils包(yum –enablerepo=epel -y install scsi-target-utils),但是这个包里的TGT不支持rbd backing store,所以还是要手工编译。

Debian 9发行版可能有tgt-rbd包可以用,https://packages.debian.org/stretch/tgt, https://packages.debian.org/stretch/tgt-rbd, 安装这两个包应该就可以了。

 

编译TGT

  1. 下载源码:wget https://github.com/fujita/tgt/archive/v1.0.73.tar.gz
  2. tar xzf v1.0.73.tar.gz; cd tgt-1.0.73; make; make install (如果make提示xsltproc command not found,需要先执行yum install libxslt -y安装依赖包)
  3. 启动tgtd服务,可以手工启动:/usr/sbin/tgtd -f,或者用systemctl start tgtd(实际测试过程中发现tgt源码目录tgt-1.0.73/scripts下的tgtd.service配置文件并不好用,启动会卡住,我这里是先安装了epel源的scsi-target-utils,然后make install替换掉二进制文件,就可以正常启动带rbd backing store的tgtd服务了)
  4. 检查是否支持rbd backing store:tgtadm –lld iscsi –op show –mode system | grep rbd,输出rbd (bsoflags sync:direct)表示支持。

 

部署iscsi initiator(initiator端)

这里为了方便,直接在节点tcmu2上部署initiator软件(与target端共用一个节点)。

参考http://www.zphj1987.com/2018/04/11/ceph-ISCSI-GATEWAY/ Linux的客户端连接部分即可,主要是安装iscsi-initiator-utils客户端软件,以及多路径软件device-mapper-multipath。

 

创建target及lun(target端)

先创建一个rbd卷:

之后在tcmu、tcmu2上执行相同命令:

$ tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2018-10.com.netease:cephtgt.target0  # 创建target
$ tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store disk2 --bstype rbd  # 将rbd卷作为lun添加到target,注意lun id要从1开始,0被tgt使用
$ tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL  # 配置ACL授权,ALL表示所有节点均可访问该target,也可以用CIDR限制某个网段访问

 

initiator连接到target(initiator端)

在tcmu2节点上执行:

$ iscsiadm -m discovery -t st -p tcmu  # 发现target
$ iscsiadm -m discovery -t st -p tcmu2
$ iscsiadm -m node -T iqn.2018-10.com.netease:cephtgt.target0 -l -p tcmu # 登录target
$ iscsiadm -m node -T iqn.2018-10.com.netease:cephtgt.target0 -l -p tcmu2

即可连接到target,查看映射到本机的iscsi卷:

[root@tcmu2 ~]# lsblk
NAME     MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda        8:0    0    1G  0 disk 
└─mpathc 252:0    0    1G  0 mpath
sdb        8:16   0    1G  0 disk 
└─mpathc 252:0    0    1G  0 mpath
[root@tcmu2 ~]# multipath -ll   # 查看多路径设备信息
mpathc (360000000000000000e00000000020001) dm-0 IET     ,VIRTUAL-DISK   
size=1.0G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=0 status=enabled
| - 10:0:0:1 sda 8:0  failed faulty running
-+- policy='service-time 0' prio=1 status=active
  `- 11:0:0:1 sdb 8:16 active ready running

使用/dev/mapper/mpathc设备即可访问rbd卷disk2,并且是多路径方式,tcmu节点上的tgtd服务异常或者网络异常、节点宕机,均可自动切换到tcmu2的tgtd进行正常的IO访问。

 

添加一个新的lun到target(target端)

先创建一个rbd卷:

在tcmu、tcmu2上分别执行:

$ tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store disk3 --bstype rbd  # 将rbd卷作为lun添加到target

 

initiator端发现新的lun(initiator端)

 

$ iscsiadm -m session -R  # 重新扫描所有已建立的target连接,发现新的lun及lun大小变动等信息更新

查看映射的iscsi卷方法同上。

 

initiator端登出

$ iscsiadm -m node -T iqn.2018-10.com.netease:cephtgt.target0 --logout # 先确保卷未使用
$ iscsiadm -m node -T iqn.2018-10.com.netease:cephtgt.target0 -o delete
$ iscsiadm -m node  # 查看所有保存的target记录(可能未login)

 

target端清理

$ tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 2  # 删除target id为1中的id为2的lun,先确保initiator端先logout
$ tgtadm --lld iscsi --mode target --op delete --tid 1  # 删除id为1的target
$ tgt-admin --show   # 查看所有target信息

配置持久化

通过配置文件实现target和initiator端重启后自动恢复相关配置和连接。

待补充

参考:

  1. http://www.zphj1987.com/2018/04/11/ceph-ISCSI-GATEWAY/
  2. https://jerry.red/300/%E5%88%9B%E5%BB%BA-iscsi-target-%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%92%8C-iscsi-initiator-%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%BF%9E%E6%8E%A5
  3. http://linux.vbird.org/linux_server/0460iscsi.php#initiator_exam

 

方案3:LIO+krbd/rbd-nbd实现iscsi target方案

LIO是内核态的iscsi target实现,支持多种backing store,但还不支持rbd,只能用krbd或者rbd-nbd方式先把rbd卷map成block device,之后再将映射的设备如/dev/rbdX或/dev/nbdX给LIO作为block backing store使用,并最终作为target导出给initiator使用。

TCMU是LIO的用户态实现,可直接支持rbd后端:Ceph iscsi gateway及tcmu-runner部署流程

LIO原理介绍:Linux LIO 与 TCMU 用户空间透传 – Lixiubo_Liuyuan.pdf

本次测试在两台Centos7.5云主机上完成,分别为tcmu(192.168.0.6)作为target节点、tcmu2(192.168.0.7)作为initiator节点。

前提:一个可以正常创建卷的ceph L版本集群,target节点可以访问该集群。

相关操作流程如下:

内核模块检查

一般内核都是默认加载的,如果没有加载可以手工modprobe加载上:

# lsmod | grep target_core_mod               
target_core_mod       340809  13 target_core_iblock,target_core_pscsi,iscsi_target_mod,target_core_file,target_core_user
crc_t10dif             12912  2 target_core_mod,sd_mod

 

安装targetcli客户端

# 在target节点(tcmu)上执行
$ git clone https://github.com/open-iscsi/targetcli-fb; git clone https://github.com/open-iscsi/configshell-fb; git clone https://github.com/open-iscsi/rtslib-fb  ## 下载包及依赖
$ python setup.py install  # 在上述3个目录下执行安装命令,targetcli-fb依赖后面两个包,如有提示缺少其他依赖包则手工pip install安装,或者从github上(pip命令需要安装python-pip rpm包)

 

进行target配置

首先要有一个rbd卷,这里已经create过一个vol3,1G大小,属于rbd pool。

然后在target(tcmu)节点上map这个rbd卷:

# 在target节点(tcmu)上执行
$ rbd map vol3  # 或者用rbd-nbd方式map也可以
$ rbd showmapped
id pool image snap device   
0  rbd  vol3  -    /dev/rbd0

之后将/dev/rbd0作为block设备给LIO使用。

在target(tcmu)节点执行targetcli命令:

$ targetcli
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
 /> cd /backstores/block
/backstores/blockls
o- block ...................................................................................................... [Storage Objects: 0]
/backstores/block> create name=rbd0 dev=/dev/rbd0 # 添加block后端
Created block storage object rbd0 using /dev/rbd0.
/backstores/blockls
o- block ...................................................................................................... [Storage Objects: 1]
 o- rbd0 .............................................................................. [/dev/rbd0 (1.0GiB) write-thru deactivated]
 o- alua ....................................................................................................... [ALUA Groups: 1]
 o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]/>
cd /iscsi/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.tcmu.x8664:sn.546f452bcfe2.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsils
o- iscsi .............................................................................................................. [Targets: 1]
 o- iqn.2003-01.org.linux-iscsi.tcmu.x8664:sn.546f452bcfe2 .............................................................. [TPGs: 1]
 o- tpg1 ................................................................................................. [no-gen-acls, no-auth]
 o- acls ............................................................................................................ [ACLs: 0]
 o- luns ............................................................................................................ [LUNs: 0]
 o- portals ...................................................................................................... [Portals: 1]
 o- 0.0.0.0:3260 ....................................................................................................... [OK]
/iscsicd iqn.2003-01.org.linux-iscsi.tcmu.x8664:sn.546f452bcfe2/tpg1/luns
/iscsi/iqn.20...fe2/tpg1/luns> create /backstores/block/rbd0
Created LUN 0.
/iscsi/iqn.20...fe2/tpg1/lunsls
o- luns .................................................................................................................. [LUNs: 1]
 o- lun0 .............................................................................. [block/rbd0 (/dev/rbd0) (default_tg_pt_gp)]
/iscsi/iqn.20...fe2/tpg1/lunscd ..
/iscsi/iqn.20...452bcfe2/tpg1set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1
Parameter demo_mode_write_protect is now '0'.
Parameter authentication is now '0'.
Parameter generate_node_acls is now '1'.
Parameter cache_dynamic_acls is now '1'./iscsi/iqn.20...452bcfe2/tpg1cd /
/> saveconfig
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json/> exit

 

initiator操作

与其他target方式相同,都是用iscsiadm工具连接到target,具体参考TGT+rbd backing store部署流程这篇文档中的操作流程。

# 在tcmu2节点执行
$ iscsiadm -m discovery -t st -p tcmu
$ iscsiadm -m node -T iqn.2018-10.com.netease:cephtgt.target0 -l -p tcmu
$ lsblk
NAME   MAJ:MIN RM SIZE RO TYPE  MOUNTPOINT
sda      8:0    0   1G  0 disk

 

多路径

RBD exclusive lock feature对多路径有影响,参考:https://www.sebastien-han.fr/blog/2017/01/05/Ceph-RBD-and-iSCSI/(第5节),只能是主备模式?这部分有待补充。