Linux   samba基础   NFS基础

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux   samba基础   NFS基础相关的知识,希望对你有一定的参考价值。


两台虚拟机,均要检测


1. Yum是否可用

2.  防火墙默认区域修改为trusted

3. IP地址是否配置



####################################################


  samba 文件共享(共享文件夹)


Samba 软件项目

– 用途:为客户机提供共享使用的文件夹

– 协议:SMB(TCP 139)、CIFS(TCP 445)


所需软件包:samba

系统服务:smb




一、搭建基本samba服务

1.安装samba软件包

2.创建samba的共享帐号。与系统相同用户名,不同密码


[[email protected] ~]# useradd -s /sbin/nologin harry

[[email protected] ~]# useradd -s /sbin/nologin kenji

[[email protected] ~]# useradd -s /sbin/nologin chihiro


[[email protected] ~]# pdbedit -a harry    #添加samba帐号,设置密码

[[email protected] ~]# pdbedit -a kenji    #添加samba帐号,设置密码

[[email protected] ~]# pdbedit -a chihiro  #添加samba帐号,设置密码


[[email protected] ~]# pdbedit -L        #列出所有有效的samba帐号


3.修改服务配置文件 /etc/samba/smb.conf

 

   补充:vim   末行模式    set  nu  添加行号


    89行          workgroup = STAFF

    321行     [common]                          #共享名

    322行        path = /common      #共享实际路径


[[email protected] ~]# mkdir /common

[[email protected] ~]# echo haha > /common/abc.txt


4. 重起smb服务,设置为开机自起


虚拟机Desktop0

所需软件包:samba-client


[[email protected] ~]# smbclient -L //172.25.0.11

Enter root‘s password: 


[[email protected] ~]# smbclient -U harry //172.25.0.11/common

Enter harry‘s password: 

Domain=[STAFF] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

NT_STATUS_ACCESS_DENIED listing \*


思路:客户端访问服务端资源

    1.防火墙是否限制

    2.服务本身的访问控制

  3.SELinux 是否限制 


  SELinux:  布尔值  (功能的开关)


getsebool 查看 SELinux 开关

[[email protected] ~]# getsebool -a | grep samba

samba_export_all_ro --> off

samba_export_all_rw --> off


setsebool 控制 SELinux 开关

– 需要加 -P 选项才能实现永久设置

[[email protected] ~]# setsebool  samba_export_all_ro=on

[[email protected] ~]# getsebool -a | grep samba


虚拟机Desktop0

[[email protected] ~]# smbclient -U harry //172.25.0.11/common

Enter harry‘s password: 

Domain=[STAFF] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls


所需软件包:cifs-utils


  _netdev: 开启网络服务后在改在该设备


1.安装软件包cifs-utils

2.修改/etc/fstab


//172.25.0.11/common /mnt/samba cifs user=harry,pass=123,_netdev 0  0


3. mount -a  验证

   df   -h




########################################################

 Samba读写的共享


1.修改配置文件/etc/samba/smb.conf


 [devops]

   path = /devops

   write list = chihiro


[[email protected] /]# mkdir /devops

[[email protected] /]# echo hahaxixi > /devops/123.txt

2.重起smb服务

3.客户端验证:

[[email protected] ~]# smbclient  -L   172.25.0.11

Enter root‘s password: 


4.客户端挂载验证

[[email protected] ~]# mkdir /mnt/dev

[[email protected] ~]# vim /etc/fstab 

//172.25.0.11/devops /mnt/dev cifs user=chihiro,pass=123,_netdev 0  0

[[email protected] ~]# mount -a

[[email protected] ~]# df -h


##################################################

实现读写Samba共享的其他操作


思路:客户端访问服务端资源

    1.防火墙是否限制

    2.服务本身的访问控制

  3.SELinux 是否限制 

    4. 服务端目录本地权限


一、修改服务端SELinux布尔值,开放读写

[[email protected] /]# getsebool -a | grep samba

[[email protected] /]# setsebool samba_export_all_rw=on

[[email protected] /]# getsebool -a | grep samba


二、目录本地权限

[[email protected] /]# ls -ld /devops/

[[email protected] /]# setfacl -m u:chihiro:rwx /devops/

[[email protected] /]# getfacl   /devops/


三、客户端验证

[[email protected] ~]# touch /mnt/dev/test.txt


########################################################

 multiuser多用户访问(了解)


– multiuser,提供对客户端多个用户身份的区分支持

– sec=ntlmssp,提供NT局域网管理安全支持


客户端完成:

[[email protected] /]# vim  /etc/fstab

//172.25.0.11/devops /mnt/dev cifs user=kenji,pass=123,_netdev,multiuser,sec=ntlmssp 0  0


[[email protected] /]# umount /mnt/dev/

[[email protected] /]# mount -a

[[email protected] /]# df -h


[[email protected] /]# su - student

[[email protected] dev]$ cd /mnt/dev

[[email protected] dev]$ cifscreds add -u chihiro 172.25.0.11

Password: 

[[email protected] dev]$ ls

[[email protected] dev]$ touch abc.txt

[[email protected] dev]$ exit


#########################################################

 配置NFS共享


Network File System,网络文件系统

– 用途:为客户机提供共享使用的文件夹

– 协议:NFS(TCP/UDP 2049)、RPC(TCP/UDP 111)


所需软件包: nfs-utils

系统服务: nfs-server


搭建基本的只读NFS服务

1.在虚拟机server0上,检测nfs-utils是否安装

[[email protected] /]# rpm -q nfs-utils


2.修改配置文件/etc/exports

[[email protected] /]# mkdir /public

[[email protected] /]# echo hehelele > /public/nsd.txt

[[email protected] /]# vim /etc/exports


/public   172.25.0.0/24(ro)

 

3.重起nfs-server服务,设置开机自起

[[email protected] /]# systemctl restart  nfs-server

[[email protected] /]# systemctl enable  nfs-server


4.客户端  访问nfs-server服务

[[email protected] /]# mkdir /mnt/nfs

[[email protected] /]# showmount -e 172.25.0.11

[[email protected] /]# vim /etc/fstab 


 172.25.0.11:/public /mnt/nfs  nfs  _netdev 0 0


[[email protected] /]# mount -a

[[email protected] /]# ls  /mnt/nfs

#######################################################


  读写nfs-server服务


一.客户端root用户的读写

服务端:

[[email protected] /]# mkdir /abc

[[email protected] /]# echo 123 > /abc/a.txt

[[email protected] /]# vim /etc/exports

  /abc   172.25.0.0/24(rw)


[[email protected] /]# systemctl restart nfs-server


客户端:

[[email protected] /]# vim /etc/fstab 

172.25.0.11:/abc /mnt/nsd  nfs  _netdev 0 0


[[email protected] /]# mkdir /mnt/nsd

[[email protected] /]# mount -a

[[email protected] /]# df -h


服务端:

[[email protected] /]# vim /etc/exports

/abc   172.25.0.0/24(rw,no_root_squash)    #不压榨客户端root权限


[[email protected] /]# systemctl restart nfs-server


客户端:


[[email protected] /]# systemctl  restart nfs  #重起客户端服务

[[email protected] /]# touch /mnt/nsd/5.txt



二、普通用户

  

     客户端普通用户访问服务端nfs-server服务,

     服务端会以客户端相同UID身份的本地用户进行权限判定


    LDAP :  网络用户,提供用户名

    kerberos : 密码验证,实现“一次密码认证,多次免密登录”的通行证机制


服务端:

[[email protected] /]# lab  nfskrb5  setup

[[email protected] /]# grep ldapuser0 /etc/passwd

[[email protected] /]# id ldapuser0


1.部署kerberos加密的密钥文件

wget http://172.25.254.254/pub/keytabs/server0.keytab -O /etc/krb5.keytab

[[email protected] /]# ls /etc/krb5.keytab 


2.修改配置文件

[[email protected] /]# vim /etc/exports

 /abc   172.25.0.0/24(rw,no_root_squash,sec=krb5p)


3.重起nfs-server与nfs-secure-server

# systemctl restart nfs-server  nfs-secure-server




客户端:

[[email protected] /]# lab  nfskrb5  setup

[[email protected] /]# grep ldapuser0 /etc/passwd

[[email protected] /]# id ldapuser0


1.部署kerberos加密的密钥文件

wget http://172.25.254.254/pub/keytabs/desktop0.keytab -O /etc/krb5.keytab


[[email protected] /]# ls /etc/krb5.keytab 


2.修改/etc/fstab

172.25.0.11:/abc /mnt/nsd  nfs  _netdev,sec=krb5p 0 0


3.重起nfs与nfs-secure服务

[[email protected] /]# systemctl restart nfs  nfs-secure


4.验证挂载

[[email protected] /]# umount /mnt/nsd

[[email protected]top0 /]# mount -a

[[email protected] /]# df -ah





以上是关于Linux   samba基础   NFS基础的主要内容,如果未能解决你的问题,请参考以下文章

Linux   samba基础   NFS基础

linux操作系统基础篇

linux基础-第十七单元 Samba服务

Python学习day9--linux基础

Linux基础网络设置和Samba文件共享服务

Samba Linux 和windows 共享