###### 1. samba服务简介 ########
作用:
smb = Server Message Block        Sum
cifs = Common Internet File System Miscrosoft
windows系统共享文件时用到的协议smb
smb是由miscrosoft+sun
Linux cifs

######2.samba基本信息######
服务启动脚本:
smb.service
主配置目录:
/etc/samba
主配置文件:
/etc/smb.conf
安全上下文:
samba_share_t

######2.samba的安装与启用######

[root@westosa ~]# dnf search samba  ##搜索[root@westosa ~]# dnf install samba-client samba-commony  -y ##下载samba服务[root@westosa ~]# systemctl enable --now smb.service   ##开启服务
Created symlink /etc/systemd/system/multi-user.target.wants/smb.service → /usr/lib/systemd/system/smb.service.
[root@westosa ~]# firewall-cmd --permanent --add-service=samba    ##添加火墙服务
success
[root@westosa ~]# firewall-cmd --reload    ##重启服务
success

###### 3.samba用户的建立 #############

[root@westosa ~]# useradd -s /sbin/nologin lee -M  ##添加一个lee 没有系统交互式
[root@westosa ~]# id lee
uid=1001(lee) gid=1001(lee) groups=1001(lee)
[root@westosa ~]# id westos
uid=1000(westos) gid=1000(westos) groups=1000(westos)
[root@westosa ~]# smbpasswd -a westos    ##添加westos
[root@westosa ~]# smbpasswd -a lee      ##添加lee[root@westosa ~]# pdbedit -L    ##查看 -L列出
westos:1000:westos
lee:1001:
[root@westosa ~]# pdbedit -x lee        ##删除 -x
[root@westosa ~]# pdbedit -L
westos:1000:westos
[root@westosa ~]# smbpasswd -a lee
New SMB password:
Retype new SMB password:
Added user lee.
[root@westosa ~]# pdbedit -L
westos:1000:westos
lee:1001:
[root@westosa ~]# smbclient  //172.25.254.170/westos -U westos
Enter SAMBA\westos's password:
Try "help" to get a list of possible commands.
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*   ##查看不到是因为selinux

#######4.samba用户访问加目录######

[root@westosa ~]# cd /etc/samba/
[root@westosa samba]# ls
lmhosts  smb.conf  smb.conf.example
[root@westosa samba]# vim smb.conf
[root@westosa samba]# cp -p smb.conf.example smb.conf
cp: overwrite 'smb.conf'? y
[root@westosa samba]# vim smb.conf  ##查找到setsebool -P samba_enable_home_dirs on
[root@westosa samba]#  setsebool -P samba_enable_home_dirs on  ##开启
[root@westosa samba]# smbclient //172.25.254.170/westos -U westos   ##登陆共享目录就可以查看到内容
Enter MYGROUP\westos's password:
Try "help" to get a list of possible commands.
smb: \> ls.                                   D        0  Fri Mar 26 14:04:40 2021..                                  D        0  Fri Mar 26 14:12:46 2021.bash_logout                        H       18  Fri Aug 30 13:30:21 2019.bash_profile                       H      141  Fri Aug 30 13:30:21 2019.bashrc                             H      312  Fri Aug 30 13:30:21 2019.config                            DH        0  Fri Mar 26 14:07:18 2021.esd_auth                           H       16  Fri Mar 26 14:04:38 2021.local                             DH        0  Fri Mar 26 14:04:38 2021.ICEauthority                       H      310  Fri Mar 26 14:04:39 2021.cache                             DH        0  Fri Mar 26 14:05:30 2021Desktop                             D        0  Fri Mar 26 14:04:40 2021Downloads                           D        0  Fri Mar 26 14:04:40 2021Templates                           D        0  Fri Mar 26 14:04:40 2021Public                              D        0  Fri Mar 26 14:04:40 2021Documents                           D        0  Fri Mar 26 14:04:40 2021Music                               D        0  Fri Mar 26 14:04:40 2021Pictures                            D        0  Fri Mar 26 14:05:37 2021Videos                              D        0  Fri Mar 26 14:04:40 2021.pki                               DH        0  Fri Mar 26 14:04:40 202117814528 blocks of size 1024. 14411364 blocks available
smb: \> ^C[root@westosa samba]# mkdir /westos_share
[root@westosa samba]# ls -ld  /westos_share
drwxr-xr-x. 2 root root 6 Aug 10 11:39 /westos_share
[root@westosa samba]# vim smb.conf最下面添加[westos_share]comment = westos sharepath = /westos_share[root@westosa samba]# systemctl restart smb.service[root@westosa samba]# smbclient -L //172.25.254.170 -U westos
Enter MYGROUP\westos's password:Sharename       Type      Comment---------       ----      -------westos_share    Disk      westos share    ##这里查看到添加共享目录成功IPC$            IPC       IPC Service (Samba Server Version 4.11.2)westos          Disk      Home Directories
SMB1 disabled -- no workgroup available
[root@westosa samba]# smbclient //172.25.254.170/westos_share -U westos
Enter MYGROUP\westos's password:
Try "help" to get a list of possible commands.
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*   ##因为安全上下文的原因没有登陆成功   去更改安全上下文[root@westosa samba]# touch /westos_share/westosfile{1..3}[root@westosa samba]# semanage fcontext -a -t samba_share_t '/westos_share(/.*)?'  ##更改安全上下文
[root@westosa samba]# restorecon -RvvF /westos_share/    ##刷新显示明细
Relabeled /westos_share from unconfined_u:object_r:default_t:s0 to system_u:object_r:samba_share_t:s0
Relabeled /westos_share/westosfile1 from unconfined_u:object_r:default_t:s0 to system_u:object_r:samba_share_t:s0
Relabeled /westos_share/westosfile2 from unconfined_u:object_r:default_t:s0 to system_u:object_r:samba_share_t:s0
Relabeled /westos_share/westosfile3 from unconfined_u:object_r:default_t:s0 to system_u:object_r:samba_share_t:s0[root@westosa samba]# smbclient //172.25.254.170/westos_share -U westos      ##在此登陆就可以查看的
了
Enter MYGROUP\westos's password:
Try "help" to get a list of possible commands.
smb: \> ls.                                   D        0  Tue Aug 10 11:44:04 2021..                                  D        0  Tue Aug 10 11:39:41 2021westosfile1                         N        0  Tue Aug 10 11:44:04 2021westosfile2                         N        0  Tue Aug 10 11:44:04 2021westosfile3                         N        0  Tue Aug 10 11:44:04 202117814528 blocks of size 1024. 14410780 blocks available
smb: \> ^C[root@westosa samba]# vim smb.conf ##最后面添加  系统级别目录[mnt]comment = mnt dirpath = /mnt
[root@westosa samba]#systemctl  restart smb.server  ##重启服务
[root@westosa samba]# smbclient -L //172.25.254.170 -U westos  ##查看是否添加成功
Enter MYGROUP\westos's password:Sharename       Type      Comment---------       ----      -------westos_share    Disk      westos sharemnt             Disk      mnt dirIPC$            IPC       IPC Service (Samba Server Version 4.11.2)westos          Disk      Home Directories
SMB1 disabled -- no workgroup available
[root@westosa samba]# smbclient  //172.25.254.170/mnt -U westos
Enter MYGROUP\westos's password:
Try "help" to get a list of possible commands.
smb: \> ls.                                   D        0  Fri Mar 26 14:10:41 2021..                                  D        0  Tue Aug 10 11:39:41 20218-abstract-dark.xml                 N      823  Tue Aug 13 04:54:10 20198-abstract-light.xml                N      829  Fri Aug 16 21:24:14 2019circles-dark.xml                    N      805  Tue Aug 13 04:58:35 2019circles-light.xml                   N      811  Tue Aug 13 04:58:48 2019desktop-backgrounds-default.xml      N     1606  Tue Feb 19 04:29:54 2019hello-world-dark.xml                N      829  Tue Aug 13 04:59:06 201917814528 blocks of size 1024. 14410256 blocks available
smb: \> ^C如果添加了系统级别目录被selinux阻止了   操作如下[root@westosa samba]# getsebool -a | grep samba  ##查看服务开启状态
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> on
samba_export_all_ro --> off     ##共享系统级别的被selinux阻止      打开它就可以了
samba_export_all_rw --> off      ##共享系统级别的被selinux阻止     打开它就可以了
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off

##### 6.samba的访问控制######

vim  amb.conf  ##在91行添加

hosts allow        172.25.254.30 172.25.254     ##当写到单独共享时之对此共享生效
hosts deny                ##当写到【GLOBAL】时对samba整体生效

### 7.samba的常用配置参数#####

writable = yes                            ##可写
write list = westos                    ##指定用户可写
write list = +westos                  ##指定组可写
write list = @westos
valid users = lee                      ##指定访问用户
valid users = +lee|@lee         ##指定访问组
browseable = yes|no              ##是否隐藏共享

map to guest = bad user ##写到全局设定中

guest ok = yes        ##允许匿名用户访问

admin users = lee        ##指定此共享的超级用户身份呢

[root@westoslinux samba]# ls -ld /westos_share/
drwxrwxrwx. 2 root root 63 Aug 10 20:55 /westos_share/
[root@westoslinux samba]# chmod 777 /westos_share/
去客户端进行下载
[root@westosb ~]# mount //172.25.254.170/westos_share /mnt/ -o username=lee,password=lee
[root@westosb ~]# df
Filesystem                    1K-blocks    Used Available Use% Mounted on
devtmpfs                         403532       0    403532   0% /dev
tmpfs                            419132       0    419132   0% /dev/shm
tmpfs                            419132    6300    412832   2% /run
tmpfs                            419132       0    419132   0% /sys/fs/cgroup
/dev/vda3                      17814528 3341388  14473140  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.170/westos_share  17814528 3371992  14442536  19% /mnt[root@westoslinux samba]# vim smb.conf     ##添加对lee可写
[westos_share]comment = westos sharepath = /westos_sharewritable = yes
[root@westoslinux samba]# systemctl restart smb.service
[root@westoslinux samba]# touch /mnt/file     ##创建成功[root@westoslinux samba]# vim smb.conf
[westos_share]comment = westos sharepath = /westos_share
;   writable = yeswrite list = lee  ##此共享只对与lee用户可写
[root@westoslinux samba]# systemctl restart smb.service [root@westoslinux samba]# mount //172.25.254.170/westos_share /mnt/ -o username=westos,password=westos    ##  使用westos用户
[root@westoslinux samba]# touch /mnt/file2
touch: cannot touch '/mnt/file2': Permission denied     ##别拒绝掉了[root@westoslinux samba]# usermod -G lee westos    ##添加lee组
[root@westoslinux samba]# id westos
uid=1000(westos) gid=1000(westos) groups=1000(westos),1001(lee)
[root@westoslinux samba]# vim smb.conf    ##添加对lee组成员可写[westos_share]comment = westos sharepath = /westos_share
;       writable = yeswrite list = +lee    ##添加对lee组成员可写
[root@westoslinux samba]# systemctl restart smb.service [root@westoslinux samba]# touch /mnt/file1
[root@westoslinux samba]# ls -ld /westos_share/
drwxrwxrwx. 2 root root 76 Aug 10 21:59 /westos_share/
[root@westoslinux samba]# ls  /westos_share/
file1  westosfile1  westosfile2  westosfile3匿名用户访问
[root@westoslinux samba]# smbclient //172.25.254.170/westos_share   ##默认情况不允许匿名用户访问
Enter MYGROUP\root's password:
Anonymous login successful
tree connect failed: NT_STATUS_ACCESS_DENIED[root@westoslinux samba]# vim smb.conf
116         security = user
117         passdb backend = tdbsam
118         map to guest = bad us
315         [westos_share]
316         comment = westos share
317         path = /westos_share
318 ;       writable = yes
319         write list = +lee
320         guest ok = yes
[root@westoslinux samba]# systemctl restart smb.service[root@westoslinux samba]# smbclient //172.25.254.170/westos_share  ##匿名登陆
Enter MYGROUP\root's password:                       ##不用密码直接回车
Try "help" to get a list of possible commands.
smb: \> ls.                                   D        0  Tue Aug 10 21:59:02 2021..                                  D        0  Tue Aug 10 21:21:30 2021westosfile1                         N        0  Tue Aug 10 20:55:40 2021westosfile2                         N        0  Tue Aug 10 20:55:40 2021westosfile3                         N        0  Tue Aug 10 20:55:40 2021file1                               A        0  Tue Aug 10 21:59:02 202117814528 blocks of size 1024. 14416584 blocks available
smb: \>

####8.samba的多用户挂载#####

在客户端如果用普通的挂载方式
没有用过用户验证的人也可以访问samba服务

客户主机
匿名用户的挂载
[root@westosb ~]# umount /mnt
[root@westosb ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          403532       0    403532   0% /dev
tmpfs             419132       0    419132   0% /dev/shm
tmpfs             419132    6296    412836   2% /run
tmpfs             419132       0    419132   0% /sys/fs/cgroup
/dev/vda3       17814528 3341352  14473176  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@westosb ~]# mount //172.25.254.170/westos_share /mnt/ -o username=guest
[root@westosb ~]# df
Filesystem                    1K-blocks    Used Available Use% Mounted on
devtmpfs                         403532       0    403532   0% /dev
tmpfs                            419132       0    419132   0% /dev/shm
tmpfs                            419132    6300    412832   2% /run
tmpfs                            419132       0    419132   0% /sys/fs/cgroup
/dev/vda3                      17814528 3342364  14472164  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.170/westos_share  17814528 3397664  14416864  20% /mnt设定自动挂载
[root@westosb ~]# vim /etc/auto.master
/misc   /etc/auto.misc
/westos /etc/auto.share   ##/etc/auto.share 子挂载策略文件,此文件名称自定义,并且在系统中默认不存在##最终挂载的上层目录 /westos[root@westosb ~]# vim /etc/auto.share
samba   -fstype=cifs,username=westos,password=westos ://172.25.254.170/westos_share
samba ##最终挂载路径
-fstype=cifs,username=westos,passwrod=westos ##挂载参数
-fstype ##挂载资源的文件系统类型
username##使用samba用户名称
passwrod##使用用户的密码
://172.25.254.170/westos_share  ##挂载服务器ip及资源共享

自动挂载

设定自动挂载
[root@westosb ~]# vim /etc/auto.master
/misc   /etc/auto.misc
/westos /etc/auto.share   ##/etc/auto.share 子挂载策略文件,此文件名称自定义,并且在系统中默认不存在##最终挂载的上层目录 /westos[root@westosb ~]# vim /etc/auto.share
samba   -fstype=cifs,username=westos,password=westos ://172.25.254.170/westos_share
samba ##最终挂载路径
-fstype=cifs,username=westos,passwrod=westos ##挂载参数
-fstype ##挂载资源的文件系统类型
username##使用samba用户名称
passwrod##使用用户的密码
://172.25.254.170/westos_share  ##挂载服务器ip及资源共享[root@westosb ~]# vim /etc/autofs.conf
15 timeout = 5   ##更改为5秒无任何程序操作自动卸载
[root@westosb ~]# systemctl restart autofs.service  ##重启服务
[root@westosb ~]# cd /westos/samba
[root@westosb samba]# df
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 3343628  14470900  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.170/westos_share  17814528 3396644  14417884  20% /westos/samba
[root@westosb ~]# df
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 3343584  14470944  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@westosb ~]# mount //172.25.254.170/westos_share /mnt/ -o username=lee,password=lee  ##在客户端中root用户用自己的samba账号挂载了服务器的资源自己是可以游览的并使用的
[root@westosb ~]# 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 3343608  14470920  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.170/westos_share  17814528 3396644  14417884  20% /mnt
[root@westosb ~]# ls /mnt
file1  westosfile1  westosfile2  westosfile3
[root@westosb ~]# su - westos       ##westos用户没有通过任何samba认证也可以游览root用户挂载的samba服务器上的资源这样客户端就出现了严重的越级漏洞
Last login: Fri Mar 26 14:04:37 CST 2021 on tty2
[westos@westosb ~]$ ls /mnt
file1  westosfile1  westosfile2  westosfile3
[westos@westosb ~]$ [root@westosb ~]# dnf install cifs-utils -y   ##安装多用户认证安全插件[root@westosb ~]# vim /root/smbpass     ##当用户挂载需要账号密码  设定安全权限
[root@westosb ~]# chmod 600 /root/smbpass
[root@westosb ~]# cat /root/smbpassusername=lee
password=lee[root@westosb ~]# umount /mnt
[root@westosb ~]# mount -o credentials=/root/smbpass,multiuser//172.25.254.170/westos_share /mnt  ##多用户指定认证参数当挂载是添加此参数没有通过认证的用户不可以使用samba上的资源
[root@westosb ~]# su - westos
Last login: Tue Aug 10 23:03:37 CST 2021 on pts/0
[westos@westosb ~]$ ls /mnt
ls: cannot access '/mnt': Permission denied
[westos@westosb ~]$ [root@westosb ~]# mount -o credentials=/root/smbpass,multiuser,sec=ntlmssp //172.25.254.170/westos_share /mnt  ##用户使用到的认证方式

####NFS####
Net File System

####nfs基本信息####
nfs-utils         ##安装包
nfs-server                ##服务脚本

/etc/exports        ##共享配置文件

####nfs的启用####

虚拟机a下载
[root@westoslinux ~]# dnf install nfs-utils.x86_64 -y     ##下载nfs
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: 12:27:09 ago on Tue 10 Aug 2021 08:49:57 PM CST.
Package nfs-utils-1:2.3.3-31.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete![root@westoslinux ~]# 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@westoslinux ~]# netstat  -antlupe | grep 2049   ##端口2049
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      0          36450      -
tcp6       0      0 :::2049                 :::*                    LISTEN      0          36461      -                   去虚拟机b测试
[root@westosb ~]# showmount -e 172.25.254.170  ##被拒绝
clnt_create: RPC: Unable to receive
去虚拟机a添加服务
[root@westoslinux ~]# firewall-cmd --permanent --add-service=nfs
success
[root@westoslinux ~]# firewall-cmd --permanent --add-service=mountd
success
[root@westoslinux ~]# firewall-cmd --permanent --add-service=rpc-bind
success
[root@westoslinux ~]# firewall-cmd --reload
success
去虚拟机b测试
[root@westosb ~]# showmount -e 172.25.254.170   ##访问成功
Export list for 172.25.254.170:   [root@westoslinux ~]# mkdir /westosdir
[root@westoslinux ~]# ls -ld /westosdir/
drwxr-xr-x. 2 root root 6 Aug 11 10:06 /westosdir/
[root@westoslinux ~]# chmod 777 /westosdir/
[root@westoslinux ~]# vim /etc/exports
/westosdir      *(ro,sync) 172.25.254.171(rw,sync,anonuid=1000,anongid=1000)
[root@westoslinux ~]# exportfs -rv

####nfs配置参数###

anonuid=1000,anongid=1000        ##指定用户身份
sync                                                ##更改生成后同步数据到服务器
async                                        ##时时同步数据到服务器
rw                                                ##读写
ro                                                ##只读
no_root_squash                                ##root用户挂载不转换身份

####nfs+autofs#######

autofa自动挂载和卸载(客户端)
[root@westosb ~]# dnf install autofs -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: 13:28:23 ago on Tue 10 Aug 2021 09:09:49 PM CST.
Package autofs-1:5.1.4-40.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@westosb ~]# vim /etc/auto.master
/misc   /etc/auto.misc
#/westos /etc/auto.share  ##注释掉
/westos /etc/auto.nfs   ##  添加/westos最终挂载点          /etc/auto.nfs##子策略文件[root@westosb ~]# vim /etc/auto.nfs
nfs     -rw     172.25.254.170:/westosdir
nfs  ##最终挂载的相对路径
-rw  挂载参数172.25.254.170:/westosdir    nfs服务器上共享出来的资源
[root@westosb ~]# systemctl restart autofs.service
[root@westosb ~]# cd /westos/nfs     ##cd过来自动挂载
[root@westosb 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 3343108  14471420  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.170:/westosdir  17814528 3346688  14467840  19% /westos/nfs
[root@westosb nfs]# cd
[root@westosb ~]# df     ##自动卸载
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 3343088  14471440  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#########

打开虚拟机控制创建5g的硬盘
[root@westos_student70 ~]# virt-manager
[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/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[root@westoslinux ~]# fdisk /dev/vdbWelcome 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 0x2d5bd4a0.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): +2G   ##2gCreated a new partition 1 of type 'Linux' and of size 2 GiB.Command (m for help): wq    ##保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.[root@westoslinux ~]# fdisk -l        ##查看
Device     Boot Start     End Sectors Size Id Type
/dev/vdb1        2048 4196351 4194304   2G 83 Linux[root@westoslinux ~]# dnf install targetcli -y   ##下载服务
[root@westoslinux ~]# systemctl enable --now target   ##开启服务
Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.
[root@westoslinux ~]# 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 ##westos:storage1在此软件中设备的别名/dev/vdb1系统中真实设备
Created block storage object westos:storage1 using /dev/vdb1.
/> /iscsi create iqn.2021-08.org.westos:storage1  ##建立对外的共享名称,iqn的命名方式iscsi限定名称  格式iqn。YYY-MM。域名:别名
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##为共享设备设定访问key             westoskey加密字符
Created Node ACL for iqn.2021-08.org.westos:westoskey
Created mapped LUN 0.
/> exit ##########
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json去客户主机
[root@westosb ~]# dnf search iscsi   ##查找下载包
[root@westosb ~]# dnf install iscsi-initiator-utils.x86_64 -y   ##下载客户端软件
[root@westosb ~]# systemctl status iscsid  ##对客户端配置控制服务
● iscsid.service - Open-iSCSILoaded: loaded (/usr/lib/systemd/system/iscsid.service; disabled; vendor preset: disabled)Active: inactive (dead) since Wed 2021-08-11 13:23:25 CST; 2s agoDocs: man:iscsid(8)man:iscsiuio(8)man:iscsiadm(8)
[root@westosb ~]# systemctl status iscsi         ##客户端对于资源利用的服务
● iscsi.service - Login and scanning of iSCSI devicesLoaded: loaded (/usr/lib/systemd/system/iscsi.service; enabled; vendor preset: disabled)Active: inactive (dead)
Condition: start condition failed at Wed 2021-08-11 09:15:09 CST; 4h 8min ago└─ ConditionDirectoryNotEmpty=/var/lib/iscsi/nodes was not metDocs: man:iscsiadm(8)man:iscsid(8)[root@westosb ~]# iscsiadm -m discovery -t st -p 172.25.254.170   ##-m mode  | -t 指定要识别的设备 -p 指定资源主机ip
iscsiadm: cannot make connection to 172.25.254.170: No route to host  ##失败需要设定170的火墙
iscsiadm: cannot make connection to 172.25.254.170: No route to host在服务器上设定
[root@westoslinux ~]# firewall-cmd --permanent --add-port=3260/tcp   ##添加端口
success
[root@westoslinux ~]# firewall-cmd --reload
success
返回客户端[root@westosb ~]# iscsiadm -m discovery -t st -p 172.25.254.170
172.25.254.170:3260,1 iqn.2021-08.org.westos:storage1        ######共享信息成功[root@westosb ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.170 -l  ##-T指定要访问的共享设备名称  -l登陆共享设备
Logging in to [iface: default, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.170,3260]
iscsiadm: Could not login to [iface: default, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.170,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)  ##不指定key无法登录
[root@westosb ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2021-08.org.westos:westoskey
[root@westosb ~]# systemctl restart iscsid.service [root@westosb ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.170 -l
Logging in to [iface: default, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.170,3260]
Login to [iface: default, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.170,3260] successful.   ##成功[root@westosb ~]# fdisk -l    ##可以看到共享设备的大小
Disk /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@westosb ~]# fdisk /dev/sda       ##n添加回车wq保存Welcome 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 0x3c9f8b64.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.Command (m for help): wq[root@westosb ~]# mkfs.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@westosb ~]#mount /dev/sda1 /mnt

删除

删除[root@westosb ~]# vim /etc/fstab
UUID=1ac4cd34-4737-4e08-8226-7a6675a445a6 /mnt/   xfs   defaults 0 0[root@westosb ~]# reboot  ##系统起不来等到超过时间延迟
输入超级用户密码进入shll
vim /etc/fstab
UUID=1ac4cd34-4737-4e08-8226-7a6675a445a6 /mnt/   xfs   defaults,_netdev 0 0
再次重启   就可以进去了
[root@westosb ~]# df     ##/mnt/已经挂载上了
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          403532       0    403532   0% /dev
tmpfs             419132       0    419132   0% /dev/shm
tmpfs             419132    6352    412780   2% /run
tmpfs             419132       0    419132   0% /sys/fs/cgroup
/dev/vda3       17814528 3342968  14471560  19% /
/dev/vda1        1038336  173320    865016  17% /boot
tmpfs              83824    1180     82644   2% /run/user/42
/dev/sda1        2085888   47580   2038308   3% /mnt
tmpfs              83824       4     83820   1% /run/user/0删除
[root@westosb ~]# vim /etc/fstab
UUID="1ac4cd34-4737-4e08-8226-7a6675a445a6 /mnt/   xfs   defaults,_netdev 0 0
[root@westosb ~]# umount /mnt
[root@westosb ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2021-08.org.westos:storage1
│       └── 172.25.254.170,3260,1
│           └── default
├── send_targets
│   ├── 172.25.254.170,3260
│   │   ├── iqn.2021-08.org.westos:storage1,172.25.254.170,3260,1,default -> /var/lib/iscsi/nodes/iqn.2021-08.org.westos:storage1/172.25.254.170,3260,1
│   │   └── st_config
│   └── 172.25.254.171,3260
│       └── st_config
├── slp
└── static[root@westosb ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.170 -u   ##-u是删除
Logging out of session [sid: 2, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.170,3260]
Logout of [sid: 2, target: iqn.2021-08.org.westos:storage1, portal: 172.25.254.170,3260] successful.
[root@westosb ~]# iscsiadm -m node -T iqn.2021-08.org.westos:storage1 -p 172.25.254.170 -o delete ##删除客户主机中此网络设备的数据[root@westosb ~]# tree /var/lib/iscsi/   ##查看是否删除掉了
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
│   ├── 172.25.254.170,3260
│   │   └── st_config
│   └── 172.25.254.171,3260
│       └── st_config
├── slp
└── static8 directories, 2 files
[root@westosb ~]# 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 ~]# 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]
/> help  ##可以提供删除参数The following commands are available in the
current path:- bookmarks action [bookmark] - cd [path] - clearconfig [confirm] - exit - get [group] [parameter...] - help [topic] - ls [path] [depth] - pwd - refresh - restoreconfig [savefile] [clear_existing] [target] [storage_object] - saveconfig [savefile] - sessions [action] [sid] - set [group] [parameter=value...] - status - version
/> clearconfig
As a precaution, confirm=True needs to be set    ##提示添加参数
/> clearconfig confirm=True    ##删除
All configuration cleared
/> 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]
/>

3-5 linux 网络文件系统相关推荐

  1. linux网络文件系统包括,Linux文件系统

    在Linux系统中,所有的目录和文件数据都是以一个树形的结构进行存储,整个系统中只存在一个根目录,所有的分区.目录.文件都在同一个根目录下面."/"下面的第一层目录包括:/bin: ...

  2. windows挂载linux网络文件系统NFS

    ubuntu上安装配置nfs服务 #apt-get install nfs-kernel-server #mkdir /home/nfs #vim /etc/exports 在文档的最后一行加入/ho ...

  3. Linux下NFS(网络文件系统)的建立与配置方法

    网络文件系统( NFS ,Network File System)是一种将远程主机上的分区(目录)经网络挂载到本地系统的一种机制,通过对网络文件系统的支持,用户可以在本地系统上像操作本地分区一样来对远 ...

  4. linux 挂载网络文件系统,[arm-linux-FL2440挂载网络文件系统共享文件]

    首先确保arm板上移植的内核开启了网络文件系统 配置开发板Linux内核,开启NFS客户端,如下界面所示,可能有的配置界面不同,具体设置:File system → Network File Syst ...

  5. 8s nfs 挂载文件_把你的树莓派家庭实验室变成一个网络文件系统 | Linux 中国

    导读:使用 NFS 服务器将共享文件系统添加到你的家庭实验室. 本文字数:8554,阅读时长大约:12分钟https://linux.cn/article-12413-1.html作者:Chris C ...

  6. linux通过网关挂在nfs,NFS 网络文件系统挂载在A8板子上

    我承认自己是菜鸟,没什么网络知识就来搞挂载nfs网络文件系统,花费了5天的时间才把nfs网络文件系统成功挂载在A8板子上,实现了A8板子和虚拟机的文件共享.分享一下个人经验: 以下是基于nfs已经完成 ...

  7. linux上ftp和ns有什么区别,Linux下ftp使用及nfs网络文件系统

    ftp 是一个文件传输协议 ,是tcp/ip 文件传输协议的一种 ftp可以用与文件的共享也可以用于文件的固定IP的收集 Linux下使用说明: 首先我们需要安装ftp程序 yum -y instal ...

  8. linux挂在网络文件系统出现 INFO: taskblocked formorethan120 seconds 问题

    事情是这样的,这几天都在搞挂在网络文件系统,想尝鲜用了ubuntu22,将旧版本的ubuntu里面制作的文件系统复制到新的ubuntu22后,挂载文件系统总是提示INFO: taskblocked f ...

  9. linux学习笔记-RH135(六):网络文件系统

    网络文件系统 一.samba服务 1.samba基本信息 2.samba的安装与启用 3.samba用户的建立 4.samba用户访问家目录 6.samba访问控制 7.samba的常用配置参数 8. ...

最新文章

  1. java中匿名内部类详解_java 中匿名内部类的实例详解
  2. 【 Verilog HDL 】寄存器数据类型(reg)与线网数据类型(wire,tri)
  3. 著名ERP厂商的SSO单点登录解决方案介绍一
  4. c语言注释的开始标记符和结束标记符分别为,C语言程序设计填空题
  5. 飞鸽传书:浅谈 Scrum
  6. c++-虚函数与多态
  7. python制作gif动图_Python几行代码制作Gif动图
  8. 详解百度地图API之地图操作
  9. 史上最详细的hadoop安装教程(含坑点)
  10. 与卿共赴鸿蒙是什么意思,经典的爱情诗句
  11. JavaScript面试题
  12. 2018网易互娱笔试1——花砖拼接C++
  13. css超出两行省略号没效果,Css 设置超过再两行显示省略号
  14. KNN算法原理与自实现电影分类
  15. Shell脚本循环语句及exit、continue和break用法
  16. 为文件夹属性添加安全标签的方法
  17. 阿信歌词很美,因为心中有至爱的人
  18. CentOS7中如何输入中文?
  19. mysql用脚本导入csv_用脚本把csv文件导入mysql
  20. python中的StratifiedKFold

热门文章

  1. 使用canmatrix工具完成DBC与xls文件转换
  2. 同步Android手机联系人到iPhone手机通讯录
  3. 河南计算机专业对口大专,计算机专业河南专科院校排名
  4. MySQL之INNER JOIN的用法
  5. Python OpenCV浅析3种滤镜效果
  6. 经典卷积模型(四)GoogLeNet-Inception(V3)代码解析
  7. 自定义view实战(10):贝塞尔曲线绘制小红点
  8. 华为AAA和RADIUS协议配置
  9. android设备断电丢失数据(设备断电重启后WIFI不能自动重连)
  10. 小视频伪原创 抖音发视频要改MD5值