RHEL7 配置iscsi服務端並實現客戶端自動開機掛載
阿新 • • 發佈:2018-09-24
page been hang disco portal count term naconda tmpfs 環境:server 172.25.0.11 ——iscsi server iqn:iqn.2016-02.com.example:server0
client 172.25.0.10 ——iscsi client iqn:iqn.2016-02.com.example:desktop0
一、iscsi服務端配置
client 172.25.0.10 ——iscsi client iqn:iqn.2016-02.com.example:desktop0
一、iscsi服務端配置
安裝targetcli
yum install targetcli -y
找一塊磁盤掛載
[root@server0 ~]# targetcli ——進入此命令配置iscsi服務端 Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb34 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type ‘help‘. /> 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] /> backstores/block create iscsi_store /dev/vdb1——使用剛才分區的磁盤vdb創建iscsi存儲塊 Created block storage object iscsi_store using /dev/vdb1. /> ls o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 1] | | o- iscsi_store ................................................................... [/dev/vdb1 (3.0GiB) write-thru deactivated] | o- fileio ................................................................................................. [Storage Objects: 0] | o- pscsi .................................................................................................. [Storage Objects: 0] | o- ramdisk ................................................................................................ [Storage Objects: 0] o- iscsi ............................................................................................................ [Targets: 0] o- loopback ......................................................................................................... [Targets: 0] /> iscsi/ create iqn.2016-02.com.example:server0——創建iscsi服務器端iqn Created target iqn.2016-02.com.example:server0. Created TPG 1. /> iscsi/iqn.2016-02.com.example:server0/tpg1/ iscsi/iqn.2016-02.com.example:server0/tpg1/* iscsi/iqn.2016-02.com.example:server0/tpg1/luns/ iscsi/iqn.2016-02.com.example:server0/tpg1/acls/ iscsi/iqn.2016-02.com.example:server0/tpg1/portals/ ...path /> iscsi/iqn.2016-02.com.example:server0/tpg1/ iscsi/iqn.2016-02.com.example:server0/tpg1/* iscsi/iqn.2016-02.com.example:server0/tpg1/luns/ iscsi/iqn.2016-02.com.example:server0/tpg1/acls/ iscsi/iqn.2016-02.com.example:server0/tpg1/portals/ ...path /> iscsi/iqn.2016-02.com.example:server0/tpg1/luns create /backstores/block/iscsi_store ——創建iscsi存儲lun Created LUN 0. /> iscsi/iqn.2016-02.com.example:server0/tpg1/acls create iqn.2016-02.com.example:desktop0 ——允許客戶端iqn訪問此服務器iscsi服務 Created Node ACL for iqn.2016-02.com.example:desktop0 Created mapped LUN 0. /> iscsi/iqn.2016-02.com.example:server0/tpg1/portals create 172.25.0.11 3260——創建服務器端偵聽ip和端口 Using default IP port 3260 Created network portal 172.25.0.11:3260. /> saveconfig ——保存配置 Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json /> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json [root@server0 ~]# systemctl start target ——啟動iscsi服務 [root@server0 ~]# systemctl enable target ln -s ‘/usr/lib/systemd/system/target.service‘ ‘/etc/systemd/system/multi-user.target.wants/target.service‘ [root@server0 ~]# firewall-cmd --permanent --add-port=3260/tcp——防火墻開啟3260端口 success [root@server0 ~]# firewall-cmd --reload——重啟防火墻服務 success [root@server0 ~]#
二、iscsi客戶端配置
[root@desktop0 ~]# yum install iscsi-initiator-utils -y Loaded plugins: langpacks Package iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 already installed and latest version Nothing to do [root@desktop0 ~]# vim /etc/iscsi/initiatorname.iscsi ——修改客戶端iqn名稱 [root@desktop0 ~]# cat !$ cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2016-02.com.example:desktop0 [root@desktop0 ~]# [root@desktop0 ~]# systemctl start iscsi iscsid [root@desktop0 ~]# systemctl enable iscsi iscsid ln -s ‘/usr/lib/systemd/system/iscsid.service‘ ‘/etc/systemd/system/multi-user.target.wants/iscsid.service‘ [root@desktop0 ~]# iscsiadm -m discovery -t st -p server0 172.25.0.11:3260,1 iqn.2016-02.com.example:server0 [root@desktop0 ~]# iscsiadm -m node -T iqn.2016-02.com.example:server0 -p 172.25.0.11 -l Logging in to [iface: default, target: iqn.2016-02.com.example:server0, portal: 172.25.0.11,3260] (multiple) Login to [iface: default, target: iqn.2016-02.com.example:server0, portal: 172.25.0.11,3260] successful. [root@desktop0 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 3G 0 disk vda 253:0 0 10G 0 disk └─vda1 253:1 0 10G 0 part / vdb 253:16 0 10G 0 disk [root@desktop0 ~]# fdisk /dev/sda——分區掛載的iscsi磁盤 Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xa975526e. Command (m for help): p Disk /dev/sda: 3221 MB, 3221225472 bytes, 6291456 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 Disk label type: dos Disk identifier: 0xa975526e Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (8192-6291455, default 8192): Using default value 8192 Last sector, +sectors or +size{K,M,G} (8192-6291455, default 6291455): Using default value 6291455 Partition 1 of type Linux and of size 3 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@desktop0 ~]# fdisk -l Disk /dev/sda: 3221 MB, 3221225472 bytes, 6291456 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 Disk label type: dos Disk identifier: 0xa975526e Device Boot Start End Blocks Id System /dev/sda1 8192 6291455 3141632 83 Linux [root@desktop0 ~]# mkfs.xfs /dev/sda1——格式化文件類型為xfs meta-data=/dev/sda1 isize=256 agcount=8, agsize=98176 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=785408, 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=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@desktop0 ~]# mkdir /mnt/data [root@desktop0 ~]# vim /etc/fstab [root@desktop0 ~]# blkid /dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" /dev/sda1: UUID="701f7c03-8f64-4d39-9acc-55a95d66e57d" TYPE="xfs" [root@desktop0 ~]# vim /etc/fstab ——使用uuid掛載 [root@desktop0 ~]# cat !$ cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 7 01:22:57 2014 # # Accessible filesystems, by reference, are maintained under ‘/dev/disk‘ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1 UUID=701f7c03-8f64-4d39-9acc-55a95d66e57d /mnt/data xfs _netdev 0 0 ——註意使用_netdev [root@desktop0 ~]# mount -a [root@desktop0 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 xfs 10G 3.1G 7.0G 31% / devtmpfs devtmpfs 906M 0 906M 0% /dev tmpfs tmpfs 921M 124K 921M 1% /dev/shm tmpfs tmpfs 921M 17M 904M 2% /run tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup /dev/sda1 xfs 3.0G 33M 3.0G 2% /mnt/data [root@desktop0 ~]#
註意:開機啟動自動掛載還需要修改此參數
vim /var/lib/iscsi/nodes/iqn.2016-02.com.example\:server0/172.25.0.11\,3260\,1/default
node.conn[0].startup = automatic——把手動改為自動
結果成功在客戶端掛載的iscsi上創建文件
RHEL7 配置iscsi服務端並實現客戶端自動開機掛載