(26) iSCSI服务
一、iSCSI服务

二、iSCSI服务设置

 1.安装并开启服务
[root@localhost ~]# yum install targetcli -y
[root@localhost ~]# systemctl start target
[root@localhost ~]# systemctl status target

 2.新建分区  ##同步分区表
[root@localhost ~]# fdisk /dev/vdb
 Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     1026047      512000   8e  Linux LVM
/dev/vdb2         1026048     3123199     1048576   83  Linux

 3.配置iSCSI
[root@localhost ~]# targetcli
/> ls   ##蓝色是目录,紫色是文件
/> /backstores/block create westos:storagel /dev/vdb2    ##命名并关联设备
Created block storage object westos:storagel using /dev/vdb2.
/> /iscsi create iqn.2018-05.com.westos:storagel   ##设定IQN
Created target iqn.2018-05.com.westos:storagel.
Created TPG 1.
/> /iscsi/iqn.2018-05.com.westos:storagel/tpg1/acls create iqn.2018-05.com.westos:westoskey  ##设置密码
Created Node ACL for iqn.2018-05.com.westos:westoskey
/> /iscsi/iqn.2018-05.com.westos:storagel/tpg1/luns create /backstores/block/westos:storagel   ##关联westos:storagel
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-05.com.westos:westoskey
/> /iscsi/iqn.2018-05.com.westos:storagel/tpg1/portals create 172.25.254.108
Using default IP port 3260   ##打开接口
Created network portal 172.25.254.108:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

客户端配置

 1.安装iscsi-initiator-utils
 
 2.开启iscsid服务

 3.查看108主机的共享硬盘
[root@localhost ~]# iscsiadm -m discovery -t st -p 172.25.254.108
172.25.254.108:3260,1 iqn.2018-05.com.westos:storagel

 4.链接108主机的硬盘  ##链接失败,没有key
[root@localhost ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storagel -p 172.25.254.108 -l
Logging in to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.108,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.108,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals
 
 5.修改key(服务端的加密key)
[root@localhost ~]# vim /etc/iscsi/initiatorname.iscsi

  重启服务再次获得硬盘
[root@localhost ~]# systemctl restart iscsid.service
[root@localhost ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storagel -p 172.25.254.108 -l
Logging in to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.108,3260] (multiple)
Login to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.108,3260] successful.

  客户端可看到添加1个硬盘
[root@localhost ~]# fdisk -l
Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes

  对/dev/sda硬盘分区、格式化、挂载
[root@localhost ~]# fdisk /dev/sda
[root@localhost ~]# mkfs.xfs /dev/sda1
[root@localhost ~]# mount /dev/sda1 /mnt
[root@localhost ~]# df
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3193680   7280220  31% /
devtmpfs              469344       0    469344   0% /dev
tmpfs                 484932      80    484852   1% /dev/shm
tmpfs                 484932   12832    472100   3% /run
tmpfs                 484932       0    484932   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2368    451811   1% /home
/dev/sda1            1041068   33056   1008012   4% /mnt

三、iSCSI管理

 1.客户端永久挂载 /etc/fstab ##注意:先开启服务,再加载网络
/dev/sda1       /mnt    xfs     defaults,_netdev 0 0
  重启后会出错,需要强制关闭,再开启服务端
[root@foundation8 ~]# virsh destroy desktop
Domain desktop destroyed
  开机后查看
[root@108local ~]# df
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3186972   7286928  31% /
devtmpfs              469344       0    469344   0% /dev
tmpfs                 484932      84    484848   1% /dev/shm
tmpfs                 484932   12808    472124   3% /run
tmpfs                 484932       0    484932   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2339    451840   1% /home
/dev/sda1            1041068   33056   1008012   4% /mnt
/dev/sr0             3654720 3654720         0 100% /run/media/root/RHEL-7.0 Server.x86_64

还原设置
 1.取消永久挂载 /etc/fstab
 2.安装目录树服务  tree
 3.卸载硬盘   ##此时fdisk -l 已无/dev/sda硬盘
[root@108local ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storage1 -u
Logging out of session [sid: 1, target: iqn.2018-05.com.westos:storage1, portal: 172.25.254.208,3260]
Logout of [sid: 1, target: iqn.2018-05.com.westos:storage1, portal: 172.25.254.208,3260] successful.
  注意:重启iscsi服务,依然会自动挂载
[root@108local ~]# systemctl restart iscsi
[root@108local ~]# fdisk -l

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk label type: dos
Disk identifier: 0xb08b3a8c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1

[root@108local ~]# df
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3187032   7286868  31% /
devtmpfs              469344       0    469344   0% /dev
tmpfs                 484932     124    484808   1% /dev/shm
tmpfs                 484932   12808    472124   3% /run
tmpfs                 484932       0    484932   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2339    451840   1% /home
/dev/sr0             3654720 3654720         0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/sda1            1041068   33056   1008012   4% /mnt

 4.查看iscsi的树目录结构
[root@108local ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2018-05.com.westos:storage1
│       └── 172.25.254.208,3260,1
│           └── default
├── send_targets
│   └── 172.25.254.208,3260
│       ├── iqn.2018-05.com.westos:storage1,172.25.254.208,3260,1,default -> /var/lib/iscsi/nodes/iqn.2018-05.com.westos:storage1/172.25.254.208,3260,1
│       └── st_config
├── slp
└── static

 5.删除iscsi树目录下的iqn.2018-05.com.westos:storage1
  iscsiadm -m node -T  iqn设备名 【-u(卸载)】【-o delete】

[root@108local ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storage1 -u
Logging out of session [sid: 3, target: iqn.2018-05.com.westos:storage1, portal: 172.25.254.208,3260]
Logout of [sid: 3, target: iqn.2018-05.com.westos:storage1, portal: 172.25.254.208,3260] successful.
[root@108local ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storage1 -o delete

[root@108local ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
│   └── 172.25.254.208,3260
│       └── st_config
├── slp
└── static

 6.再次重启iscsi,/dev/sda硬盘已移除
[root@108local ~]# systemctl restart iscsi
[root@108local ~]# fdisk -l

 7.服务端删除共享硬盘
[root@localhost ~]# targetcli
/> help   ##查看相关命令帮助

AVAILABLE COMMANDS
==================
The following commands are available in the
current path:

  - bookmarks action [bookmark]
  - cd [path]
  - clearconfig [confirm]
  - exit
  - get [group] [parameter...]
  - help [topic]
  - ls [path] [depth]
  - pwd
  - refresh
  - restoreconfig [savefile] [clear_existing]
  - saveconfig [savefile]
  - sessions [action] [sid]
  - set [group] [parameter=value...]
  - status
  - version

/> clearconfig confirm=true
All configuration cleared
/> ls
o- / ..................................................................... [...]
  o- backstores .......................................................... [...]
  | o- block .............................................. [Storage Objects: 0]
  | o- fileio ............................................. [Storage Objects: 0]
  | o- pscsi .............................................. [Storage Objects: 0]
  | o- ramdisk ............................................ [Storage Objects: 0]
  o- iscsi ........................................................ [Targets: 0]
  o- loopback ..................................................... [Targets: 0]
 







阅读更多
想对作者说点什么? 我来说一句

iscsi客户端自动安装包

2013年03月02日 1.56MB 下载

suse iscsi 安装配置指导

2012年04月23日 1.8MB 下载

精简xp安装 iSCSI 补丁

2009年09月05日 3.05MB 下载

没有更多推荐了,返回首页

不良信息举报

(26) iSCSI服务

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭