Configure iSCSI network storage under CentOS 7.x

  Copyright statement: This article is an original article by Shaon Puppet. Please indicate the original address for reprinting. Thank you very much. https://blog.csdn.net/wh211212/article/details/52981305

1. Introduction to iSCSI##

Two, experimental environment##

Operating system: CentOS Linux release 7.2.1511 (Core)
iSCSI Target:10.1.1.56 / vdevops.org
iSCSI Initiator:10.1.1.53 / linuxprobe.org
The firewall is closed/iptables: Firewall is not running.
SELINUX is disabled: SELINUX=disabled

Three, configure iSCSI Target

# Enter the management console
[ root@vdevops ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
# in/iscsi_disks/disk01.Use 2G to create a disk image named "disk01" on img
/> cd backstores/fileio 
/backstores/fileio> create disk01 /iscsi_disks/disk01.img 2G
Created fileio disk01 with size 2147483648/backstores/fileio> cd /iscsi 
# Create goals
/iscsi> create iqn.2016-10.vdevops.org:storage.target00
Created target iqn.2016-10.vdevops.org:storage.target00.
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.2016-10.vdevops.org:storage.target00/tpg1/luns 
# Set up luns
/iscsi/iqn.20...t00/tpg1/luns> create /backstores/fileio/disk01 
Created LUN 0./iscsi/iqn.20...t00/tpg1/luns> cd ../acls 
/iscsi/iqn.20...t00/tpg1/acls> create iqn.2016-10.vdevops.org:vdevops.org
Created Node ACL for iqn.2016-10.vdevops.org:vdevops.org
Created mapped LUN 0.
# Set ACL (it is the IQN of the initiator that is allowed to connect)
/iscsi/iqn.20...t00/tpg1/acls> cd iqn.2016-10.vdevops.org:vdevops.org/
# Set UserID for authentication
/iscsi/iqn.20...g:vdevops.org>set auth userid=username
Parameter userid is now 'username'./iscsi/iqn.20...g:vdevops.org>set auth password=password
Parameter password is now 'password'./iscsi/iqn.20...g:vdevops.org> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in/etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[ root@vdevops ~]# ss -napt | grep 3260
LISTEN     0256*:3260*:*[root@vdevops ~]# systemctl enable target
Created symlink from/etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.[root@vdevops ~]# firewall-cmd --add-service=iscsi-target --permanent
success
[ root@vdevops ~]# firewall-cmd --reload
success 
[1] Install scsi-target-utils.
# Install using EPEL source
[ root@vdevops ~]# yum --enablerepo=epel -y install scsi-target-utils 
[2] Configure the iSCSI target.
For example, in[/ iscsi_disks]Create a disk image under the directory and set it as a shared disk.
# Create a hard disk image
[ root@vdevops ~]# mkdir /iscsi_disks   #No need to recreate
[ root@vdevops ~]# dd if=/dev/zero of=/iscsi_disks/disk01.img count=0 bs=1 seek=2G  #No need to recreate
[ root@vdevops iscsi_disks]# vi /etc/tgt/targets.conf 
< target iqn.2016-10.vdevops.org:target00>
 # provided devicce as a iSCSI target
  #
 backing-store /iscsi_disks/disk01.img
 # iSCSI Initiator's IP address you allow to connect
  #
 initiator-address 10.1.1.53
 # authentication info(set anyone you like for"username","password")
  #
 incominguser username password
< /target>[3]If SElinux is enabled,Change SElinux type.[root@vdevops ~]# chcon -R -t tgtd_var_lib_t /iscsi_disks
[ root@vdevops ~]# semanage fcontext -a -t tgtd_var_lib_t /iscsi_disks
[4] If the firewall is enabled, allow iSCSI Target service
[ root@vdevops ~]# firewall-cmd --add-service=iscsi-target --permanent
success
[ root@vdevops ~]# firewall-cmd --reload
success 
[ root@vdevops ~]# systemctl start tgtd
[ root@vdevops ~]# systemctl status tgtd
● tgtd.service - tgtd iSCSI target daemon
 Loaded:loaded(/usr/lib/systemd/system/tgtd.service; disabled; vendor preset: disabled)
 Active:active(running) since Mon 2016-10-3120:46:10 CST; 7s ago
 Process:2860 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v ready(code=exited, status=0/SUCCESS)
 Process:2830 ExecStartPost=/usr/sbin/tgt-admin -e -c $TGTD_CONFIG(code=exited, status=0/SUCCESS)
 Process:2829 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v offline(code=exited, status=0/SUCCESS)
 Process:2828 ExecStartPost=/bin/sleep 5(code=exited, status=0/SUCCESS)
 Main PID:2827(tgtd)
 CGroup:/system.slice/tgtd.service
   └─2827/usr/sbin/tgtd -f

Oct 3120:46:04 vdevops.org systemd[1]: Starting tgtd iSCSI target daemon...
Oct 3120:46:04 vdevops.org tgtd[2827]: tgtd:iscsi_tcp_init_portal(347) unable to bind server socket, Address already in use
Oct 3120:46:04 vdevops.org tgtd[2827]: tgtd:iser_ib_init(3436) Failed to initialize RDMA; load kernel modules?
Oct 3120:46:04 vdevops.org tgtd[2827]: tgtd:work_timer_start(146) use timer_fd based scheduler
Oct 3120:46:04 vdevops.org tgtd[2827]: tgtd:bs_init_signalfd(267) could not open backing-store module directory /usr/lib64/tgt/backing-store
Oct 3120:46:04 vdevops.org tgtd[2827]: tgtd:bs_init(386) use signalfd notification
Oct 3120:46:10 vdevops.org tgtd[2827]: tgtd:device_mgmt(246) sz:29 params:path=/iscsi_disks/disk01.img
Oct 3120:46:10 vdevops.org tgtd[2827]: tgtd:bs_thread_open(408)16
Oct 3120:46:10 vdevops.org systemd[1]: Started tgtd iSCSI target daemon.
Hint: Some lines were ellipsized, use -l to show in full.[root@vdevops ~]# systemctl enable tgtd
Created symlink from/etc/systemd/system/multi-user.target.wants/tgtd.service to /usr/lib/systemd/system/tgtd.service.
# Check status
[ root@vdevops ~]# tgtadm --mode target --op show
Target 1: iqn.2016-10.world.srv:target00
 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:2147 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:/iscsi_disks/disk01.img
   Backing store flags: 
 Account information:
  username
 ACL information:10.1.1.53
# Install iscsi using EPEL-initiator-utils
[ root@linuxprobe ~]# yum -y install iscsi-initiator-utils 
[ root@linuxprobe ~]# vi /etc/iscsi/initiatorname.iscsi
# change to the same IQN you set on the iSCSI target server
InitiatorName=iqn.2016-10.vdevops.org:vdevops.org
[ root@linuxprobe ~]# vi /etc/iscsi/iscsid.conf
# line 57:Uncomment
node.session.auth.authmethod = CHAP
# line 61,62:Uncomment and specify the username and password you set on the iSCSI target server
node.session.auth.username = username
node.session.auth.password = password
# Found target
[ root@linuxprobe ~]# iscsiadm -m discovery -t sendtargets -p 10.1.1.5610.1.1.56:3260,1 iqn.2016-10.vdevops.org:storage.target00
[ root@linuxprobe ~]# iscsiadm -m node -o show
# BEGIN RECORD 6.2.0.873-33.2
node.name = iqn.2016-10.vdevops.org:storage.target00
node.tpgt =1
node.startup = automatic
node.leading_login = No
......
node.conn[0].iscsi.MaxXmitDataSegmentLength =0
node.conn[0].iscsi.MaxRecvDataSegmentLength =262144
node.conn[0].iscsi.HeaderDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD
# Login target
[ root@linuxprobe ~]# iscsiadm -m node --login
Logging in to [iface:default, target: iqn.2016-10.vdevops.org:storage.target00, portal:10.1.1.56,3260](multiple)
Login to [iface:default, target: iqn.2016-10.vdevops.org:storage.target00, portal:10.1.1.56,3260] successful.
# Confirm connection status
[ root@linuxprobe ~]# iscsiadm -m session -o show
tcp:[1]10.1.1.56:3260,1 iqn.2016-10.vdevops.org:storage.target00(non-flash)
# Confirm partition status
[ root@linuxprobe ~]# cat /proc/partitions
major minor  #blocks  name

 204 fd0
 8020971520 sda
 81512000 sda1
 8220458496 sda2
 1104228096 sr0
 253018317312 dm-025312097152 dm-18162097152 sdb
 # The new device added from the target server is &quot;sdb&quot;
# Create label
[ root@linuxprobe ~]# parted --script /dev/sdb "mklabel msdos"
# Create partition
[ root@linuxprobe ~]# parted --script /dev/sdb "mkpart primary 0% 100%"
# Format partition
[ root@linuxprobe ~]# mkfs.xfs -i size=1024-s size=4096/dev/sdb1
meta-data=/dev/sdb1              isize=1024   agcount=4, agsize=130560 blks
   =      sectsz=4096  attr=2, projid32bit=1=                       crc=0        finobt=0
data     =                       bsize=4096   blocks=522240, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2=                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
# Mount partition
[ root@linuxprobe ~]# mount /dev/sdb1 /mnt/
# View system mount
[ root@linuxprobe ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        18G  1.9G   16G  11% /
devtmpfs                devtmpfs  483M     0  483M   0%/dev
tmpfs                   tmpfs     493M     0  493M   0%/dev/shm
tmpfs                   tmpfs     493M  6.7M  487M   2%/run
tmpfs                   tmpfs     493M     0  493M   0%/sys/fs/cgroup
/dev/sda1               xfs       497M  125M  373M  26%/boot
tmpfs                   tmpfs      99M     0   99M   0%/run/user/0**/dev/sdb1               xfs       2.0G   33M  2.0G   2%/mnt**

At this point, we can see that the ISCSI configuration is complete and can be used normally.

Recommended Posts

Configure iSCSI network storage under CentOS 7.x
Configure lamp under centos6.8
Configure static IP under CentOS 7
Install and configure keepalived under CentOS 5.9
VMware Fusion install CentOS7 and configure the network
CentOS7.0 network configuration
CentOS 7.0 network configuration
Install MySQL 8.x from source code under CentOS7
CentOS6.5 network settings
Centos7 configure JDK
Install PHP in yum under CentOS, configure php-fpm service
Deploy GitBook under CentOS7
Linux Network Foundation (CentOS7)
Compile Hadoop-2.7.6 under CentOS7.4
Configure Ocserv on CentOS 6
Install mysql5.7 under CentOS7
Install ActiveMQ under Centos7
Install PostgreSQL12 under CentOS7
Install CentOS under VMware
Ubuntu configure network commands
Network configuration under Ubuntu
CentOS 6.X install VirtualBox-5.1
Deploy JDK+Tomcat8 under CentOS
Centos7 install mongodb 4.x
Install mysql under Centos 7
Centos7 configure IP address
Install Jenkins under Centos 7
Redis3 installation under Centos7
Install MariaDB under MariaDB Centos7
Install mysql5.1 under CentOS6.5
Centos7 configure nodejs environment
Configure CentOS7 GPU environment
CentOS 7 network settings --- connectivity
Set the network card to bridge mode under CentOS6.3 KVM