服务器端安装配置//安装iscsi服务#yum -y install targetcli//创建目录以便于设置共享#mkdir /iscsi_iso //进入进入管理控制台#targetcli/> cd backstores/fileio/backstores/fileio> create iso /iscsi_iso/iso.img 2G Created fileio iso with size 2147483648 //创建目标/backstores/fileio> cd /iscsi注意:命名在同一子网内确保是唯一的,命名格式为:iqn.yyyy-mm. <主机名反写> :自定义名称(自定义名称内不能有下划线)创建一个客户的iqn. 这里的iqn是客户端的名字可以自己自定义/iscsi> create iqn.2018-07.icee.cn:isoCreated target iqn.2018-07.icee.cn:iso.Created TPG 1.Global pref auto_add_default_portal=trueCreated default portal listening on all IPs (0.0.0.0), port 3260.//设定luns,也就是绑定访问的磁盘,也就是第一步创建的磁盘镜像的名称/iscsi> cd iqn.2018-07.icee.cn:iso/tpg1/luns /iscsi/iqn.20...iso/tpg1/luns> create /backstores/fileio/isoCreated LUN 0. //创建acls,允许访问的iqn或者说允许访问的客户端/iscsi/iqn.20...iso/tpg1/luns> cd ../acls /iscsi/iqn.20...iso/tpg1/acls> create iqn.2018-07.icee.cn:isoCreated Node ACL for iqn.2018-07.icee.cn:isoCreated mapped LUN 0.//在这里有一个步骤设置可以多台客户端共同访问:添加一条新的acls 也是另外一台客户端的iqn /iscsi/iqn.20...iso/tpg1/acls>create iqn.1998-01.com.vmware:5b16a947-1b34-c8ce-b854-b82a72dc11f2-4679e709 //我这里添加的是自己将要准备共享给esxi的共享iscsi,当然你也可以给其他的iqn同理 //设置ACL(客户端连接的IQN)这里可以不设置验证密码。/iscsi/iqn.20...iso/tpg1/acls> cd iqn.2018-07.icee.cn:iso/iscsi/iqn.20...7.icee.cn:iso> set auth userid=usernameParameter userid is now 'username'./iscsi/iqn.20...7.icee.cn:iso> set auth password=passwordParameter password is now 'password'./iscsi/iqn.20...7.icee.cn:iso> exitGlobal pref auto_save_on_exit=trueLast 10 configs saved in /etc/target/backup/.Configuration saved to /etc/target/saveconfig.json //查看防火墙设置,或者关闭防火墙。# ss -napt | grep 3260 查看端口LISTEN 1 256 *:3260 #firewall-cmd --add-port 3260/tcp --permanent //在防火墙上开启相应的端口//开启target服务systemctl start target//设置开机自行启动systemctl enable target 主机名反写>
//接下来我们设置客户端配置。//安装客户端的服务yum -y install iscsi-initiator-utils 修改iqn改成自定义的,当然你先安装客户端的时候可以使用客户端给的vi /etc/iscsi/initiatorname.iscsiInitiatorName=iqn.2018-07.icee.cn:isovi /etc/iscsi/iscsid.conf//取消以下注释:node.session.auth.authmethod = CHAPnode.session.auth.username = usernamenode.session.auth.password = passwordsystemctl restart iscsisystemctl enable iscsi//发现target[root@localhost ~]# iscsiadm -m discovery -t sendtargets -p 172.18.0.109172.18.0.109:3260,1 iqn.2018-07.icee.cn:iso[root@localhost ~]# iscsiadm -m node -o show# BEGIN RECORD 6.2.0.874-7node.name = iqn.2018-07.icee.cn:isonode.tpgt = 1node.startup = automaticnode.leading_login = Noiface.hwaddress = iface.ipaddress = iface.iscsi_ifacename = defaultiface.net_ifacename = iface.gateway = iface.subnet_mask = iface.transport_name = tcpiface.initiatorname = iface.state = iface.vlan_id = 0iface.vlan_priority = 0iface.vlan_state = iface.iface_num = 0iface.mtu = 0iface.port = 0iface.bootproto = iface.dhcp_alt_client_id_state = iface.dhcp_alt_client_id = iface.dhcp_dns = iface.dhcp_learn_iqn = iface.dhcp_req_vendor_id_state = iface.dhcp_vendor_id_state = iface.dhcp_vendor_id = iface.dhcp_slp_da = iface.fragmentation = iface.gratuitous_arp = iface.incoming_forwarding = iface.tos_state = iface.tos = 0iface.ttl = 0iface.delayed_ack = iface.tcp_nagle = iface.tcp_wsf_state = iface.tcp_wsf = 0iface.tcp_timer_scale = 0iface.tcp_timestamp = iface.redirect = iface.def_task_mgmt_timeout = 0iface.header_digest = iface.data_digest = iface.immediate_data = iface.initial_r2t = iface.data_seq_inorder = iface.data_pdu_inorder = iface.erl = 0iface.max_receive_data_len = 0iface.first_burst_len = 0iface.max_outstanding_r2t = 0iface.max_burst_len = 0iface.chap_auth = iface.bidi_chap = iface.strict_login_compliance = iface.discovery_auth = iface.discovery_logout = node.discovery_address = 172.18.0.109node.discovery_port = 3260node.discovery_type = send_targetsnode.session.initial_cmdsn = 0node.session.initial_login_retry_max = 8node.session.xmit_thread_priority = -20node.session.cmds_max = 128node.session.queue_depth = 32node.session.nr_sessions = 1node.session.auth.authmethod = CHAPnode.session.auth.username = node.session.auth.password = node.session.auth.username_in = node.session.auth.password_in = node.session.timeo.replacement_timeout = 120node.session.err_timeo.abort_timeout = 15node.session.err_timeo.lu_reset_timeout = 30node.session.err_timeo.tgt_reset_timeout = 30node.session.err_timeo.host_reset_timeout = 60node.session.iscsi.FastAbort = Yesnode.session.iscsi.InitialR2T = Nonode.session.iscsi.ImmediateData = Yesnode.session.iscsi.FirstBurstLength = 262144node.session.iscsi.MaxBurstLength = 16776192node.session.iscsi.DefaultTime2Retain = 0node.session.iscsi.DefaultTime2Wait = 2node.session.iscsi.MaxConnections = 1node.session.iscsi.MaxOutstandingR2T = 1node.session.iscsi.ERL = 0node.session.scan = autonode.conn[0].address = 172.18.0.109node.conn[0].port = 3260node.conn[0].startup = manualnode.conn[0].tcp.window_size = 524288node.conn[0].tcp.type_of_service = 0node.conn[0].timeo.logout_timeout = 15node.conn[0].timeo.login_timeout = 15node.conn[0].timeo.auth_timeout = 45node.conn[0].timeo.noop_out_interval = 5node.conn[0].timeo.noop_out_timeout = 5node.conn[0].iscsi.MaxXmitDataSegmentLength = 0node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144node.conn[0].iscsi.HeaderDigest = Nonenode.conn[0].iscsi.IFMarker = Nonode.conn[0].iscsi.OFMarker = No# END RECORD//登录target[root@localhost ~]# iscsiadm -m node --loginLogging in to [iface: default, target: iqn.2018-07.icee.cn:iso, portal: 172.18.0.109,3260] (multiple)Login to [iface: default, target: iqn.2018-07.icee.cn:iso, portal: 172.18.0.109,3260] successful.//确认连接状态[root@localhost ~]# iscsiadm -m session -o showtcp: [5] 172.18.0.109:3260,1 iqn.2018-07.icee.cn:iso (non-flash)//确认分区状况[root@localhost iso]# cat /proc/partitionsmajor minor #blocks name 8 0 209715200 sda 8 1 1048576 sda1 8 2 152171520 sda2 8 3 52428800 sda3 8 4 1 sda4 8 5 4063232 sda5 11 0 1048575 sr0 8 16 2097152 sdb//新建分区[root@localhost ~]# fdisk /dev/sdb欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。Device does not contain a recognized partition table使用磁盘标识符 0xebbdff66 创建新的 DOS 磁盘标签。命令(输入 m 获取帮助):nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): p分区号 (1-4,默认 1):起始 扇区 (8192-4194303,默认为 8192):将使用默认值 8192Last 扇区, +扇区 or +size{K,M,G} (8192-4194303,默认为 4194303):将使用默认值 4194303分区 1 已设置为 Linux 类型,大小设为 2 GiB命令(输入 m 获取帮助):sBuilding a new Sun disklabel.分区 1 已设置为 Linux native 类型,大小设为 2 GiB分区 2 已设置为 Linux swap 类型,大小设为 48.7 MiB分区 3 已设置为 Whole disk 类型,大小设为 2 GiB命令(输入 m 获取帮助):wThe partition table has been altered!Calling ioctl() to re-read partition table.正在同步磁盘。[root@localhost ~]#//格式化分区[root@localhost ~]# mkfs.ext4 /dev/sdb1mke2fs 1.42.9 (28-Dec-2013)文件系统标签=OS type: Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=1024 blocks128000 inodes, 511461 blocks25573 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=52428800016 block groups32768 blocks per group, 32768 fragments per group8000 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: 完成正在写入inode表: 完成Creating journal (8192 blocks): 完成Writing superblocks and filesystem accounting information: 完成//挂载分区mkdir /isomount /dev/sdb1 /iso查看是否挂载上去了还有磁盘类型[root@localhost ~]# df -hT文件系统 类型 容量 已用 可用 已用% 挂载点/dev/sda3 ext4 50G 1.1G 46G 3% /devtmpfs devtmpfs 1.9G 0 1.9G 0% /devtmpfs tmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs tmpfs 1.9G 8.9M 1.9G 1% /runtmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 ext4 976M 104M 806M 12% /boot/dev/sda2 ext4 143G 61M 136G 1% /hometmpfs tmpfs 380M 0 380M 0% /run/user/0/dev/sdb1 ext4 1.9G 5.9M 1.8G 1% /iso查看/dev/sdb1 的uuid[root@localhost ~]# blkid /dev/sdb1/dev/sdb1: UUID="f3072c49-b159-46e9-b0cd-83cae896c57c" TYPE="ext4"在/etc/fstab中添加UUID=f3072c49-b159-46e9-b0cd-83cae896c57c /iso ext4 _netdev 0 0自动连接 iscsi# iscsiadm -m node -T iqn.2017-05.com.mwdserver:iscsimwd1 -p192.168.13.30:3260 -o update -n node.startup -v automatic命令tune2fs -l /dev/sdb可以查到文件系统的UUID在/etc/fstab中添加 UUID=xxxxxxx /data ext4 _netdev 0 0 替换掉原来的那行