1. 程式人生 > >菜鳥學習---NFS共享文件服器務搭建

菜鳥學習---NFS共享文件服器務搭建

linux nfs rpcbind

一、搭建環境

服務端:Linux nfsser 2.6.32-431.el6.x86_64 IP:10.10.10.11

客戶端:Linux nfsclient 2.6.32-431.el6.x86_64 IP:10.10.10.12

二、服務端和客戶端安裝nfs-utils rpcbind

1、對服務端配置

檢查系統是否安裝rpcbind和nfs-utils

[root@nfsser ~]# rpm -qa |grep rpcbind
[root@nfsser ~]# rpm -qa |grep nfs-utils

通過yum進行安裝

[root@nfsser ~]# yum install -y rpcbind nfs-utils portmap
Loaded plugins: fastestmirror, security
base                                                                                                    | 3.7 kB     00:00     
base/primary_db                                                                                         | 4.7 MB     00:03     
extras                                                                                                  | 3.4 kB     00:00     
extras/primary_db                                                                                       |  29 kB     00:00     
updates                                                                                                 | 3.4 kB     00:00     
中間省略。。。。。。
Dependency Updated:
  keyutils-libs.x86_64 0:1.4-5.el6                                                                                             
Complete!

查看安裝結果:

[root@nfsser ~]# rpm -qa nfs-utils portmap rpcbind
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6.x86_64

2、對服務端進行配置

[root@nfsclient ~]# /etc/init.d/rpcbind start         #啟動rpcbind服務
Starting rpcbind:                                          [  OK  ]
[root@nfsclient ~]# ps -ef |grep rpcbind               #查看rpcbind服務進程
rpc       26947      1  0 21:34 ?        00:00:00 rpcbind
root      26951   1500  0 21:35 pts/0    00:00:00 grep rpcbind
[root@nfsclient ~]# /etc/init.d/rpcbind status     #查看服務運行狀態
rpcbind (pid  26947) is running...   
[root@nfsclient ~]# rpcinfo -p localhost          
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
#如查rpcbind服務停止後,查看rpcbind本地對應端口
[root@nfsclient ~]# /etc/init.d/rpcbind stop         #停止rpcbind服務
Stopping rpcbind:                                     [  OK  ]
[root@nfsclient ~]# rpcinfo -p localhost           
rpcinfo: can‘t contact portmapper: RPC: Remote system error - Connection refused 
#報錯原因是因為rpcbind服務未啟動
[root@nfsclient ~]# /etc/init.d/rpcbind reload  #平滑加載nfs服務           
Stopping rpcbind:                                      [FAILED]
Starting rpcbind:                                      [  OK  ]
:通過reload啟動rpcbind服務(通過reload啟動服務,類似於你在5點銀行下班的時候你已經在銀行大
廳,不會影響你辦理業務,但5點的時候外面的人在進來是進不來的)
[root@nfsser ~]# /etc/init.d/nfs start          #啟動nfs服務
Starting NFS services:                                   [  OK  ]
Starting NFS quotas:                                    [  OK  ]
Starting NFS mountd:                                    [  OK  ]
Starting NFS daemon:                                    [  OK  ]
Starting RPC idmapd:                                    [  OK  ]
[root@nfsser ~]# rpcinfo -p localhost
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100011    1   udp    875  rquotad
    100011    2   udp    875  rquotad
    100011    1   tcp    875  rquotad
    100011    2   tcp    875  rquotad
    100005    1   udp  50275  mountd
    100005    1   tcp  46245  mountd
    100005    2   udp  45499  mountd
    100005    2   tcp  51182  mountd
    100005    3   udp  36337  mountd
    100005    3   tcp  52782  mountd
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049  nfs_acl
    100227    3   tcp   2049  nfs_acl
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100021    1   udp  52478  nlockmgr
    100021    3   udp  52478  nlockmgr
    100021    4   udp  52478  nlockmgr
    100021    1   tcp  41895  nlockmgr
    100021    3   tcp  41895  nlockmgr
    100021    4   tcp  41895  nlockmgr
[root@nfsser ~]# chkconfig rpcbind on   #加入開自啟
[root@nfsser ~]# chkconfig  nfs on         
[root@nfsser ~]# chkconfig --list rpcbind    #檢查是否加入開機自啟
rpcbind        0:off1:off2:on3:on4:on5:on6:off    
[root@nfsser ~]# chkconfig --list nfs
nfs            0:off1:off2:on3:on4:on5:on6:off

2、對客戶端配置(服務端只用開啟rpcbind服務即可)

[root@nfsser ~]# yum install -y rpcbind nfs-utils portmap
Loaded plugins: fastestmirror, security
base                                                                                                    | 3.7 kB     00:00     
base/primary_db                                                                                         | 4.7 MB     00:03     
extras                                                                                                  | 3.4 kB     00:00     
extras/primary_db                                                                                       |  29 kB     00:00     
updates                                                                                                 | 3.4 kB     00:00     
中間省略。。。。。。
Dependency Updated:
  keyutils-libs.x86_64 0:1.4-5.el6                                                                                             
Complete!

查看安裝結果:

[root@nfsser ~]# rpm -qa nfs-utils portmap rpcbind
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6.x86_64
[root@nfsclient ~]# /etc/init.d/rpcbind start     #啟動rpcbind服務
Starting rpcbind:                                          [  OK  ]
[root@nfsclient ~]# chkconfig rpcbind on    #加入開機自啟
[root@nfsclient ~]# chkconfig --list rpcbind    #檢查是否添加開機自啟
rpcbind        0:off1:off2:on3:on4:on5:on6:off
[root@nfsclient ~]# /etc/init.d/rpcbind status
rpcbind (pid  27102) is running...
[root@nfsclient ~]#

二、對共享文件配置

1、配置服務器端文件

[root@nfsser ~]# mkdir /sharedata   #建立共享sharedata
[root@nfsser ~]# vi /etc/exports     #編輯nfs配置文件
[root@nfsser ~]# cat /etc/exports   #查看nfs配置文件結果
##share data at 20171018
/sharedata 10.10.10.0/24(rw,sync)
註:
[root@nfsser ~]# cat /var/lib/nfs/etab    #查看nfs默認配置
/sharedata10.10.10.0/24(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,ro,root_squash,no_all_squash)
/sharedata*(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
[root@nfsser ~]# showmount -e localhost   #查看本機共享是否成功
Export list for localhost:
/sharedata (everyone)

2、配置客戶端文件

[root@nfsclient ~]# showmount -e 10.10.10.11   #成功檢沒到共享 
Export list for 10.10.10.11:
/sharedata (everyone)
[root@nfsclient ~]# mount -t nfs 10.10.10.11:/sharedata /mnt   #掛載到/mnt下
[root@nfsclient ~]# df -h
Filesystem              Size  Used Avail Use% Mounted on
/dev/sda3                59G  1.6G   55G   3% /
tmpfs                   931M     0  931M   0% /dev/shm
/dev/sda1               194M   34M  151M  19% /boot
10.10.10.11:/sharedata   59G  1.6G   55G   3% /alidata
[root@nfsclient mnt]# ll    #查文件sharedata文件裏的內容
total 72
-rw-r--r--. 1 root root 46850 Mar 23  2016 log.txt
-rw-r--r--. 1 root root 14476 Mar 23  2016 mytlv-20160119.log
-rw-r--r--. 1 root root  4537 Sep  5 22:12 qzj.txt
[root@nfsclient mnt]# touch 123  #測試能否有寫入權限
touch: cannot touch `123‘: Permission denied   拒絕訪問

在nfsser端檢查

[root@nfsser /]# ll -ld /sharedata/
drwxr-xr-x. 2 root root 4096 Oct 18 22:51 /sharedata/

[root@nfsser sharedata]# cat /var/lib/nfs/etab 
/sharedata10.10.10.0/24(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,ro,root_squash,no_all_squash)
/sharedata*(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
[root@nfsser sharedata]# grep 65534 /etc/passwd  #根據ID查找用戶
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[root@nfsser sharedata]# chown -R nfsnobody.nfsnobody /sharedata/  #給sharedata賦予權限
[root@nfsser /]# ll -ld /sharedata/
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Oct 18 22:51 /sharedata/
[root@nfsclient alidata]# touch asd   # 測試創建asd文件 
[root@nfsclient alidata]# ll 
total 72
-rw-r--r--. 1 root      root          0 Oct 18 23:53 ad   
-rw-r--r--. 1 nfsnobody nfsnobody     0 Oct 19 00:11 asd  創建成功
-rw-r--r--. 1 nfsnobody nfsnobody 46850 Mar 23  2016 log.txt
-rw-r--r--. 1 nfsnobody nfsnobody 14476 Mar 23  2016 mytlv-20160119.log
-rw-r--r--. 1 nfsnobody nfsnobody  4537 Sep  5 22:12 qzj.txt

客戶端在重啟後,掛載的alidata會丟失,需要加載到開機自啟。

echo "mount -t nfs 10.10.10.11:/sharedata /alidata" >>/etc/rc.local


本文出自 “菜鳥八哥” 博客,請務必保留此出處http://cainiaibage.blog.51cto.com/5307589/1974118

菜鳥學習---NFS共享文件服器務搭建