Centos7.2使用离线源配置ISCSI服务器

准备工作,安装好CentOS7.2系统,本次使用的镜像为

CentOS-7-x86_64-DVD-1511.iso

一、配置基础环境

1. 因为软件包在安装镜像中已有,所以先通过xftp或其它方式将安装镜像上传到安装好的CentOS系统中,创建镜像文件的挂载目录并挂载

[root@iscsi ~]# mkdir /mnt/os     创建镜像的挂载目录
[root@iscsi ~]# mount CentOS-7-x86_64-DVD-1511.iso /mnt/os/    对镜像进行挂载

2. 配置yum源

备份原有yum源配置文件到/opt目录下并删除原有yum源文件

[root@iscsi ~]# rm CentOS-7-x86_64-DVD-1511.iso /mnt/os/

3.编辑yum源配置文件

[root@iscsi ~]# vi /etc/yum.repos.d/CentOS-Base.repo 

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[centos]
name=centos
baseurl=file:///mnt/os/
gpgcheck=0
enabled=1

4. 清空yum缓存

[root@iscsi ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: centos repo
Cleaning up everything
Cleaning up list of fastest mirrors
[root@iscsi ~]# yum makecache
Loaded plugins: fastestmirror
centos                                                                                                                                                 | 3.6 kB  00:00:00     
(1/4): centos/group_gz                                                                                                                                 | 155 kB  00:00:00     
(2/4): centos/filelists_db                                                                                                                             | 2.9 MB  00:00:00     
(3/4): centos/primary_db                                                                                                                               | 2.8 MB  00:00:00     
(4/4): centos/other_db                                                                                                                                 | 1.2 MB  00:00:00     
Determining fastest mirrors
Metadata Cache Created

二、配置ISCSI

1. 安装targetcli

[root@iscsi ~]# yum install targetcli -y

2. 创建iscsi磁盘文件存放目录后,进入targetcli

[root@iscsi ~]# mkdir /var/lib/iscsi_disks/
[root@iscsi ~]# targetcli 
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> 

3.  进行iscsi相关配置

切换工作目录
/> cd backstores/fileio

创建iscsi共享磁盘文件,设置容量为100G
/backstores/fileio> create diskfile /var/lib/iscsi_disks/diskfile01.img 100G   
Created fileio diskfile with size 107374182400

切换工作目录
/backstores/fileio> cd /iscsi 

创建iqn号
/iscsi> create iqn.2021-07.xxx.com.smartmap:storage.target01

切换工作目录
/iscsi> cd iqn.2021-07.xxx.com.smartmap:storage.target01/tpg1/luns

创建lun
/iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/diskfile01

切换工作目录
/iscsi/iqn.20...t01/tpg1/luns> cd /iscsi/iqn.2021-07.xxx.com.smartmap:storage.target01/tpg1/portals/

删除默认接入IP
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260

配置新的接入IP(iscsi客户端连接iscsi使用的目标IP)
/iscsi/iqn.20.../tpg1/portals> create 10.250.0.150
    注意:这一步不加端口号的话为默认3260端口,如果需要修改配置,比如6000端口,则书写为
                                create 10.250.0.150 6000

4.配置iscsi认证

在客户端上查看iqn信息
[root@cvknode01 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1993-08.org.cas:01:192168000004


服务端切换工作目录
/iscsi/iqn.20.../tpg1/acls> cd /iscsi/iqn.2021-07.xxx.com.smartmap:storage.target01/tpg1/acls

服务端创建wwn  通过创建wwn可以实现客户端免认证
/iscsi/iqn.20...t01/tpg1/acls> create wwn=iqn.1993-08.org.cas:01:192168000004
Created Node ACL for iqn.1993-08.org.cas:01:192168000004
Created mapped LUN 0.

5. 服务端保存配置

/iscsi/iqn.20...t02/tpg1/acls> cd /
/> saveconfig 
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> 

6.重启iscsi服务并设置开机

三、、客户端连接

 至此,客户端已经可以发现iscsi磁盘并接入,且不限制客户端的ip地址、lun等参数,不需要认证

客户端发现iscsi共享存储
[root@cvknode01 ~]# iscsiadm -m discovery -t st -p 10.250.0.150
10.250.0.150:3260,1 iqn.2021-07.xxx.com.smartmap:storage.target01

客户端查看发现的共享存储
[root@cvknode01 ~]# iscsiadm -m node
10.250.0.150:3260,1 iqn.2021-07.xxx.com.smartmap:storage.target01

客户端连接共享存储
[root@cvknode01 ~]# iscsiadm -m node -T iqn.2021-07.xxx.com.smartmap:storage.target01 -p 10.250.0.150 -l
Logging in to [iface: default, target: iqn.2021-07.xxx.com.smartmap:storage.target01, portal: 10.250.0.150,3260] (multiple)
Login to [iface: default, target: iqn.2021-07.xxx.com.smartmap:storage.target01, portal: 10.250.0.150,3260] successful.

查看连接结果,sdb即是挂载好的共享存储,可以正常进行分区挂载等操作
[root@cvknode01 ~]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb      8:16   0   100G  0 disk 
sr0     11:0    1  1024M  0 rom  
nbd0    43:0    0   1.1G  1 disk 
sda      8:0    0 838.1G  0 disk 
├─sda4   8:4    0     1K  0 part 
├─sda2   8:2    0   200G  0 part /
├─sda5   8:5    0    40G  0 part /var/log
├─sda3   8:3    0  11.8G  0 part [SWAP]
├─sda1   8:1    0     1G  0 part /boot
└─sda6   8:6    0 585.4G  0 part /vms

客户端断开iscsi共享存储连接
[root@cvknode01 ~]# iscsiadm -m node -T iqn.2021-07.xxx.com.smartmap:storage.target01 -u
Logging out of session [sid: 25, target: iqn.2021-07.xxx.com.smartmap:storage.target01, portal: 10.250.0.150,3260]
Logout of [sid: 25, target: iqn.2021-07.xxx.com.smartmap:storage.target01, portal: 10.250.0.150,3260] successful.

再次lsblk查看,发现sdb已经消失
[root@cvknode01 ~]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  1024M  0 rom  
sda      8:0    0 838.1G  0 disk 
├─sda4   8:4    0     1K  0 part 
├─sda2   8:2    0   200G  0 part /
├─sda5   8:5    0    40G  0 part /var/log
├─sda3   8:3    0  11.8G  0 part [SWAP]
├─sda1   8:1    0     1G  0 part /boot
└─sda6   8:6    0 585.4G  0 part /vms





  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个小网工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值