安装、配置和启用Ceph iSCSI gateway

版权声明:本文为博主原创文章,可以转载但必须注明出处。 https://blog.csdn.net/nirendao/article/details/83184715

本文介绍如何安装、配置和启用Ceph iSCSI gateway

要求:

  1. 已经有一套Luminous的Ceph集群(Ceph 12.2.x)

  2. 建议使用 2-4 台机器作为 iSCSI gateway nodes,目的是为了 Ceph iSCSI gateway HA.

  3. 关于 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服务一定能起来。

  1. 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的超时时间。

  1. 在线更改配置

    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’

  2. 更改配置文件 /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 chap=finix@lenovo/finix@lenovo 

注意:
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的用户名和密码写到该文件的合适的位置,见下:

[root@mymachine ~]# 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 = finix@lenovo
node.session.auth.password = finix@lenovo
# 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

[root@mymachine ~]# 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)

[root@mymachine ~]# 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

[root@mymachine ~]# 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

参考文献

猜你喜欢

转载自blog.csdn.net/nirendao/article/details/83184715