iSCSI文件系统

一、iSCSI服务

二、iSCSI服务设置

 1.安装并开启服务

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

[root@server ~]# systemctl start target

[root@server ~]# systemctl status target

 2.新建分区  ##同步分区表

[root@server ~]# fdisk /dev/vdb

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     2099199     1048576   8e  Linux LVM

/dev/vdb2         2099200     6293503     2097152   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

帮助服务

/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/portals/

/iscsi/iqn.20.../tpg1/portals> help

客户端配置

 1.安装iscsi-initiator-utils

[root@client ~]# yum install iscsi-initiator-utils -y

 2.开启iscsid服务

[root@client ~]# systemctl stop firewalld.service

[root@client ~]# systemctl start iscsid

 3.查看108主机的共享硬盘

[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.181

172.25.254.181:3260,1 iqn.2018-05.com.westos:storagel

 4.链接108主机的硬盘  ##链接失败,没有key

[root@client ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storagel -p 172.25.254.181 -l

Logging in to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.181,3260] (multiple)

iscsiadm: Could not login to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.181,3260].

iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)

iscsiadm: Could not log into all portals

  

 5.修改key(服务端的加密key)

[root@client ~]# vim /etc/iscsi/initiatorname.iscsi

iqn.2018-05.com.westos:westoskey

  重启服务再次获得硬盘

[root@client ~]# systemctl restart iscsid.service

[root@client ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storagel -p 172.25.254.181 -l

Logging in to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.181,3260] (multiple)

Login to [iface: default, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.181,3260] successful.

  客户端可看到添加1个硬盘

[root@client ~]# fdisk -l

Disk /dev/sda: 2147 MB, 2147483648 bytes, 4194304 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/sda

[root@localhost ~]# mount /dev/sda /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@client ~]# virsh destroy desktop

Domain desktop destroyed

  开机后查看

[root@client ~]# df

Filesystem         1K-blocks    Used Available Use% Mounted on

/dev/vda1           10473900 3194712   7279188  31% /

devtmpfs              469344       0    469344   0% /dev

tmpfs                 484932     124    484808   1% /dev/shm

tmpfs                 484932   12840    472092   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/sda             2086912   33056   2053856   2% /mnt

还原设置

 1.取消永久挂载 /etc/fstab

 2.安装目录树服务  tree

 3.卸载硬盘   ##此时fdisk -l 已无/dev/sda硬盘

[root@client ~]# 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.181,3260]

Logout of [sid: 1, target: iqn.2018-05.com.westos:storage1, portal: 172.25.254.181,3260] successful.

  注意:重启iscsi服务,依然会自动挂载

[root@client ~]# systemctl restart iscsi

[root@client ~]# fdisk -l

Disk /dev/sda: 2147 MB, 2147483648 bytes, 4194304 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

[root@client ~]# df

Filesystem         1K-blocks    Used Available Use% Mounted on

/dev/vda1           10473900 3194712   7279188  31% /

devtmpfs              469344       0    469344   0% /dev

tmpfs                 484932     124    484808   1% /dev/shm

tmpfs                 484932   12840    472092   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/sda             2086912   33056   2053856   2% /mnt

 4.查看iscsi的树目录结构

yum install tree -y

[root@client ~]# tree /var/lib/iscsi/

/var/lib/iscsi/

├── ifaces

├── isns

├── nodes

   └── iqn.2018-05.com.westos:storagel

       └── 172.25.254.181,3260,1

           └── default

├── send_targets

   └── 172.25.254.181,3260

       ├── iqn.2018-05.com.westos:storagel,172.25.254.181,3260,1,default -> /var/lib/iscsi/nodes/iqn.2018-05.com.westos:storagel/172.25.254.181,3260,1

       └── st_config

├── slp

└── static

10 directories, 2 files

 5.删除iscsi树目录下的iqn.2018-05.com.westos:storagel

  iscsiadm -m node -T  iqn设备名 【-u(卸载)】【-o delete】

[root@client ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storagel -u

Logging out of session [sid: 4, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.181,3260]

Logout of [sid: 4, target: iqn.2018-05.com.westos:storagel, portal: 172.25.254.181,3260] successful.

[root@client ~]# iscsiadm -m node -T iqn.2018-05.com.westos:storagel -o delete

[root@client ~]# tree /var/lib/iscsi/

/var/lib/iscsi/

├── ifaces

├── isns

├── nodes

├── send_targets

   └── 172.25.254.181,3260

       └── st_config

├── slp

└── static

7 directories, 1 file

 6.再次重启iscsi,/dev/sda硬盘已移除

[root@client ~]# systemctl restart iscsi

[root@client ~]# fdisk -l | grep /dev/sda

 7.服务端删除共享硬盘  服务器

[root@server ~]# targetcli

targetcli shell version 2.1.fb34

Copyright 2011-2013 by Datera, Inc and others.

For help on commands, type 'help'.

/iscsi> 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]

猜你喜欢

转载自blog.csdn.net/period000/article/details/80623704
今日推荐