网络文件系统

  • Post author:
  • Post category:其他


实验环境:

[root@westos_student50 Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-ens160

[root@westos_student50 Desktop]# nmcli  connection reload

[root@westos_student50 Desktop]# nmcli  connection up ens160

[root@westos_student50 ~]# mkdir /zcx

[root@westos_student50 ~]# mount /iso/rhel-8.2-x86_64-dvd.iso /zcx

[root@westos_student50 Desktop]# cd /etc/yum.repos.d

[root@westos_student50 yum.repos.d]# vim westos.repo

Windows:

创建一个新用户westos

关闭防火墙

测试虚拟机是否可以列出:

[root@westos_student50 ~]# dnf install  samba-client -y 下载

[root@westos_student50 Desktop]# smbclient -L //192.168.0.101 -U westos连接windows  列出westos的共享

root@westos_student50 ~]# smbclient //192.168.0.101/westos-test -U westos 共享Windows中的westos-test文件

[root@westos_student50 ~]# mount -o username=westos,password=westos //192.168.0.101/westos-test /mnt  把共享的文件挂载在/mnt里

[root@westos_student50 ~]# touch /mnt/westosfile{1..10} 创建Windows中的文件

[root@westos_student50 mnt]# rm -rf * 删除Windows中的内容


1.samba


服务简介


smb




=




Server Message Block Sum


cifs




=




Common Internet File System Miscrosoft


windows系统共享文件时用到的协议cifs


smb是由miscrosoft




+




sun


Linux


用的时smb


2.samba


的安装与启用

[root@westos_student50 ~]# dnf install samba samba-common samba-client -y 下载

[root@westos_student50 samba]# firewall-cmd –permanent –add-service=samba

[root@westos_student50 samba]# firewall-cmd –reload

[root@westos_student50 samba]# firewall-cmd –add-service=samba-client

测试:


3.samba


用户的建立


[root@westos_student50 samba]# useradd lee

[root@westos_student50 samba]# smbpasswd -a westos  建立westos

[root@westos_student50 samba]# smbpasswd -a lee    建立lee

[root@westos_student50 samba]# pdbedit -L   查看用户

[root@westos_student50 samba]# pdbedit -x westos    删除用户westos


4.


samba


用户访问加目录

[root@westos_student50 ~]# setsebool -P samba_create_home_dirs on设定家目录可以建立文件

[root@westos_student50 ~]# setsebool -P samba_enable_home_dirs on设定可以访问家目录


windows下






linux







5.


samba服务共享目录

[root@westos_student50 ~]# mkdir /westos

[root@westos_student50 ~]# vim /etc/samba/smb.conf

root@westos_student50 ~]#

s


emanage fcontext









a









t samba_share_t


‘/westos(/.*)?’

[root@westos_student50 ~]#

restorecon









RvvF




/




westos




/






刷新


[root@westos_student50 ~]#

systemctl restart smb


重启服务




测试:



[roo


t@westos_student50 ~]# setsebool -P samba_export_all_rw on


打开安全上下文的读写


测试:在windows中看是否有mnt目录


6.


samba


的访问控制(当写到





GLOBAL





时对


samba


整体生效)

[root@westos_student50 ~]# vim /etc/samba/smb.conf  不允许192.168.155.60登陆


[root@westos_student50 ~]# systemctl restart smb.service


[root@westos_student50 ~]# smbclient -L //192.168.155.60 -U lee

[root@westos_student50 ~]# vim /etc/samba/smb.conf  只允许192.168.155.70登陆

[root@westos_student50 ~]# systemctl restart smb.service

[root@westos_student50 ~]# smbclient -L //192.168.155.60 -U lee

[root@westos_student50 ~]# vim /etc/samba/smb.conf(

当写到单独共享时之对此共享生效

[root@westos_student50 ~]# systemctl restart smb.service

[root@westos_student50 ~]# smbclient //192.168.155.60/storage1 -U lee


7.


samba


的常用配置参数

[root@westos_student50 Desktop]# chmod 777 /westos

[root@westos_student50 Desktop]# mount -o username=westos,password=lee //192.168.0.70/storage1 /mnt

[root@westos_student50 Desktop]# vim /etc/samba/smb.conf

[root@westos_student50 Desktop]# systemctl restart smb

[root@westos_student50 Desktop]# touch /mnt/file1 建立成功代表可写

[root@westos_student50 Desktop]# vim /etc/samba/smb.conf

[root@westos_student50 Desktop]# systemctl restart smb

[root@westos_student50 Desktop]# touch /mnt/file2 使用westos身份挂载不可写

[root@westos_student50 Desktop]# mount -o username=lee,password=lee //192.168.0.70/storage1 /mnt

[root@westos_student50 Desktop]# touch /mnt/file2用lee身份挂载可写


[root@westos_student50 Desktop]# vim /etc/samba/smb.conf只有lee组成员可以建立

[root@westos_student50 Desktop]# systemctl restart smb

[root@westos_student50 Desktop]# usermod -G lee westos   添加组成员lee

[root@westos_student50 Desktop]# touch /mnt/file3   可写


[root@westos_student50 Desktop]# vim /etc/samba/smb.conf   只有westos用户可以访问

[root@westos_student50 Desktop]# systemctl restart smb

[root@westos_student50 Desktop]# umount /mnt卸载

[root@westos_student50 Desktop]# mount -o username=westos,password=lee //192.168.0.70/storage1 /mnt使用westos可以挂载

[root@westos_student50 Desktop]# mount -o username=lee,password=lee //192.168.0.70/storage1 /mnt使用lee不可以挂载

[root@westos_student50 Desktop]# vim /etc/samba/smb.conf只有westos组成员才可以访问

[root@westos_student50 Desktop]# systemctl restart smb

[root@westos_student50 Desktop]# usermod -G westos lee赋予组成员身份


[root@westos_student50 Desktop]# vim /etc/samba/smb.conf

[root@westos_student50 Desktop]# systemctl restart smb.service

[root@westos_student50 Desktop]# smbclient -L //192.168.0.70 -U westos

[root@westos_student50 Desktop]# smbclient //192.168.0.70/storage1 -U westos本地用户实名可以登陆

[root@westos_student50 Desktop]# smbclient //192.168.0.70/storage1 匿名用户无法访问

[root@westos_student50 Desktop]# vim /etc/samba/smb.conf

[root@westos_student50 Desktop]# systemctl restart smb.service

[root@westos_student50 Desktop]# smbclient //192.168.0.70/storage1 匿名用户可以访问

[root@westos_student50 Desktop]# systemctl restart smb.service

[root@westos_student50 Desktop]# vim /etc/samba/smb.conf

[root@westos_student50 Desktop]# systemctl restart smb.service

[root@westos_student50 Desktop]# mount -o username=westos,password=lee //192.168.0.70/storage1 /mnt

[root@westos_student50 Desktop]# touch /mnt/file4

[root@westos_student50 Desktop]# ls -l /westos

9.

samba的多用户挂载


1).


autofs




+




samba自动挂载与卸载


(客户端优化)

在192.168.0.80(squid)主机中:

[root@westos_student50 ~]# dnf install autofs -y

[root@westos_student50 ~]# vim /etc/auto.master

[root@westos_squid ~]# vim /etc/auto.samba

[root@westos_squid ~]# systemctl enable –now autofs.service

[root@westos_squid ~]# cd /samba

[root@westos_squid samba]# cd storage1

[root@westos_squid storage1]# df

[root@westos_squid storage1]# cd

[root@westos_squid ~]# vim /etc/autofs.conf


[root@westos_squid ~]# systemctl restart autofs.service

[root@westos_squid storage1]# dnf install cifs-utils -y

[root@westos_squid storage1]# vim /root/authsamba

[root@westos_squid storage1]# chmod 600 /root/authsamba

[root@westos_squid storage1]# vim /etc/auto.samba

[root@westos_squid storage1]# cat /etc/auto.samba storage1

-fstype=cifs,credentials=/root/authsamba        ://192.168.0.70/storage1

[root@westos_squid storage1]# systemctl restart autofs.service

[root@westos_squid storage1]# cd /samba/storage1

[root@westos_squid storage1]# mount

[root@westos_squid storage1]# su – westos

[westos@westos_squid ~]$ cd /samba/storage1

[westos@westos_squid storage1]$ touch file

touch: cannot touch ‘file’: Permission denied

[root@westos_squid ~]# vim /etc/auto.samba

[root@westos_squid ~]# systemctl restart autofs.service

[root@westos_squid ~]# su – westos

[westos@westos_squid ~]$ cd /samba/storage1

[westos@westos_squid storage1]$ ls

[westos@westos_squid storage1]$ cifscreds  add -u lee 192.168.0.70

[westos@westos_squid storage1]$ ls

[westos@westos_squid storage1]$ cifscreds clearall   清除

3).nfs

[root@westos_student50 ~]# dnf install nfs-utils -y

[root@westos_student50 ~]# systemctl enable –now nfs-server

[root@westos_student50 ~]# firewall-cmd –permanent –add-service=rpc-bind

[root@westos_student50 ~]# firewall-cmd –reload

[root@westos_student50 ~]# firewall-cmd –permanent –add-service=mountd

[root@westos_student50 ~]# firewall-cmd –reload

[root@westos_student50 ~]# firewall-cmd –permanent –add-service=nfs

[root@westos_student50 ~]# firewall-cmd –reload

[root@westos_student50 ~]# vim /etc/exports

[root@westos_student50 ~]# exportfs -rv

[root@westos_squid ~]# showmount -e 192.168.0.70

rpc mount export: RPC: Unable to receive; errno = No route to host

[root@westos_squid ~]# showmount -e 192.168.0.70

Export list for 192.168.0.70:

[root@westos_squid ~]# showmount -e 192.168.0.70

Export list for 192.168.0.70:

[root@westos_squid ~]# showmount -e 192.168.0.70

Export list for 192.168.0.70:

/westos *

[root@westos_squid ~]# mount 192.168.0.70:/westos /mnt

[root@westos_squid ~]# df


nfs


配置参数




anonuid




=




1000


,anongid




=




1000


指定用户身份


sync


更改生成后同步数据到服务器


async


时时同步数据到服务器


rw


读写


ro


只读


no_root_squash                      root


用户挂载不转换身份


[root@westos_student50 ~]# vim /etc/exports


[root@westos_student50 ~]# exportfs -rv


[root@westos_squid ~]# cd /mnt


[root@westos_squid mnt]# touch file6


[root@westos_student50 ~]# ls -l /westos

[root@westos_student50 ~]# vim /etc/exports

[root@westos_student50 ~]# exportfs -rv

[root@westos_squid mnt]# touch file7

[root@westos_student50 ~]# ls -l /westos

[root@westos_student50 ~]# vim /etc/exports

[root@westos_student50 ~]# exportfs -rv

[root@westos_squid mnt]# touch file8

[root@westos_student50 ~]# ls -l /westos

[root@westos_student50 ~]# vim /etc/exports

[root@westos_student50 ~]# exportfs -rv

[root@westos_squid mnt]# touch file9

[root@westos_student50 ~]# ls -l /westos


#nfs




+




autofs

[root@westos_squid ~]# vim /etc/auto.master


[root@westos_squid ~]# vim /etc/auto.nfs

[root@westos_squid ~]# systemctl restart autofs.service

[root@westos_squid ~]# cd /westos/lee

[root@westos_squid lee]# df

[root@westos_squid lee]# cd

[root@westos_squid ~]# df


10.iscsi


[root@westos_linux Desktop]# fdisk /dev/sdb

[root@westos_linux Desktop]# udevadm settle

[root@westos_linux Desktop]# dnf install targetcli -y

[root@westos_linux Desktop]# systemctl enable –now targetclid.service

[root@westos_linux Desktop]# systemctl enable –now target.service

[root@westos_linux Desktop]# targetcli

[root@westos_linux Desktop]# firewall-cmd –permanent –add-port=3260/tcp

[root@westos_linux Desktop]# firewall-cmd –reload

[root@westos_squid ~]# dnf install iscsi-initiator-utils.x86_64 -y

[root@westos_squid ~]# iscsiadm -m node -T iqn.2022-07.org.westos:strage1 -p 192.168.0.70 -l

[root@westos_squid ~]# vim /etc/iscsi/initiatorname.iscsi

[root@westos_squid ~]# systemctl restart iscsid

[root@westos_squid ~]# iscsiadm -m node -T iqn.2022-07.org.westos:strage1 -p 192.168.0.70 -l

[root@westos_squid ~]# fdisk /dev/sdb

[root@westos_squid ~]# udevadm settle

[root@westos_squid ~]# mkfs.xfs /dev/sdb1

[root@westos_squid ~]# mount /dev/sdb1 /mnt

[root@westos_squid ~]# df

[root@westos_squid ~]# blkid

[root@westos_squid ~]# vim /etc/fstab

[root@westos_squid ~]# mount -a

[root@westos_squid ~]# df

删除:

[root@westos_linux Desktop]# targetcli


root@westos_squid ~]# vim /etc/fstab

[root@westos_squid ~]# umount /mnt

[root@westos_squid ~]# iscsiadm -m node -T iqn.2022-07.org.westos:strage1 -p 192.168.0.70 -u 登出

[root@westos_squid ~]# tree /var/lib/iscsi/

[root@westos_squid ~]# iscsiadm -m node -T iqn.2022-07.org.westos:strage1 -p 192.168.0.70 -o delete

[root@westos_squid ~]# tree /var/lib/iscsi/



版权声明:本文为z17609273238原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。