NFS服務基本配置

一安裝啓動:linux

先檢查有沒有安裝過NFS服務的包:rpm -aq nfs-utils rpcbind服務器

沒有的話就進行安裝:yum install nfs-utils rpcbind -y網絡

而後進入NFS的配置文件裏寫入須要共享的文件及其權限和共享客戶端的範圍:app

[root@NFS-SERVER ~]# cat /etc/exportsasync

/data/r_shared 192.168.20.0/24(ro,sync)tcp

/data/w_shared 192.168.20.0/24(rw,sync)ide

而後先啓動rpcbind,再啓動nfs要先啓動rpcbind服務再啓動nfs服務不然倒過來的話會致使nfsbind學習不到nfs的共享。學習

/etc/init.d/rpcbind start測試

/etc/init.d/nfs startui

也能夠把這兩條命令加入/etc/rc.local開機啓動時自啓動

[root@NFS-SERVER ~]# 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

/etc/init.d/nfs start

chkconfig啓動rpcbindnfs

chkconfig rpcbind on

chkconfig nfs on

chkconfig --list rpcbindnfs查看有沒有啓動

問題?要求rpcbind服務要先啓動於nfs服務,如今兩個都啓動要怎麼解決rpcbind先啓動?

wKiom1gRvBqidrQYAABRo6AY-Nk134.jpg-wh_50

wKiom1gRvBqiMWbbAAA03BlQSaY608.jpg-wh_50

rpcbind的啓動號比nfs小,因此兩個一塊兒打開的時候rpcbind天然會比nfs先啓動

查看rpc裏面有沒有東西用:rpcinfo -p localhost

裏面就是存放nfs給的東西

[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

    100005    1   udp  50653  mountd

    100005    1   tcp  55661  mountd

    100005    2   udp  35917  mountd

    100005    2   tcp  39194  mountd

    100005    3   udp  49181  mountd

    100005    3   tcp  47489  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  40329  nlockmgr

    100021    3   udp  40329  nlockmgr

    100021    4   udp  40329  nlockmgr

    100021    1   tcp  45731  nlockmgr

    100021    3   tcp  45731  nlockmgr

    100021    4   tcp  45731  nlockmgr

    100024    1   udp  35464  status

    100024    1   tcp  55621  status

2、配置

1、配置文件定義

NFS的配置文件爲 /etc/exports,內容格式以下:

<共享目錄> 客戶端1(選項) [客戶端2(選項) ...]

 共享目錄:NFS共享給客戶機的目錄。

 客戶端:網絡中能夠訪問此目錄的主機。多個客戶端以空格分隔。

 選項:設置目錄的訪問權限、用戶映射等,多個選項以逗號分隔。

例如:

/data/r_shared 192.168.20.0/24(rw,insecure,sync,all_squash,anonuid= 65534,anongid=65534)

2、客戶端的指定方式

指定ip地址的主機:192.168.02.100

指定子網中的全部主機:192.168.20.0/24 192.168.20.0/255.255.255.0

指定域名的主機:nfs.test.com

指定域中的全部主機:*.test.com

全部主機:*

 

3、選項說明

ro:共享目錄只讀;

rw:共享目錄可讀可寫;

all_squash:全部訪問用戶都映射爲匿名用戶或用戶組;

no_all_squash(默認):訪問用戶先與本機用戶匹配,匹配失敗後再映射爲匿名用戶或用戶組;

root_squash(默認):未來訪的root用戶映射爲匿名用戶或用戶組;

no_root_squash:來訪的root用戶保持root賬號權限;

anonuid=<UID>:指定匿名訪問用戶的本地用戶UID,默認爲nfsnobody65534);

anongid=<GID>:指定匿名訪問用戶的本地用戶組GID,默認爲nfsnobody65534);

secure(默認):限制客戶端只能從小於1024tcp/ip端口鏈接服務器;

insecure:容許客戶端從大於1024tcp/ip端口鏈接服務器;

sync:將數據同步寫入內存緩衝區與磁盤中,效率低,但能夠保證數據的一致性;

async:將數據先保存在內存緩衝區中,必要時才寫入磁盤;

wdelay(默認):檢查是否有相關的寫操做,若是有則將這些寫操做一塊兒執行,這樣能夠提升效率;

no_wdelay:如有寫操做則當即執行,應與sync配合使用;

subtree_check(默認) :若輸出目錄是一個子目錄,則nfs服務器將檢查其父目錄的權限;

no_subtree_check :即便輸出目錄是一個子目錄,nfs服務器也不檢查其父目錄的權限,這樣能夠提升效率;

如個人配置是:

[root@NFS-SERVER ~]# cat /etc/exports

/data/r_shared 192.168.20.0/24(ro,sync)

/data/w_shared 192.168.20.0/24(rw,sync)

 

配置好以後重啓下rpcbindnfs服務:(注意重啓前你所要共享的那兩個目錄得先存在沒有的話要先建立

 mkdir -p /data/r_shared

mkdir -p /data/w_shared )

/etc/init.d/rpcbind restart

 /etc/init.d/nfs restart

 

 

三,測試

如今本地掛載試下有沒有錯誤:

mount -t nfs 192.168.20.6:/data/r_shared /mnt

[root@NFS-SERVER ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              18G  1.2G   16G   8% /

tmpfs                 504M     0  504M   0% /dev/shm

/dev/sda1             190M   48M  132M  27% /boot

192.168.20.6:/data/r_shared

                       18G  1.2G   16G   8% /mnt

表示掛載成功

 

四,到客戶端安裝NFS服務

先檢查有沒有安裝過NFS服務的包:rpm -aq nfs-utils rpcbind

沒有的話就進行安裝:yum install nfs-utils rpcbind -y

而後開啓rpcbind的服務:

/etc/init.d/rpcbind start

也能夠加入開機自啓動裏面:

[root@lnmp01 ~]# 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

查看有沒有啓動成功

[root@lnmp01 ~]# /etc/init.d/rpcbind status

rpcbind (pid  2561) 正在運行...

而後開始掛載:

mount -t nfs 192.168.20.6:/data/r_shared /mnt

[root@lnmp01 ~]# mount -t nfs 192.168.20.6:/data/r_shared /mnt

mount.nfs: Connection timed out

出現這個問題通常是防火牆沒有關閉

暫時關閉防火牆,重啓後失效的命令是:

service iptables stop

查看防禦牆狀態的命令 是:

 service iptables status

想永久的關閉防火牆的命令是

vi /etc/selinux/config

SELINUX=enforcing

SELINUXTYPE=targeted 兩行註釋掉在最後加入

SELINUX=disabled

[root@lnmp01 ~]# cat /etc/selinux/config

 

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

#SELINUX=enforcing

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

#SELINUXTYPE=targeted

SELINUX=disabled

而後再進行掛載:

[root@lnmp01 ~]# mount -t nfs 192.168.20.6:/data/r_shared /mnt

[root@lnmp01 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              18G  1.2G   16G   8% /

tmpfs                 504M     0  504M   0% /dev/shm

/dev/sda1             190M   48M  132M  27% /boot

192.168.20.6:/data/r_shared

                       18G  1.2G   16G   8% /mnt

能夠了

相關文章
相關標籤/搜索