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