14.2 NFS服務端安裝配置

NFS服務端安裝配置目錄概要

  • yum install -y nfs-utils rpcbind
  • vim /etc/exports //加入以下內容
/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
  • 保存配置文件後,執行以下準備操做
  • mkdir /home/nfstestdir
  • chmod 777 /home/nfstestdir
  • systemctl start rpcbind
  • systemctl start nfs
  • systemctl enable rpcbind
  • systemctl enable nfs

NFS服務端安裝配置

  1. 首先準備兩臺機器,我這裏準備兩臺虛擬機,A機器IP分別爲192.168.202.130,B機器IP爲192.168.202.131
  • A機器,查看IP
[root@hanfeng ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.202.130  netmask 255.255.255.0  broadcast 192.168.202.255
        inet6 fe80::20c:29ff:feff:458f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ff:45:8f  txqueuelen 1000  (Ethernet)
        RX packets 684  bytes 68341 (66.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 226  bytes 26200 (25.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno16777736:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.202.150  netmask 255.255.255.0  broadcast 192.168.202.255
        ether 00:0c:29:ff:45:8f  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 8  bytes 536 (536.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 536 (536.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@hanfeng ~]#
  • B機器,查看IP
[root@hf-01 ~]# ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.202.131  netmask 255.255.255.0  broadcast 192.168.202.255
        inet6 fe80::baa:c015:db72:1d5c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b6:4d:41  txqueuelen 1000  (Ethernet)
        RX packets 63  bytes 7905 (7.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 79  bytes 11615 (11.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 68  bytes 5524 (5.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 68  bytes 5524 (5.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@hf-01 ~]#
  1. 將A機器做爲服務端,並安裝兩個包,分別爲 nfs-utils 和 rpcbind
  • yum install -y nfs-utils rpcbind
[root@hanfeng ~]# yum install -y nfs-utils rpcbind
  1. 將B機器做爲客戶端,安裝 nfs-utils 包
  • 每次剛開機運行yum的時候都會很慢,由於須要從新生成一個緩存文件
  • 有時yum安裝的時候很慢,咱們能夠先禁掉,進入到/etc/yum.repos.d/目錄下,將目錄下的epel.repo文件改個名字,從新安裝便可
  • yum install -y nfs-utils
[root@hf-01 ~]# yum install -y nfs-utils
  1. 在安裝完成後,須要去A機器中 /etc/exports 編輯配置文件
  • vim /etc/exports //加入以下內容
[root@hanfeng ~]# vim /etc/exports

/home/nfstestdir     
要分享出去的目錄是哪個目錄,這個目錄是不存在的,後期還須要建立的
192.168.202.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
指定你要給哪一個機器去分享這個目錄,首先定義IP或IP段

保存退出
  1. 下面就能夠啓動服務了,啓動服務前須要先建立目錄,並設置權限
  2. 在A機器上建立分享的目錄
[root@hanfeng ~]# mkdir /home/nfstestdir
[root@hanfeng ~]#
  1. 並設置成777的權限,這裏設置777權限是爲了方便接下里的實驗
[root@hanfeng ~]# chmod 777 /home/nfstestdir
[root@hanfeng ~]#
  1. 啓動 rpcbind ,再啓動前查看A機器上監聽的端口,就會看到啓動了1/systemd,這是centos7系統的一個特性——>111端口是rpcbind服務監聽的
  • 用ps能夠查看服務已經啓動,由於有這個服務,因此監聽了111端口
[root@hanfeng ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2172/master         
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1115/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2172/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2264/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      1115/sshd           
[root@hanfeng ~]# ps aux |grep rpc
rpc       2393  0.0  0.1  64964  1044 ?        Ss   15:40   0:00 /sbin/rpcbind -w
root      2537  0.0  0.0 112680   972 pts/0    R+   16:17   0:00 grep --color=auto rpc
  1. 再到B機器上查看下端口,會看到也啓動了rpcbind
[root@hf-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      2393/rpcbind        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1334/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2146/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2029/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      2393/rpcbind        
tcp6       0      0 :::22                   :::*                    LISTEN      1334/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2146/master         
[root@hf-01 ~]# ps aux |grep rpc
root     16644  0.0  0.0 112656   992 pts/2    R+   04:46   0:00 grep --color=auto rpc
[root@hf-01 ~]#
  1. 在A機器啓動了rpcbind,下面就能夠啓動nfs服務,在使用ps查看
  • systemctl start rpcbind
[root@hanfeng ~]# systemctl start nfs 
[root@hanfeng ~]# ps aux |grep nfs
root      4560  0.0  0.0      0     0 ?        S<   04:52   0:00 [nfsd4]
root      4561  0.0  0.0      0     0 ?        S<   04:52   0:00 [nfsd4_callbacks]
root      4565  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4566  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4567  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4568  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4569  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4570  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4571  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4572  0.0  0.0      0     0 ?        S    04:52   0:00 [nfsd]
root      4576  0.0  0.0 112676   984 pts/0    R+   04:52   0:00 grep --color=auto nfs
[root@hanfeng ~]#
  1. 同時也能夠在A機器上ps aux |grep rpc查詢,在啓動nfs服務的時候,它會自動幫你啓動rpc相關的一些服務
[root@hanfeng ~]# ps aux |grep rpc
rpc       2957  0.0  0.1  64908  1416 ?        Ss   03:05   0:00 /sbin/rpcbind -w
rpcuser   4530  0.0  0.1  42380  1744 ?        Ss   04:52   0:00 /usr/sbin/rpc.statd
root      4531  0.0  0.0      0     0 ?        S<   04:52   0:00 [rpciod]
root      4539  0.0  0.0  19324   652 ?        Ss   04:52   0:00 /usr/sbin/rpc.idmapd
root      4550  0.0  0.0  42556   948 ?        Ss   04:52   0:00 /usr/sbin/rpc.mountd
root      4602  0.0  0.0 112676   984 pts/0    R+   05:00   0:00 grep --color=auto rpc
[root@hanfeng ~]#
  1. 而在客戶端B機器上是沒有的這些服務的
[root@hf-01 ~]# ps aux |grep rpc
root     16644  0.0  0.0 112656   992 pts/2    R+   04:46   0:00 grep --color=auto rpc
[root@hf-01 ~]#
  1. 若是想讓nfs開機啓動,還須要執行systemctl enable nfs 命令,在服務端A機器上調用
  • systemctl enable nfs 開機啓動nfs
  • systemctl disable nfs 關閉開機啓動
[root@hanfeng ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@hanfeng ~]#
相關文章
相關標籤/搜索