一、centos iscsi server
## (1)增加第二块硬盘
/dev/sdb
# (2)安装相关软件
yum install -y targetd targetctl scsi-target-utils targetcli
# (3)进行iscsi配置交互界面
targetcli
# (4)创建iSCSI target
cd /iscsi
ls
create wwn=iqn.2024-04.com.iscsi:server
# (5)创建ACLs(允许访问的iSCSI的client)
ls
cd iqn.2024-04.com.iscsi:server/tpg1/acls
create wwn=iqn.2024-04.com.iscsi:client
# (6)配置chap认证
cd iqn.2024-04.com.iscsi:client
set auth userid=username password=password
# (7)创建block backstores named sdb,sdc,sdd,sde
cd /backstores/block
create name=sdb dev=/dev/sdb
# (8)添加LUNs到iSCSI target
cd /iscsi/iqn.2024-04.com.iscsi:server/tpg1/luns
ls
create /backstores/block/sdb
# (9)修改portal
#cd /iscsi/iqn.2024-04.com.iscsi:server/tpg1/portals/
#delete 0.0.0.0 3260
#create 10.168.1.201 3260
# (10)退出保存
cd /
saveconfig
exit
# (11)重启iscsi服务
systemctl enable target
systemctl restart target
ubuntu 20.04 iscsi client
apt-get install -y open-iscsi
echo "InitiatorName=iqn.2024-04.com.iscsi:client" | sudo tee /etc/iscsi/initiatorname.iscsi
cat <<'EOF'> /etc/iscsi/iscsid.conf
iscsid.startup = /bin/systemctl start iscsid.socket
# 自动挂载
#node.startup = manual
node.startup = automatic
node.leading_login = No
node.session.auth.username = username
node.session.auth.password = password
node.session.timeo.replacement_timeout = 120
node.conn[0].timeo.login_timeout = 15
node.conn[0].timeo.logout_timeout = 15
node.conn[0].timeo.noop_out_interval = 5
node.conn[0].timeo.noop_out_timeout = 5
node.session.err_timeo.abort_timeout = 15
node.session.err_timeo.lu_reset_timeout = 30
node.session.err_timeo.tgt_reset_timeout = 30
node.session.initial_login_retry_max = 8
node.session.cmds_max = 128
node.session.queue_depth = 32
node.session.xmit_thread_priority = -20
node.session.iscsi.InitialR2T = No
node.session.iscsi.ImmediateData = Yes
node.session.iscsi.FirstBurstLength = 262144
node.session.iscsi.MaxBurstLength = 16776192
node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144
node.conn[0].iscsi.MaxXmitDataSegmentLength = 0
discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
node.session.nr_sessions = 1
node.session.reopen_max = 0
node.session.iscsi.FastAbort = Yes
node.session.scan = auto
EOF
# 发现与认证
iscsiadm --mode discovery --type sendtargets --portal 192.168.234.153 --discover
iscsiadm --mode node --portal 192.168.234.153 --login
# 查看是否连接成功
lsblk
# 格式化硬盘
apt install -y xfsprogs
mkfs.xfs /dev/sdb
# 创建挂载点/data
mkdir /data
# 添加内容到/etc/fstab
cat <<'EOF'>/etc/fstab
/dev/sdb /data xfs defaults,_netdev 0 0
EOF
参考