工作点滴/

Ubuntu Server 18.04安装iSCSI

2个方法均可实现,推荐tgt,感觉最简单(Target是服务器端,Initiator是客户端)
其余文章参考
https://www.ubuntubar.com/y2019/403.html
https://www.howtoforge.com/how-to-setup-iscsi-storage-server-on-ubuntu-1804/
https://blog.51cto.com/winterx/1414574

Configure iSCSI Target (targetcli)

Configure Storage Server with iSCSI.
A storage on a network is called iSCSI Target, a Client which connects to iSCSI Target is called iSCSI Initiator. This example is based on the environment below.

+----------------------+          |          +----------------------+
| [   iSCSI Target   ] |10.0.0.30 | 10.0.0.31| [ iSCSI Initiator  ] |
|     dlp.srv.world    +----------+----------+     www.srv.world    |
|                      |                     |                      |
+----------------------+                     +----------------------+

[1] Install administration tools first.

root@dlp:~# apt -y install targetcli-fb

[2] Configure iSCSI Target.
For example, create an disk-image under the [/var/lib/iscsi_disks] directory and set it as a SCSI device.

# create a directory
root@dlp:~# mkdir /var/lib/iscsi_disks 
# enter the admin console
root@dlp:~# targetcli 
targetcli shell version 2.1.fb43
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> cd backstores/fileio 

# create a disk-image with the name "disk01" on /var/lib/iscsi_disks/disk01.img with 10G
/backstores/fileio> create disk01 /var/lib/iscsi_disks/disk01.img 10G 
Created fileio disk01 with size 10737418240
/backstores/fileio> cd /iscsi 

# create a target
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
/iscsi> create iqn.2018-05.world.srv:dlp.target01 
Created target iqn.2018-05.world.srv:dlp.target01.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2018-05.world.srv:dlp.target01/tpg1/luns 

# set LUN
/iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk01 
Created LUN 0.
/iscsi/iqn.20...t01/tpg1/luns> cd ../acls 

# set ACL (it's the IQN of an initiator you permit to connect)
/iscsi/iqn.20...t01/tpg1/acls> create iqn.2018-05.world.srv:www.initiator01 
Created Node ACL for iqn.2018-05.world.srv:www.initiator01
Created mapped LUN 0.
/iscsi/iqn.20...t01/tpg1/acls> cd iqn.2018-05.world.srv:www.initiator01 

# set UserID for authentication
/iscsi/iqn.20...w.initiator01> set auth userid=username 
Parameter userid is now 'username'.
/iscsi/iqn.20...w.initiator01> set auth password=password 
Parameter password is now 'password'.
/iscsi/iqn.20...w.initiator01> exit 
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/rtslib-fb-target/backup.
Configuration saved to /etc/rtslib-fb-target/saveconfig.json

# after configuration above, the target enters in listening like follows
root@dlp:~# ss -napt | grep 3260 
LISTEN   0         256                 0.0.0.0:3260             0.0.0.0:* 

Configure iSCSI Target (tgt)

Configure Storage Server with iSCSI.
This is the case you use "tgt" for iSCSI Target.
A storage on a network is called iSCSI Target, a Client which connects to iSCSI Target is called iSCSI Initiator. This example is based on the environment below.

+----------------------+          |          +----------------------+
| [   iSCSI Target   ] |10.0.0.30 | 10.0.0.31| [ iSCSI Initiator  ] |
|     dlp.srv.world    +----------+----------+     www.srv.world    |
|                      |                     |                      |
+----------------------+                     +----------------------+

[1] Install administration tools first.

root@dlp:~# apt -y install tgt

[2] Configure iSCSI Target.
For example, create an disk-image under the [/var/lib/iscsi_disks] directory and set it as a SCSI device.

# create a disk-image
root@dlp:~# mkdir /var/lib/iscsi_disks 
root@dlp:~# dd if=/dev/zero of=/var/lib/iscsi_disks/disk01.img count=0 bs=1 seek=10G
[root@dlp ~]# vi /etc/tgt/conf.d/target01.conf
# create new
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
<target iqn.2018-05.world.srv:dlp.target01>
    # provided devicce as a iSCSI target
    backing-store /var/lib/iscsi_disks/disk01.img
    # iSCSI Initiator's IQN you allow to connect to this Target
    initiator-name iqn.2018-05.world.srv:www.initiator01
    # authentication info ( set any name you like for "username", "password" )
    incominguser username password
</target> 

root@dlp:~# systemctl restart tgt
# show status
root@dlp:~# tgtadm --mode target --op show 
Target 1: iqn.2018-05.world.srv:dlp.target01
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: rdwr
            Backing store path: /var/lib/iscsi_disks/disk01.img
            Backing store flags:
    Account information:
        username
    ACL information:
        ALL
        iqn.2018-05.world.srv:www.initiator01

碰到的问题

1.initiator-name iqn.2018-05.world.srv:www.initiator01;iSCSI发起程序名称要修改为iqn.2018-05.world.srv:www.initiator01,否则连接不上
也可以使用initiator-address 10.0.0.31;允许10.0.0.31的客户端连接
initiator-address All允许所有ip连接
2.incominguser username password中密码长度要在[12-16]字节,否则在实体机Windows10上,试图用iSCSI发起程序连接到远程的iSCSI存储,提示“CHAP密码不符合标准”。
15804-y23k9z6gkm.png
3.关闭防火墙:sudo ufw disable

Configure iSCSI Initiator

Configure iSCSI Initiator.
This example is based on the environment below.

+----------------------+          |          +----------------------+
| [   iSCSI Target   ] |10.0.0.30 | 10.0.0.31| [ iSCSI Initiator  ] |
|     dlp.srv.world    +----------+----------+     www.srv.world    |
|                      |                     |                      |
+----------------------+                     +----------------------+

[1] Configure iSCSI Initiator.

root@www:~# apt -y install open-iscsi
root@www:~# vi /etc/iscsi/initiatorname.iscsi
# change to the same IQN you set on the iSCSI target server
InitiatorName=iqn.2018-05.world.srv:www.initiator01
root@www:~# vi /etc/iscsi/iscsid.conf
# line 56: uncomment
node.session.auth.authmethod = CHAP
# line 60,61: uncomment and specify the username and password you set on the iSCSI target
node.session.auth.username = username
node.session.auth.password = password
root@www:~# systemctl restart iscsid open-iscsi
# discover target
root@www:~# iscsiadm -m discovery -t sendtargets -p 10.0.0.30 
10.0.0.30:3260,1 iqn.2018-05.world.srv:dlp.target01
# confirm status after discovery
root@www:~# iscsiadm -m node -o show 
# BEGIN RECORD 2.0-874
node.name = iqn.2018-05.world.srv:dlp.target01
node.tpgt = 1
node.startup = manual
node.leading_login = No
.....
.....
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD

# login to the target
root@www:~# iscsiadm -m node --login 
Logging in to [iface: default, target: iqn.2018-05.world.srv:dlp.target01, portal: 10.0.0.30,3260] (multiple)
Login to [iface: default, target: iqn.2018-05.world.srv:dlp.target01, portal: 10.0.0.30,3260] successful.

# confirm the established session
root@www:~# iscsiadm -m session -o show 
tcp: [1] 10.0.0.30:3260,1 iqn.2018-05.world.srv:dlp.target01 (non-flash)
# confirm the partitions
root@www:~# cat /proc/partitions 
major minor  #blocks  name

 252        0   31457280 sda
 252        1   31455232 sda1
 253        0   30441472 dm-0
 253        1     999424 dm-1
   8        0   10485760 sdb
# added new device provided from the target server as [sdb]

[2] After setting iSCSI devide, configure on Initiator to use it like follwos.

# create label
root@www:~# parted --script /dev/sdb "mklabel msdos" 
# create partiton
root@www:~# parted --script /dev/sdb "mkpart primary 0% 100%" 
# format with ext4
root@www:~# mkfs.ext4 /dev/sdb1 
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 2619392 4k blocks and 655360 inodes
Filesystem UUID: 841e57a2-b0d7-4431-945b-7e0ceb15b0f7
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

# mount device
root@www:~# mount /dev/sdb1 /mnt 
root@www:~# df -hT 
Filesystem                  Type      Size  Used Avail Use% Mounted on
udev                        devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                       tmpfs     395M  612K  394M   1% /run
/dev/mapper/ubuntu--vg-root ext4       29G  1.7G   26G   7% /
tmpfs                       tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs                       tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs                       tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs                       tmpfs     395M     0  395M   0% /run/user/0
/dev/sdb1                   ext4      9.8G   37M  9.3G   1% /mnt

win10中连接iSCSI服务(针对tgt)

打开:控制面板\所有控制面板项\管理工具\iSCSI 发起程序(复制到此电脑中也可打开)
实际路径为:%windir%\system32\iscsicpl.exe
开始菜单路径为:C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\iSCSI Initiator.lnk

如弹出Microsoft iSCSI服务尚未运行,请点击以开启服务(服务名称:Microsoft iSCSI Initiator Service)
如果上面target01.conf配置的是initiator-name连接方式,进入配置->更改,输入设置的initiator-name,确定(未设置忽略此步)
70031-v44b8w0xm5s.png

进入目标,输入服务器ip地址后点击快速连接(我这里服务器的ip是192.168.3.142)
60440-jpu70o5x39o.png

选择目标,点击连接,点击高级输入用户名和密码(如有设置),确定
79421-7u4n7zca9lk.png
16542-jv54lgvec9s.png

连接后的已发现的目标状态显示为已连接
打开:此电脑->管理->磁盘管理,会检测到新硬盘,弹出初始化磁盘窗口,格式化后即可

留下一条评论

暂无评论