NFS(Network File System)网络文件系统html
企业应用:为集群中的web server提供后端存储ios
该服务包括的组件:web
RPC(Remote Procedure Call Protocol):shell
远程过程调用协议,它是一种经过从网络从远程计算机程序上请求服务;不须要了解底层网络技术的协议。数据库
rpcbind //负责NFS的数据传输,远程过程调用tcp协议 端口111vim
nfs-utils //控制共享哪些文件,权限管理后端
[root@server ~]# rpm -q rpcbind rpcbind-0.2.0-11.el6.x86_64 [root@server ~]# rpm -aq|grep ^nfs nfs-utils-1.2.3-54.el6.x86_64 nfs-utils-lib-1.1.5-9.el6.x86_64 nfs4-acl-tools-0.3.3-6.el6.x86_64
```powershell~~~
/etc/exports (man 5 exports
共享目录 共享选项
/nfs/share (ro,sync)
共享主机:
:表明全部主机
192.168.1.0/24表明共享给某个网段
192.168.1.0/24(rw) 192.168.1.0/24(ro):表明共享给不一样网段
192.168.1.254:共享给某个IP
*.uplook.com:表明共享给某个域下的全部主机
共享选项:
ro:只读
rw:读写
sync:实时同步,直接写入磁盘
async:异步,先缓存在内存再同步磁盘
anonuid:设置访问nfs服务的用户的uid,uid须要在/etc/passwd中存在
anongid:设置访问nfs服务的用户gid
root_squash:默认选项root用户建立的文件的属主和属组都变成nfsnobody,其余人server端是它本身,client端是nobody。
no_root_squash:root用户建立的文件属主和属组仍是root,其余人server端是它本身uid,client端是nobody。
all_squash:无论是root仍是其余普通用户建立的文件的属主和属组都是nfsnobody缓存
设置 NFS 要共享的目录,在命令行输入 vi /etc/exports
[root@client ~]# mkdir /nfs/ftp
mkdir: cannot create directory `/nfs/ftp': No such file or directory
[root@client ~]# mkdir /nfs/ftp -p
[root@client ~]# mount -t nfs -o rw 192.168.1.128:/var/ftp /nfs/ftpbash
需求1:共享本地/var/ftp目录给全部人,以读写方式共享 ```powershell server端: 1.[root@server ~]# mkdir /var/ftp -p [root@server ~]# ls /nfs -l total 4 drwxr-xr-x 2 root root 4096 Nov 28 03:28 ftp 2.vim /etc/exports /var/ftp *(rw,no_root_squash) 3.启动服务 service rpcbind restart service nfs start client测试: [root@client ~]# mkdir /nfs/ftp -p [root@client ~]# mount -t nfs -o rw 192.168.1.128:/var/ftp /nfs/ftp [root@client ~]# df -h ... 192.168.1.128:/var/ftp 18G 2.7G 14G 16% /nfs/ftp 说明挂载成功 测试写入: [root@client ftp]# touch file8 touch: cannot touch `file8': Permission denie //权限拒绝 缘由:server端的共享目录权限不够 解决: [root@server ~]# ll -d /var/ftp drwxr-xr-x 3 root root 4096 Nov 28 09:03 /var/ftp [root@server ~]# chmod o+w /var/ftp [root@server ~]# ll /var/ftp total 52 -rw-r--r-- 1 root root 0 Nov 24 13:11 file1 -rw-r--r-- 1 root root 0 Nov 24 13:11 file2 -rw-r--r-- 1 root root 0 Nov 24 13:11 file3 -rw-r--r-- 1 root root 0 Nov 24 13:11 file4 -rw-r--r-- 1 root root 0 Nov 24 13:11 file5 -rw-r--r-- 1 root root 0 Nov 28 08:55 file6 -rw-r--r-- 1 root root 0 Nov 28 09:00 file7 -rw-r--r-- 1 nfsnobody nfsnobody 0 Nov 28 09:17 file8 -rw------- 1 ftp ftp 45941 Nov 25 14:09 install.log drwxr-xr-x 2 root root 4096 Aug 4 2014 pub
思路: A主机上: 1.须要建立相应的用户user1~user3 eg:user1---> /user1(挂载点) B主机上: 搭建NFS服务,将/nfs/share共享出来 A主机上: 1.挂载B主机上的共享目录到指定挂载点上 测试验证: 在A主机进行 步骤: 环境: FTP-server:192.168.1.128 NFS-server:192.168.1.129 client:192.168.1.130 FTP-server上完成 1.建立用户而且制定用户的家目录 [root@ftp-server ~]# mkdir /rhome [root@ftp-server ~]# useradd -d /rhome/user01 -M user01 [root@ftp-server ~]# useradd -d /rhome/user02 -M user02 [root@ftp-server ~]# useradd -d /rhome/user03 -M user03 [root@ftp-server ~]# echo 123|passwd --stdin user01 Changing password for user user01. passwd: all authentication tokens updated successfully. [root@server ~]# echo 123|passwd --stdin user02 Changing password for user user02. passwd: all authentication tokens updated successfully. [root@server ~]# echo 123|passwd --stdin user03 Changing password for user user03. passwd: all authentication tokens updated successfully. NFS-server操做: [root@nfs-server ~]# mkdir /var/nfs-ftp [root@nfs-server ~]# vim /etc/exports /var/nfs-ftp 192.168.1.128(rw) [root@ftp-server ~]# mkdir /rhome/user0{1..3} [root@ftp-server ~]# mount.nfs 192.168.1.129:/var/nfs-ftp/user01 /rhome/user01 [root@ftp-server ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 2.7G 14G 16% / tmpfs 754M 76K 754M 1% /dev/shm /dev/sda1 283M 28M 240M 11% /boot /dev/sr0 4.4G 4.4G 0 100% /media/CentOS_6.6_Final 192.168.1.129:/var/nfs-ftp/user01 18G 3.5G 13G 22% /rhome/user01 [root@nfs-server nfs-ftp]# cd /var/nfs-ftp/user01 [root@nfs-server user01]# ll total 0 [root@nfs-server user01]# pwd /var/nfs-ftp/user01 [root@nfs-server user01]# echo hello world >>file1 [root@nfs-server user01]# ll total 4 -rw-r--r--. 1 root root 12 Nov 30 04:50 file1 client测试验证: [root@client ~]# ftp 192.168.1.128 Connected to 192.168.1.128 (192.168.1.128). 220 (vsFTPd 2.2.2) Name (192.168.1.128:root): user01 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> exit [root@client ~]# ftp 192.168.1.128 Connected to 192.168.1.128 (192.168.1.128). 220 (vsFTPd 2.2.2) Name (192.168.1.128:root): user01 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (192,168,1,128,248,38). 150 Here comes the directory listing. -rw-r--r-- 1 0 0 12 Nov 29 20:50 file1 226 Directory send OK. [root@nfs-server user01]# echo hello world >>file1 [root@nfs-server user01]# ll total 4 -rw-r--r--. 1 root root 12 Nov 30 04:50 file1 补充高级权限:o+t 粘滞位 通常做用在公共的目录上(777) 只能本身管理本身,在该目录下,只有root和文件的建立者能够删除,其余用户不能够删除不属于本身的文件 [root@nfs-server user01]# ll -d /var/nfs-ftp/user01 drwxr-xr-x. 2 root root 4096 Nov 30 04:50 /var/nfs-ftp/user01 [root@ftp-server ~]# su - user01 -bash-4.1$ pwd /rhome/user01 -bash-4.1$ touch file2 touch: cannot touch `file2': Permission denied -bash-4.1$ touch file2 说明: 正常状况下,user01用户只可以访问ftp服务器,可是不可以上传文件,缘由是nfs-server端的共享目录没有权限 解决:nfs-server [root@nfs-server user01]# chmod 1777 /var/nfs-ftp/ -R [root@nfs-server user01]# ll total 4 -rwxrwxrwt. 1 root root 12 Nov 30 04:50 file1 -rw-rw-r--. 1 503 503 0 Nov 30 04:56 file2 [root@client ~]# ftp 192.168.1.128 Connected to 192.168.1.128 (192.168.1.128). 220 (vsFTPd 2.2.2) Name (192.168.1.128:root): user01 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (192,168,1,128,97,129). 150 Here comes the directory listing. -rwxrwxrwt 1 0 0 12 Nov 29 20:50 file1 -rw-rw-r-- 1 99 99 0 Nov 29 20:56 file2 -rw-r--r-- 1 99 99 45941 Nov 29 20:58 install.log 226 Directory send OK. ftp> put install.log local: install.log remote: install.log No control connection for command: 成功 Passive mode refused. 方法2: FTP-Server:192.168.1.128 NFS-Server:192.168.1.129 Client:192.168.1.130 步骤: FTP-Server操做: 1.建立用户 useradd uu1 useradd uu2 NFS-Server操做: 1./data目录里给用户建立相应的目录 mkdir /data/uu1 mkdir /data/uu2 2.给共享目录设置相应的权限 chmod 1777 /var/nfs-ftp -R 3.发布共享目录 vim /etc/exports /var/nfs-ftp 192.168.1.129(rw) 4.重启nfs服务 service nfs restart FTP-Server端操做: uu1用户: mount.nfs 192.168.1.129:/var/nfs-ftp/uu1 /home/uu1
Nfs-server端:共享目录,而且建立一个首页文件 1.mkdir /share/web -p 2.echo "hello world!" >/share/web/index.html 3.vim /etc/exports(发布目录) /share/web 192.168.1.0/24(ro) 4.重启服务(nfs) service nfs start 或 exportfs -rv Web1服务器: 1.安装httpd软件 2.挂载nfs-server端的共享目录到/var/www/html 3.启动服务 [root@server ~]# mkdir /share/web -p [root@server ~]# echo "hello world" >/share/web/index.html [root@server ~]#ls /var/www/html/ index.html [root@server web]# service httpd start Starting httpd: httpd: apr_sockaddr_info_get() failed for server httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ] Web2服务器 1.安装httpd软件 2.挂载nfs-server端的共享目录到/var/www/html
Samba服务的主要进程服务器
NetBIOS是Network Basic Input/Output System的简称,通常指用于局域网通讯的一套API
[root@samba-server ~]# rpm -aq|grep ^samba samba-3.6.23-12.el6.x86_64 samba-winbind-3.6.23-12.el6.x86_64 samba-winbind-clients-3.6.23-12.el6.x86_64 samba4-libs-4.0.0-64.el6.rc4.x86_64 samba-client-3.6.23-12.el6.x86_64 samba-common-3.6.23-12.el6.x86_64 //启动服务: [root@samba-server ~]# service smb restart Shutting down SMB services: [ OK ] Starting SMB services: [ OK ] [root@samba-server ~]# service nmb restart Shutting down NMB services: [ OK ] Starting NMB services: [ OK ] [root@client ~]# smbclient -L //192.168.1.128 Enter root's password: Anonymous login successful Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-12.el6] Sharename Type Comment --------- ---- ------- IPC$ IPC IPC Service (Samba Server Version 3.6.23-12.el6) HP_Color_LaserJet_Pro_M252_PCL_6:4 Printer HP Color LaserJet Pro M252 PCL 6 Adobe_PDF:7 Printer Adobe PDF 172.16.134.200\HP_LaserJet_MFP_M725_PCL_6_(Copy_2):8 Printer \\172.16.134.200\HP LaserJet MFP M725 PCL 6 (Copy 2) GoldGrid_Virtual_Printer:3 Printer GoldGrid Virtual Printer Fax:1 Printer Fax _OneNote_16:2 Printer OneNote 16 Anonymous login successful Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-12.el6] Server Comment --------- ------- SAMBA-SERVER Samba Server Version 3.6.23-12.el6 Workgroup Master --------- ------- MYGROUP SAMBA-SERVER WORKGROUP IKQFZFGBIVWYJ76
配置文件:
[root@samba-server ~]# ls /etc/samba/smb.conf /etc/samba/smb.conf [global] //全局选项 workgroup = MYGROUP //定义samba服务器所在的工做组 server string = Samba Server Version %v //smb服务的描述 log file = /var/log/samba/log.%m //日志文件 max log size = 50 //日志的最大大小KB security = user //认证模式:share匿名|user用户密码|server外部服务器用户密码 passdb backend = tdbsam //密码格式 load printers = yes //加载打印机 cups options = raw //打印机选项 [homes] //局部选项(共享名称) comment = Home Directories //描述 browseable = no //隐藏共享名称 writable = yes //可读可写 [printers] //共享名称 comment = All Printers //描述 path = /var/spool/samba //本地的共享目录 browseable = no //隐藏 guest ok = no //public = no 须要帐户和密码访问 writable = no //read only = yes 不可写 printable = yes //
客户端工具如何使用:
//查看samba服务器的共享名 [root@client ~]# smbclient -L //192.168.1.128 Enter root's password: //匿名用户查看 Anonymous login successful //将zhangsan本地用户加入到smb数据库中: [root@samba-server ~]# smbpasswd -a zhangsan New SMB password: Retype new SMB password: Added user zhangsan. [root@samba-server ~]# pdbedit -L zhangsan:508: [root@Server2 ~]# smbclient //192.168.1.128/zhangsan -U zhangsan //指定用户名访问samba服务 Enter zhangsan's password: Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-12.el6] smb: \> ls 需求:让匿名用户访问/samba/share共享资源,本地用户不能访问 [anon_share] path=/samba/share public = yes writable = yes [root@Server2 ~]# smbclient //192.168.1.128/anon_share (共享标签名称) //匿名用户能够访问 Enter root's password: Anonymous login successful Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-12.el6] smb: \> ls [root@Server2 ~]# smbclient //192.168.1.128/anon_share -U zhangsan Enter zhangsan's password: Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-12.el6] smb: \> ls 经过挂载的方式访问: [root@Server2 ~]# mount.cifs -o user=zhangsan,pass=123 //192.168.1.128/anon_share /u01 总结: 1.samba服务默认是基于用户名和密码认证的服务 2.samba服务的用户必须是samba服务器上存在的用户,密码必须是samba数据库里的密码 3.对于发布的共享资源,默认状况下本地用户是能够访问的,匿名用户是否访问看是否打开public=yes
访问控制:
```powershell~~~
控制读写权限:
writable = yes/no
readonly = yes/no
若是资源可写,但只容许某些用户可写,其它都是只读
write list = admin,root,@staff(用户组)
read list = mary,@students
控制访问对象
valid users = tom mary
invalid users = tom
注意:以上两个选项只能存在其中一个
网络访问控制:hosts deny = 192.168.0. 拒绝某个网段host allow = 192.168.0.254 容许某个IPhosts deny = all 拒绝全部hosts allow = 192.168.0. EXCEPT 192.168.0.254 容许某个网段,但拒绝某单个IP