1. 程式人生 > >簡單安裝NFS服務端和客戶端

簡單安裝NFS服務端和客戶端

工具 dbo load rpcbind hat uname 1.3 starting nfs

[root@nfs01 ~]# cat /etc/redhat-release =》查看操作系統
CentOS release 6.9 (Final)
[root@nfs01 ~]# uname -r =》查看操作系統內核
2.6.32-696.el6.x86_64
[root@nfs01 ~]# uname -m =》查看操作系統位數
x86_64

準備2臺虛擬機,2臺都安裝nfs-utils rpcbind工具。
nfs01為服務器端,web01為客戶端
nfs01IP地址:172.16.1.31 web01IP地址為:172.16.1.8

1、安裝nfs-utils rpcbind
‘yum install nfs-utils rpcbind -y #安裝nfs-utils rpcbind

rpm -aq nfs-utils rpcbind #查看nfs-utils和rpcbind是否安裝好
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6_9.x86_64

安裝完畢註意在nfs01服務端啟動順序 先啟動rpcbind,在啟動nfs-utils要不然容易報錯。

2、啟動rpcbind
/etc/init.d/rpcbind start #啟動rpcbind
[root@nfs01 ~]# netstat -lntup |grep rpc #查看rpc端口是否開啟成功,prc端口是111
tcp 0 0 0.0.0.0:111 0.0.0.0: LISTEN 38496/rpcbind

tcp 0 0 :::111 ::: LISTEN 38496/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0: 38496/rpcbind
udp 0 0 0.0.0.0:935 0.0.0.0:
38496/rpcbind
udp 0 0 :::111 ::: 38496/rpcbind
udp 0 0 :::935 :::
38496/rpcbind

[root@nfs01 ~]# rpcinfo -p localhost #查看有沒有資源
program vers proto port service
100000 4 tcp 111 portmapper =》111是主端口
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

3、nfs01服務端啟動nfs
[root@nfs01 ~]# /etc/init.d/nfs start #啟動nfs服務
[root@nfs01 ~]# rpcinfo -p localhost #再次查看會多出很多資源

4、設置nfs服務和rpc服務開機啟動
[root@nfs01 ~]# chkconfig nfs on
[root@nfs01 ~]# chkconfig rpcbind on

5、nfs01服務端創建data目錄和授權
[root@nfs01 ~]# mkdir /data
[root@nfs01 ~]# id nfsnobody
uid=65534(nfsnobody) gid=65534(nfsnobody) 組=65534(nfsnobody)
[root@nfs01 ~]# chown -R nfsnobody.nfsnobody /data
[root@nfs01 ~]# ls -ld /data/
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 1月 4 23:55 /data/

6、nfs01服務端創建exports(服務器共享路徑和權限)
[root@nfs01 ~]# vi /etc/exports
#shara /data by oldboy for bingbing at 20180104
/data 172.16.1.0/24(rw,sync)
#/data目錄 172.16.1.0/24允許訪問的IP段 (rw,sync) rw可以讀和寫,sync=直接寫到磁盤上 async=大並發的時候使用(異步寫入)
[root@nfs01 ~]# cat /etc/exports #查看是否配置成功
#shara /data by oldboy for bingbing at 20180104
/data 172.16.1.0/24(rw,sync)

7、重啟服務
[root@nfs01 ~]# /etc/init.d/nfs reload =》配置文件配置完了需要重啟服務

[root@nfs01 ~]# showmount -e 172.16.1.31 #重啟服務之後自我檢查看看是否成功
Export list for 172.16.1.31:
/data 172.16.1.0/24 #出現這個表示成功的服務端就配置好了

8、web01客戶端啟動rpc服務
[root@web01 /]# /etc/init.d/rpcbind start =》啟動服務
Starting rpcbind: [ OK ]
[root@web01 /]# /etc/init.d/rpcbind status =》檢查服務
rpcbind (pid 13542) is running..

9、客戶端開啟開機自啟動
[root@web01 /]# chkconfig rpcbind on
[root@web01 /]# chkconfig --list |grep "rpcbind" =》查看啟動狀態
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:of

10、客戶端檢查是否可以掛載
[root@web01 /]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24 =》表示成功的
[root@web01 /]# mount -t nfs 172.16.1.31:/data /mnt =》開始掛載
#-t是類型 nfs類型 nfs服務器IP地址 nfs服務器端的/data目錄 掛載到 客戶端的/mnt目錄下

[root@web01 /]# df -h #查看掛載
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.9G 6.5G 23% /
tmpfs 364M 0 364M 0% /dev/shm
/dev/sda1 190M 66M 115M 37% /boot
172.16.1.31:/data 8.8G 1.8G 6.6G 21% /mnt #=》成功的

11、放到開機自啟動配置文件中
[root@web01 ~]# echo "mount -t nfs 172.16.1.31:/data /mnt">>/etc/rc.local
[root@web01 ~]# tail -1 /etc/rc.local # =》檢查
mount -t nfs 172.16.1.31:/data /mnt

簡單安裝NFS服務端和客戶端