实战NFS服务搭建与配置
nfs服務(wù)應(yīng)用:
存儲靜態(tài)文件如:圖片(頭像logo),視頻,附件等。
1. 查看所有機器是否安裝了 rpcbind?nfs-utils
[root@nfs-server ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6_9.x86_64
如果沒有安裝則安裝:
yum install nfs-utils rpcbind -y
2.服務(wù)端:
[root@nfs-server ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@nfs-server ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@nfs-server ~]# /etc/init.d/rpcbind status
rpcbind (pid 46014) is running...
#查看端口和服務(wù)驗證rpcbind是否啟動
[root@nfs-server ~]# lsof -i :111
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 46014 rpc 6u IPv4 43942 0t0 UDP *:sunrpc
rpcbind 46014 rpc 8u IPv4 43944 0t0 TCP *:sunrpc (LISTEN)
rpcbind 46014 rpc 9u IPv6 43945 0t0 UDP *:sunrpc
rpcbind 46014 rpc 11u IPv6 43947 0t0 TCP *:sunrpc (LISTEN)
[root@nfs-server ~]# netstat -lntup|grep rpcbind
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 46014/rpcbind
tcp 0 0 :::111 :::* LISTEN 46014/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 46014/rpcbind
udp 0 0 0.0.0.0:821 0.0.0.0:* 46014/rpcbind
udp 0 0 :::111 :::* 46014/rpcbind
udp 0 0 :::821 :::* 46014/rpcbind
[root@nfs-server ~]# ps -ef|grep rpcbind
rpc 46014 1 0 13:50 ? 00:00:00 rpcbind
root 46031 1341 0 13:53 pts/0 00:00:00 grep rpcbind
如果rpc 服務(wù)是停止的則提示:
[root@nfs-server ~]# rpcinfo -p localhost
rpcinfo: can't contact portmapper: RPC: Remote system error - Connection refused
此時使用下面命令開啟:
[root@nfs-server ~]#/etc/init.d/rpcbind start
3. 啟動NFS 服務(wù)
[root@nfs-server ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@nfs-server ~]# 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 16420 mountd
100005 1 tcp 29507 mountd
100005 2 udp 45473 mountd
100005 2 tcp 12943 mountd
100005 3 udp 29388 mountd
100005 3 tcp 22133 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 21445 nlockmgr
100021 3 udp 21445 nlockmgr
100021 4 udp 21445 nlockmgr
100021 1 tcp 27929 nlockmgr
100021 3 tcp 27929 nlockmgr
100021 4 tcp 27929 nlockmgr
4.加人開機自啟動
[root@nfs-server ~]# chkconfig nfs on
[root@lnmp ~]# chkconfig rpcbind on
#檢查開機自啟動加入是否成功
[root@nfs-server ~]# chkconfig --list nfs
nfs 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
[root@nfs-server ~]# chkconfig --list rpcbind
rpcbind 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
#寫入開機啟動文件/etc/rc.local?中
[root@nfs-server ~]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
>/etc/udev/rules.d/70-persistent-net.rules
/etc/init.d/rpcbind start
/etc/init.d/nfs start
?
***實戰(zhàn)配置服務(wù)端 (將data 目錄共享給192.168.0.0/24網(wǎng)段的主機,可讀寫)***
5. 服務(wù)器端配置
5.1 服務(wù)器端創(chuàng)建共享目錄
[root@nfs-server ~]# mkdir /data
5.2 服務(wù)器端編輯nfs配置文件
vi /etc/exports
####################################
#share data by alvin at 2018-09-22
/data 192.168.0.0/24(rw,sync,all_squash)
####################################
服務(wù)器端檢查配置
[root@nfs-server ~]# cat /etc/exports
#share data by alvin at 2018-09-22
/data 192.168.0.0/24(rw,sync,all_squash)
共享的目錄名稱 共享的網(wǎng)段 權(quán)限,同步
5.3 服務(wù)器端重啟服務(wù)
[root@nfs-server ~]# /etc/init.d/nfs reload? ? ?#?此處是查看 nfs 中reload 命令情況 reload 相當(dāng)于 exportfs -r
5.4 服務(wù)器端本機自身檢查一下共享的情況
[root@nfs-server ~]# showmount -e localhost
Export list for localhost:
/data 192.168.0.0/24
#查看一下,/data目錄的權(quán)限:
[root@nfs-server ~]# ll -ld /data
drwxr-xr-x 2 root root 4096 Sep 22 15:36 /data
[root@nfs-server ~]# cat /var/lib/nfs/etab? ??#因為默認的讀寫權(quán)限給的是:anonuid=65534
/data 192.168.0.0/24(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@nfs-server ~]#
#如果不修改,客戶端創(chuàng)建文件提示沒有權(quán)限:
[root@lnmp02 mnt]# touch aaboy.log
touch: cannot touch aaboy.log: Permission denied
修改/data權(quán)限
[root@nfs-server ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[root@nfs-server ~]# chown -R nfsnobody.nfsnobody /data
[root@nfs-server ~]# ll -ld /data
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Sep 22 15:36 /data
客戶端
檢查是否安裝了rpcbind
[root@Client-3 ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-11.el6.i686
nfs-utils-1.2.3-39.el6.i686
#啟動rpc服務(wù)并加入開機自啟動就可以了
/etc/init.d/rpcbind start
/etc/init.d/rpcbind status
chkconfig rpcbind on
chkconfig --list rpcbind
客戶端檢查一下共享
[root@lamp01 ~]# showmount -e 192.168.0.15
Export list for 192.168.0.15:
/data 192.168.0.0/24
6.客戶端檢查并掛載/mnt
[root@lamp01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 25G 2.4G 21G 11% /
tmpfs 490M 0 490M 0% /dev/shm
/dev/sda1 969M 70M 849M 8% /boot
[root@lamp01 ~]# mount -t nfs 192.168.0.15:/data /mnt? ? ? ? ? ? ? ? ? ? #192.168.0.15 是服務(wù)器端的IP地址
[root@lamp01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 25G 2.4G 21G 11% /
tmpfs 490M 0 490M 0% /dev/shm
/dev/sda1 969M 70M 849M 8% /boot
192.168.0.15:/data 25G 2.4G 21G 11% /mnt
為了防止客戶端重啟后不再掛載,需要添加開機自動掛載
echo "/etc/init.d/rpcbind start" >>/etc/rc.local
echo "/bin/mount -t nfs 192.168.0.15:/data /mnt" >>/etc/rc.local
[root@lamp01 ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
> /etc/udev/rules.d/70-persistent-net.rules
/etc/init.d/rpcbind start
/bin/mount -t nfs 192.168.0.15:/data /mnt
測試驗證:
服務(wù)器端創(chuàng)建文件
[root@nfs-server ~]# cd /data
[root@nfs-server data]# ll
total 0
[root@nfs-server data]# touch a.txt
[root@nfs-server data]# ll
total 0
-rw-r--r-- 1 root root 0 Sep 22 16:09 a.txt? ? ? ? ? #服務(wù)器端創(chuàng)建的文件,用戶和屬組是root
客戶端刪除文件
[root@lnmp02 ~]# ll /mnt
total 0
-rw-r--r-- 1 root root 0 Sep 22 16:09 a.txt
[root@lnmp02 ~]# rm -f /mnt/a.txt
[root@lnmp02 ~]# ll /mnt
total 0
[root@lnmp02 ~]#
服務(wù)器端再次查看,發(fā)現(xiàn)消失.............
[root@nfs-server data]# ll
total 0
[root@nfs-server data]#
#服務(wù)器端創(chuàng)建文件,演示同上省略
[root@lnmp02 ~]# cd /mnt
[root@lnmp02 mnt]# touch b.txt
[root@lnmp02 mnt]# ll
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Sep 22 16:17 b.txt? ? ? ? ?# 客戶端創(chuàng)建的文件,用戶和屬組是nfsnobody
轉(zhuǎn)載于:https://www.cnblogs.com/ahtornado/p/9690494.html
總結(jié)
以上是生活随笔為你收集整理的实战NFS服务搭建与配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 福田汽车空调继电器在哪里啊福田欧航货车空
- 下一篇: 变速箱维修费用明细?