linux中的nfs、iscsi共享服务
nfs(Net File System),网络文件系统,英文Network File System(NFS),是由SUN公司研制的UNIX表示层协议(presentation layer protocol),能使使用者访问网络上别处的文件就像在使用自己的计算机一样。
nfs基本信息
nfs-utils 安装包
nfs-server 服务脚本
/etc/exports 共享配置文件
nfs的安装与启用
在westos_strage 172.25.254.100主机上:
75 dnf install nfs-utils.x86_64 -y ##安装nfs-utils
76 systemctl enable --now nfs-server.service ##开启nfs-server服务
79 firewall-cmd --permanent --add-service=nfs ##防火墙中永久添加nfs、rpc-bind、mountd服务
81 firewall-cmd --permanent --add-service=mountd
82 firewall-cmd --permanent --add-service=rpc-bind
83 firewall-cmd --reload ##重载火墙使设定生效
[root@westos_storage ~]# dnf install nfs-utils.x86_64 -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:02:53 ago on Wed 11 Aug 2021 09:12:09 AM CST.
Package nfs-utils-1:2.3.3-31.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@westos_storage ~]# systemctl enable --now nfs-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
[root@westos_storage ~]# netstat -antlupe | grep 2049
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN 0 39364 -
tcp6 0 0 :::2049 :::* LISTEN 0 39375 -
[root@westos_storage ~]# firewall-cmd --permanent --add-service=nfs
success
[root@westos_storage ~]# firewall-cmd --permanent --add-service=mountd
success
[root@westos_storage ~]# firewall-cmd --permanent --add-service=rpc-bind
success
[root@westos_storage ~]# firewall-cmd --reload
success
在westoslinux 172.25.254.200主机上:
showmount -e 172.25.254.100 ##查看nfs服务器上的所有共享资源
[root@westoslinux ~]# showmount -e 172.25.254.100 ##列出服务器的共享资源
Export list for 172.25.254.100:
nfs配置参数
anonuid=1000,anongid=1000 ##指定用户身份
sync ##更改生成后同步数据到服务器
async ##时时同步数据到服务器
rw ##读写
ro ##只读
no_root_squash ##root用户挂载不转换身份
**共享资源使用方式:mount 172.25.254.100:/westosdir /mnt/
**man 5 exports :可以查看共享策略文件的书写参数和共享书写方式
实验:
(1)、在westos_strage 172.25.254.100主机上:
[root@westos_storage ~]# mkdir /westosdir ##建立共享目录
[root@westos_storage ~]# ls -ld /westosdir ##查看目录权限
drwxr-xr-x. 2 root root 6 Aug 11 09:37 /westosdir
[root@westos_storage ~]# chmod 777 /westosdir/ ##在进行参数设置之前,为了不使共享的本地文件系统的权限设定限制我们写入文件,需要将共享目录的权限设置为777
[root@westos_storage ~]# ls -ld /westosdir
drwxrwxrwx. 2 root root 6 Aug 11 09:37 /westosdir
[root@westos_storage ~]# vim /etc/exports ##修改共享策略文件
//1 /westosdir *(ro,sync) ##只读共享,并在数据真实发生改变后才同步数据到nfs共享目录
//
[root@westos_storage ~]# exportfs -rv ##使共享策略生效
exporting *:/westosdir
在客户端westoslinux 172.25.254.200主机上可以查看到共享:
[root@westoslinux ~]# showmount -e 172.25.254.100
Export list for 172.25.254.100:
/westosdir *
(2)、修改westos_strage 172.25.254.100主机的共享策略文件,对于除200主机以外的只读共享,对200主机读写共享:
[root@westos_storage ~]# touch /westosdir/westosfile{1..3}
[root@westos_storage ~]# vim /etc/exports
//2 /westosdir 172.25.254.200(rw,sync) 或者 1 /westosdir *(ro,sync) 172.25.254.200(rw,sync)
//
[root@westos_storage ~]# exportfs -rv
exporting 172.25.254.200:/westosdir
exporting *:/westosdir
在客户端westoslinux 172.25.254.200主机上可以在共享目录中新建文件:
[root@westoslinux ~]# mount 172.25.254.100:/westosdir /mnt/
[root@westoslinux ~]# touch /mnt/westosfile4
[root@westoslinux ~]# unmount /mnt/
查询westos_strage 172.25.254.100主机上的共享目录:
[root@westos_storage ~]# ls /westosdir -l
total 0
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile1
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile2
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile3
-rw-r--r--. 1 nobody nobody 0 Aug 11 09:48 westosfile4 ##新建文件成功,当客户端挂载共享到本地目录后,使用到的用户身份是服务器上的nobody
(3)、修改westos_strage 172.25.254.100主机的共享策略文件,对于除200主机以外的只读共享,对200主机读写共享并指定客户端挂载时使用的用户为1000,不是默认的nobody:
[root@westos_storage ~]# vim /etc/exports
//2 /westosdir 172.25.254.200(rw,sync,anonuid=1000,anongid=1000)
//
[root@westos_storage ~]# exportfs -rv
exporting 172.25.254.200:/westosdir
exporting *:/westosdir
在客户端westoslinux 172.25.254.200主机上可以在共享目录中新建文件:
[root@westoslinux ~]# mount 172.25.254.100:/westosdir /mnt/
[root@westoslinux ~]# cd /mnt/
[root@westoslinux mnt]# touch file6
[root@westoslinux mnt]# ls /mnt/
file6 westosfile1 westosfile2 westosfile3 westosfile4
[root@westoslinux mnt]# cd
[root@westoslinux ~]# umount /mnt/
查询westos_strage 172.25.254.100主机上的共享目录:
[root@westos_storage ~]# ls /westosdir -l
total 0
-rw-r--r--. 1 westos westos 0 Aug 11 09:53 file6 ####用户和组设置成功
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile1
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile2
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile3
-rw-r--r--. 1 nobody nobody 0 Aug 11 09:48 westosfile4
(4)、修改westos_strage 172.25.254.100主机的共享策略文件,对于除200主机以外的只读共享,对200主机读写共享并当客户端使用超级用户挂载后沿用自己的root用户身份到服务器中:
[root@westos_storage ~]# vim /etc/exports
//2 /westosdir 172.25.254.200(rw,sync,no_root_squash)
//
[root@westos_storage ~]# exportfs -rv
exporting 172.25.254.200:/westosdir
exporting *:/westosdir
在客户端westoslinux 172.25.254.200主机上可以在共享目录中新建文件:
[root@westoslinux ~]# mount 172.25.254.100:/westosdir /mnt/
[root@westoslinux ~]# cd /mnt
[root@westoslinux mnt]# touch file7
查询westos_strage 172.25.254.100主机上的共享目录:
[root@westos_storage ~]# ls /westosdir -l
total 0
-rw-r--r--. 1 westos westos 0 Aug 11 09:53 file6
-rw-r--r--. 1 root root 0 Aug 11 09:55 file7 ##设置成功
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile1
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile2
-rw-r--r--. 1 root root 0 Aug 11 09:44 westosfile3
-rw-r--r--. 1 nobody nobody 0 Aug 11 09:48 westosfile4
nfs+autofs服务客户端共享优化自动挂载
dnf install autofs -y ##在客户端安装自动挂载服务autofs
vim /etc/auto.master ##编辑主挂载策略文件
//
9 /westos /etc/auto.nfs
最终挂载点的上层目录 子策略文件
//
vim /etc/auto.nfs
//
nfs -rw 172.25.254.100:/westosdir
最终挂载点的相对路径 挂载参数 nfs服务器上共享出来的资源
//
systemctl restart autofs.service ##重启服务
实验:
[root@westoslinux mnt]# vim /etc/auto.master
//
9 /westos /etc/auto.nfs
//
[root@westoslinux mnt]# vim /etc/auto.nfs
//
nfs -rw 172.25.254.100:/westosdir
//
[root@westoslinux mnt]# systemctl restart autofs.service
[root@westoslinux mnt]# df ##查询挂载
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 403532 0 403532 0% /dev
tmpfs 419132 0 419132 0% /dev/shm
tmpfs 419132 6308 412824 2% /run
tmpfs 419132 0 419132 0% /sys/fs/cgroup
/dev/vda3 17814528 3342832 14471696 19% /
/dev/vda1 1038336 173172 865164 17% /boot
tmpfs 83824 1180 82644 2% /run/user/42
tmpfs 83824 4 83820 1% /run/user/0
172.25.254.100:/westosdir 17814528 3346688 14467840 19% /mnt
[root@westoslinux mnt]# cd
[root@westoslinux ~]# umount /mnt ##卸载
[root@westoslinux ~]# cd /westos/
[root@westoslinux westos]# ls
[root@westoslinux westos]# cd nfs
[root@westoslinux nfs]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 403532 0 403532 0% /dev
tmpfs 419132 0 419132 0% /dev/shm
tmpfs 419132 6308 412824 2% /run
tmpfs 419132 0 419132 0% /sys/fs/cgroup
/dev/vda3 17814528 3342832 14471696 19% /
/dev/vda1 1038336 173172 865164 17% /boot
tmpfs 83824 1180 82644 2% /run/user/42
tmpfs 83824 4 83820 1% /run/user/0
172.25.254.100:/westosdir 17814528 3346688 14467840 19% /westos/nfs
[root@westoslinux nfs]# cd
[root@westoslinux ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 403532 0 403532 0% /dev
tmpfs 419132 0 419132 0% /dev/shm
tmpfs 419132 6308 412824 2% /run
tmpfs 419132 0 419132 0% /sys/fs/cgroup
/dev/vda3 17814528 3342832 14471696 19% /
/dev/vda1 1038336 173172 865164 17% /boot
tmpfs 83824 1180 82644 2% /run/user/42
tmpfs 83824 4 83820 1% /run/user/0
172.25.254.100:/westosdir 17814528 3346688 14467840 19% /westos/nfs
[root@westoslinux ~]# df ##过3妙,挂载自动卸载
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 403532 0 403532 0% /dev
tmpfs 419132 0 419132 0% /dev/shm
tmpfs 419132 6304 412828 2% /run
tmpfs 419132 0 419132 0% /sys/fs/cgroup
/dev/vda3 17814528 3342832 14471696 19% /
/dev/vda1 1038336 173172 865164 17% /boot
tmpfs 83824 1180 82644 2% /run/user/42
tmpfs 83824 4 83820 1% /run/user/0
iscsi设备共享
iscsi直接共享设备的读写权限,其具体共享方式如下:
先给虚拟机westos_strage 172.25.254.100添加一块2G硬盘
(1).在westos_strage 172.25.254.100主机端:
dnf install targetcli -y ##下载共享策略管理软件
systemctl enable --now target ##开启target服务
targetcli ##用此命令编写共享策略
其中:
/backstores/block create westos:storage1 /dev/vdb1
再此软件设备中的别名 /dev/vdb1系统中真实设备
/iscsi create iqn.2021-08.org.westos:storage1
##建立对外的共享名称,iqn的命名方式
##iscsi限定名称
##格式iqn.YYYY-MM.域名反写:别名
/iscsi/iqn.2021-08.org.westos:storage1/tpg1/luns create /backstores/block/westos:storage1
##把共享名称和内部制定设备关联
/iscsi/iqn.2021-08.org.westos:storage1/tpg1/acls create iqn.2021-08.org.westos:westoskey
##为共享设备设定访问key westoskey是加密字符
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
具体操作:
[root@westos_storage ~]# fdisk -l ##查看磁盘的分区情况
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x34fd8722Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 6293503 4194304 2G 82 Linux swap / Solaris
/dev/vda3 6293504 41943039 35649536 17G 83 LinuxDisk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors ##/dev/vdb硬盘添加成功
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@westos_storage ~]# fdisk /dev/vdb ##使用交互式分区方式fdisk /dev/vdb在该硬盘上新建一个大小为2G的设备/dev/vdb1Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xd6c941f3.Command (m for help): n
Partition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions)
Select (default p): Using default response p.
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +2GCreated a new partition 1 of type 'Linux' and of size 2 GiB.
Partition #1 contains a LVM2_member signature.Do you want to remove the signature? [Y]es/[N]o: YThe signature will be removed by a write command.Command (m for help): p
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd6c941f3Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 4196351 4194304 2G 83 LinuxFilesystem/RAID signature on partition 1 will be wiped.Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.[root@westos_storage ~]# dnf install targetcli -y ##下载共享策略管理软件[root@westos_storage ~]# systemctl enable --now target
Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.
[root@westos_storage ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.51
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 westos:storage1 /dev/vdb1 ####代码上面有详细解释
Created block storage object westos:storage1 using /dev/vdb1.
/> /iscsi create iqn.2021-08.org.westos:storage1
Created target iqn.2021-08.org.westos:storage1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> /iscsi/iqn.2021-08.org.westos:storage1/tpg1/luns create /backstores/block/westos:storage1
Created LUN 0.
/> /iscsi/iqn.2021-08.org.westos:storage1/tpg1/acls create iqn.2021-08.org.westos:westoskey
Created Node ACL for iqn.2021-08.org.westos:westoskey
Created mapped LUN 0.
/> quit
Command not found quit
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
(2).在iscsi客户端westoslinux 172.25.254.200:
dnf install iscsi-initiator-utils-6.2.0.878-4.gitd791ce0.el8.i686 -y ##安装iscsi服务端软件
systemctl status iscsid ##对客户端配置控制服务
systemctl status iscsi ##客户端对资源利用的服务
iscsiadm -m discovery -t st -p 172.25.254.100 ##共享信息查询:-m mode,-t 指定要识别的设备属性,-p 指定资源主机ip
*******注意:如果链接100服务失败需要设定100中的火墙
//
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
//
iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.100 -l ##-T 指定要访问的共享设备名称,-l 登陆共享设备
**注意:如果失败,是因为在客户端中未指定服务端的共享key所以无法登录
需要在/etc/iscsi/initiatorname.iscsi文件中指定key,然后重启服务
vim /etc/iscsi/initiatorname.iscsi
//
InitiatorName=iqn.2021-08.org.westos:westoskey
服务器中的共享key
//
systemctl restart iscsid.service
fdisk -l:查看磁盘的分区情况 ,子系统会出现一个新的硬盘大小为服务器中共享设备的大小
mkfs.xfs /dev/sda1 ##格式化设备为xfs文件系统,相当与在/dev/sda1上安装设备管理软件
mount /dev/sda1 /mnt/ ##挂载共享设备到/mnt/
具体操作:
[root@westoslinux ~]# dnf install iscsi-initiator-utils-6.2.0.878-4.gitd791ce0.el8.i686 -y ##安装iscsi服务端软件
[root@westoslinux ~]# systemctl status iscsid ##对客户端配置控制服务
● iscsid.service - Open-iSCSILoaded: loaded (/usr/lib/systemd/system/iscsid.service; disabled; vend>Active: inactive (dead)Docs: man:iscsid(8)man:iscsiuio(8)man:iscsiadm(8)[root@westoslinux ~]# systemctl status iscsi ##客户端对资源利用的服务
● iscsi.service - Login and scanning of iSCSI devicesLoaded: loaded (/usr/lib/systemd/system/iscsi.service; enabled; vendor>Active: inactive (dead)
Condition: start condition failed at Wed 2021-08-11 09:02:05 CST; 2h 19mi>Docs: man:iscsiadm(8)man:iscsid(8)Aug 11 09:02:05 westoslinux.westos.org systemd[1]: iscsi.service: Unit ca>[root@westoslinux ~]# iscsiadm -m discovery -t st -p 172.25.254.100 ##-m mode,-t 指定要识别的设备属性,-p 指定资源主机ip
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host ##如果链接100服务失败需要设定100中的火墙
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: connection login retries (reopen_max) 5 exceeded
iscsiadm: Could not perform SendTargets discovery: iSCSI PDU timed out[root@westoslinux ~]# iscsiadm -m discovery -t st -p 172.25.254.100 ##共享信息可以查询
172.25.254.100:3260,1 iqn.2021-08.org.westos:storage1
[root@westoslinux ~]# vim /etc/iscsi/initiatorname.iscsi
//
InitiatorName=iqn.2021-08.org.westos:westoskey
//
[root@westoslinux ~]# systemctl restart iscsid.service
[root@westoslinux ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.100 -l ##-T 指定要访问的共享设备名称,-l 登陆共享设备
Logging in to [iface: default, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.100,3260]
Login to [iface: default, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.100,3260] successful.[root@westoslinux ~]# fdisk -l
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x34fd8722Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 6293503 4194304 2G 82 Linux swap / Solaris
/dev/vda3 6293504 41943039 35649536 17G 83 LinuxDisk /dev/sda: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes[root@westoslinux ~]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xce42a8b4.Command (m for help): n
Partition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions)
Select (default p): Using default response p.
Partition number (1-4, default 1):
First sector (2048-4194303, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): Created a new partition 1 of type 'Linux' and of size 2 GiB.
Partition #1 contains a ext4 signature.Do you want to remove the signature? [Y]es/[N]o: yThe signature will be removed by a write command.Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.[root@westoslinux ~]# mkfs.xfs /dev/sda1 ##格式化设备为xfs文件系统,相当与在/dev/sda1上安装设备管理软件
meta-data=/dev/sda1 isize=512 agcount=4, agsize=131008 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=1, sparse=1, rmapbt=0= reflink=1
data = bsize=4096 blocks=524032, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
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@westoslinux ~]# mount /dev/sda1 /mnt/ ##挂载共享设备到/mnt/
卸载设备
客户端westoslinux 172.25.254.200主机:
tree /var/lib/iscsi/ ##在客户端读取到服务器的所有数据存放目录
iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.100 -u ##-u 临时登出共享设备,再-o delete删除该设备
退出登陆后设备就消失了,但是数据还在,重启iscsi服务后设备会自动出现
iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.100 -o delete ##删除客户主机中此网络设备的数据
实际操作:
[root@westoslinux ~]# umount /mnt
[root@westoslinux ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 403532 0 403532 0% /dev
tmpfs 419132 0 419132 0% /dev/shm
tmpfs 419132 6320 412812 2% /run
tmpfs 419132 0 419132 0% /sys/fs/cgroup
/dev/vda3 17814528 3369848 14444680 19% /
/dev/vda1 1038336 173172 865164 17% /boot
tmpfs 83824 1180 82644 2% /run/user/42
tmpfs 83824 4 83820 1% /run/user/0
[root@westoslinux ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2021-08.org.westos:storage1
│ └── 172.25.254.100,3260,1
│ └── default
├── send_targets
│ └── 172.25.254.100,3260
│ ├── iqn.2021-08.org.westos:storage1,172.25.254.100,3260,1,default -> /var/lib/iscsi/nodes/iqn.2021-08.org.westos:storage1/172.25.254.100,3260,1
│ └── st_config
├── slp
└── static10 directories, 2 files
[root@westoslinux ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.100 -u
Logging out of session [sid: 1, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.100,3260]
Logout of [sid: 1, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.100,3260] successful.
[root@westoslinux ~]# fdisk -l
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x34fd8722Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 6293503 4194304 2G 82 Linux swap / Solaris
/dev/vda3 6293504 41943039 35649536 17G 83 Linux
[root@westoslinux ~]# systemctl restart iscsi
[root@westoslinux ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2021-08.org.westos:storage1
│ └── 172.25.254.100,3260,1
│ └── default
├── send_targets
│ └── 172.25.254.100,3260
│ ├── iqn.2021-08.org.westos:storage1,172.25.254.100,3260,1,default -> /var/lib/iscsi/nodes/iqn.2021-08.org.westos:storage1/172.25.254.100,3260,1
│ └── st_config
├── slp
└── static10 directories, 2 files
[root@westoslinux ~]# fdisk -l
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x34fd8722Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 6293503 4194304 2G 82 Linux swap / Solaris
/dev/vda3 6293504 41943039 35649536 17G 83 LinuxDisk /dev/sda: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xce42a8b4Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 4194303 4192256 2G 83 Linux
[root@westoslinux ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.100 -u
Logging out of session [sid: 2, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.100,3260]
Logout of [sid: 2, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.100,3260] successful.
[root@westoslinux ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.100 -o delete
[root@westoslinux ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
│ └── 172.25.254.100,3260
│ └── st_config
├── slp
└── static7 directories, 1 file
[root@westoslinux ~]# systemctl restart iscsi
[root@westoslinux ~]# fdisk -l
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x34fd8722Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 6293503 4194304 2G 82 Linux swap / Solaris
/dev/vda3 6293504 41943039 35649536 17G 83 Linux
服务端westos_strage 172.25.254.100主机:
targetcli
clearconfig confirm=True ##清空服务器中iscsi的共享数据
实际操作:
[root@westos_storage ~]# targetcli
targetcli shell version 2.1.51
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'./> ls
o- / ....................................................................................................... [...]o- backstores ............................................................................................ [...]| o- block ................................................................................ [Storage Objects: 1]| | o- westos:storage1 ............................................... [/dev/vdb1 (2.0GiB) write-thru activated]| | o- alua ................................................................................. [ALUA Groups: 1]| | o- default_tg_pt_gp ..................................................... [ALUA state: Active/optimized]| o- fileio ............................................................................... [Storage Objects: 0]| o- pscsi ................................................................................ [Storage Objects: 0]| o- ramdisk .............................................................................. [Storage Objects: 0]o- iscsi .......................................................................................... [Targets: 1]| o- iqn.2021-08.org.westos:storage1 ................................................................. [TPGs: 1]| o- tpg1 ............................................................................. [no-gen-acls, no-auth]| o- acls ........................................................................................ [ACLs: 1]| | o- iqn.2021-08.org.westos:westoskey ................................................... [Mapped LUNs: 1]| | o- mapped_lun0 ..................................................... [lun0 block/westos:storage1 (rw)]| o- luns ........................................................................................ [LUNs: 1]| | o- lun0 ......................................... [block/westos:storage1 (/dev/vdb1) (default_tg_pt_gp)]| o- portals .................................................................................. [Portals: 1]| o- 0.0.0.0:3260 ................................................................................... [OK]o- loopback ....................................................................................... [Targets: 0]
/> clearconfig confirm=True
All configuration cleared
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
linux中的nfs、iscsi共享服务相关推荐
- Linux中的NFS共享
1. NFS服务介绍 1.1什么是NFS服务 一.NFS工作原理 1.什么是NFS服务器 NFS就是Network File System的缩写,它最大的功能就是可以通过网络,让不同的机器.不同的操作 ...
- Linux系统搭建NFS网络共享存储
Linux系统搭建NFS网络共享存储 一.NFS概述: NFS是一种基于TCP/IP传输的网络文件系统协议,最初由SUN公司开发.通过NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源 ...
- 在Linux中挂载Windows端共享权限设定方法和出现报错的解决办法
在Linux中挂载Windows端共享权限设定方法 Windows端共享权限设定: 关于挂载共享文件夹的报错解决 1.出现smbclient 报错 2.关闭windows防火墙 3.确认windows ...
- 如何查看 Linux 中所有正在运行的服务
有许多方法和工具可以查看 Linux 中所有正在运行的服务.大多数管理员会在 System V(SysV)初始化系统中使用 service service-name status 或 /etc/ini ...
- linux oracle查看服务,技术|如何查看 Linux 中所有正在运行的服务
有许多方法和工具可以查看 Linux 中所有正在运行的服务.大多数管理员会在 System V(SysV)初始化系统中使用 service service-name status 或 /etc/ini ...
- linux中的NFS服务器配置及/etc/exports
原文地址:http://blog.csdn.net/xph23/article/details/6001471 先简单介绍一下NFS服务器是什么? NFS server可以看作是一个FILE SERV ...
- linux中的nfs权限,Linux中的NFS协议解析
8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? 实验步骤 步骤1:下载实验文件 请访问http://file.ichunqiu.com/686f863d下载实验文件. ...
- 查看mysql服务器状态命令_在linux中,怎样查看Mysql服务运行状态?
展开全部 使用命令 # service mysqld status 命令来查看mysql 的启动状态如图所示: mysqld is stopped 那就说明mysql服务是62616964757a68 ...
- linux启动自动挂载共享文件,linux中自动挂载windows 共享目录
使用smb协议挂载很难解决乱码问题,使用cifs则没乱码问题 linux访问Windows共享文件夹或者使用其它linux机器使用samba的共享目录 1.Windows共享一个文件夹share, 开 ...
最新文章
- 精通python爬虫框架-精通Python爬虫从Scrapy到移动应用(文末福利)
- javascript数组查重方法总结
- QML 性能优化建议(二)
- WebRTC十周年、Space X成功对接国际空间站、TikTok复制品Zynn或有快手支持|Decode the Week...
- zookeeper集群部署(分布式)
- 逻辑综合工具DesignCompiler使用教程
- arthas 排查内存溢出_Java 应用线上问题排查思路、常用工具小结
- python画圣诞树代码解读_实战 | 教你用Python画各种版本的圣诞树
- Linux作者批评英特尔指令集,Linux之父炮轰英特尔:ECC内存很重要,不好买都怪你胡搞...
- java 解析josn数组
- Chrome插件扩展程序的默认安装目录
- 一意孤行亚马逊----一个钓鱼疯子的巴西亚马逊之行( 5.九月21日 亚马逊的鱼并不好钓) 作者:咸水鱼...
- “青春树儿童摄影网”首页制作
- 近两日学的Linux系统基础命令总结
- iis php mysql wiki_如何创建自己的wiki-Dokuwiki
- 详解DeepSDF: Learning Continuous Signed Distance Functions for Shape Representation
- 在ArcGIS Online中创建三维图层和网络场景(2017.9)
- win7与linux切换,Windows 7停更后不想用Win10?教你直接换上Linux再战
- 详解电脑死机没反应怎么解决
- slim android7 nexus7,新Nexus 7详细拆解:拆装不难,外壳脆弱