centos开启NFS

[root@centos-0 ~]# rpm -qa|grep rpcbind
[root@centos-0 ~]# rpm -qa|grep nfs


[root@centos-0 ~]# chkconfig --list
NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
blk-availability        0:off   1:on    2:on    3:on    4:on    5:on    6:off
bluetooth       0:off   1:off   2:off   3:on    4:on    5:on    6:off
cpuspeed        0:off   1:on    2:on    3:on    4:on    5:on    6:off
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
dnsmasq         0:off   1:off   2:off   3:off   4:off   5:off   6:off
firstboot       0:off   1:off   2:off   3:on    4:off   5:on    6:off
haldaemon       0:off   1:off   2:off   3:on    4:on    5:on    6:off
ip6tables       0:off   1:off   2:on    3:on    4:on    5:on    6:off
iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off
irqbalance      0:off   1:off   2:off   3:on    4:on    5:on    6:off
kdump           0:off   1:off   2:off   3:on    4:on    5:on    6:off
lvm2-monitor    0:off   1:on    2:on    3:on    4:on    5:on    6:off
mdmonitor       0:off   1:off   2:on    3:on    4:on    5:on    6:off
messagebus      0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
netfs           0:off   1:off   2:off   3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
ntpd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
ntpdate         0:off   1:off   2:off   3:off   4:off   5:off   6:off
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
psacct          0:off   1:off   2:off   3:off   4:off   5:off   6:off
quota_nld       0:off   1:off   2:off   3:off   4:off   5:off   6:off
rdisc           0:off   1:off   2:off   3:off   4:off   5:off   6:off
restorecond     0:off   1:off   2:off   3:off   4:off   5:off   6:off
rngd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
saslauthd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
smartd          0:off   1:off   2:off   3:off   4:off   5:off   6:off
spice-vdagentd  0:off   1:off   2:off   3:off   4:off   5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
svnserve        0:off   1:off   2:off   3:off   4:off   5:off   6:off
sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off
udev-post       0:off   1:on    2:on    3:on    4:on    5:on    6:off
vsftpd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
wdaemon         0:off   1:off   2:off   3:off   4:off   5:off   6:off
winbind         0:off   1:off   2:off   3:off   4:off   5:off   6:off
wpa_supplicant  0:off   1:off   2:off   3:off   4:off   5:off   6:off

yum install nfs-utils.x86_64

 

[root@centos-0 ~]# yum install nfs-utils.x86_64
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
base                                                                                                                   | 3.7 kB     00:00    
extras                                                                                                                 | 3.4 kB     00:00    
updates                                                                                                                | 3.4 kB     00:00    
updates/primary_db                                                                                                     | 5.1 MB     00:09    
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.2.3-36.el6 will be installed
--> Processing Dependency: nfs-utils-lib >= 1.1.0-3 for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: keyutils >= 1.4-4 for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: rpcbind for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libtirpc for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libgssglue.so.1(libgssapi_CITI_2)(64bit) for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libgssglue for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libevent for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libgssglue.so.1()(64bit) for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Processing Dependency: libevent-1.4.so.2()(64bit) for package: 1:nfs-utils-1.2.3-36.el6.x86_64
--> Running transaction check
---> Package keyutils.x86_64 0:1.4-4.el6 will be installed
---> Package libevent.x86_64 0:1.4.13-4.el6 will be installed
---> Package libgssglue.x86_64 0:0.1-11.el6 will be installed
---> Package libtirpc.x86_64 0:0.2.1-6.el6_4 will be installed
---> Package nfs-utils-lib.x86_64 0:1.1.5-6.el6 will be installed
---> Package rpcbind.x86_64 0:0.2.0-11.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================
 Package                             Arch                         Version                                 Repository                     Size
==============================================================================================================================================
Installing:
 nfs-utils                           x86_64                       1:1.2.3-36.el6                          base                          319 k
Installing for dependencies:
 keyutils                            x86_64                       1.4-4.el6                               base                           39 k
 libevent                            x86_64                       1.4.13-4.el6                            base                           66 k
 libgssglue                          x86_64                       0.1-11.el6                              base                           23 k
 libtirpc                            x86_64                       0.2.1-6.el6_4                           updates                        78 k
 nfs-utils-lib                       x86_64                       1.1.5-6.el6                             base                           67 k
 rpcbind                             x86_64                       0.2.0-11.el6                            base                           51 k

Transaction Summary
==============================================================================================================================================
Install       7 Package(s)

Total download size: 644 k
Installed size: 1.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): keyutils-1.4-4.el6.x86_64.rpm                                                                                   |  39 kB     00:00    
(2/7): libevent-1.4.13-4.el6.x86_64.rpm                                                                                |  66 kB     00:00    
(3/7): libgssglue-0.1-11.el6.x86_64.rpm                                                                                |  23 kB     00:00    
(4/7): libtirpc-0.2.1-6.el6_4.x86_64.rpm                                                                                                                  |  78 kB     00:00    
(5/7): nfs-utils-1.2.3-36.el6.x86_64.rpm                                                                                                                  | 319 kB     00:02    
(6/7): nfs-utils-lib-1.1.5-6.el6.x86_64.rpm                                                                                                               |  67 kB     00:00    
(7/7): rpcbind-0.2.0-11.el6.x86_64.rpm                                                                                                                    |  51 kB     00:00    
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                            141 kB/s | 644 kB     00:04    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libgssglue-0.1-11.el6.x86_64                                                                                                                                  1/7
  Installing : libtirpc-0.2.1-6.el6_4.x86_64                                                                                                                                 2/7
  Installing : rpcbind-0.2.0-11.el6.x86_64                                                                                                                                   3/7
  Installing : keyutils-1.4-4.el6.x86_64                                                                                                                                     4/7
  Installing : libevent-1.4.13-4.el6.x86_64                                                                                                                                  5/7
  Installing : nfs-utils-lib-1.1.5-6.el6.x86_64                                                                                                                              6/7
  Installing : 1:nfs-utils-1.2.3-36.el6.x86_64                                                                                                                               7/7
  Verifying  : rpcbind-0.2.0-11.el6.x86_64                                                                                                                                   1/7
  Verifying  : 1:nfs-utils-1.2.3-36.el6.x86_64                                                                                                                               2/7
  Verifying  : libevent-1.4.13-4.el6.x86_64                                                                                                                                  3/7
  Verifying  : nfs-utils-lib-1.1.5-6.el6.x86_64                                                                                                                              4/7
  Verifying  : libgssglue-0.1-11.el6.x86_64                                                                                                                                  5/7
  Verifying  : keyutils-1.4-4.el6.x86_64                                                                                                                                     6/7
  Verifying  : libtirpc-0.2.1-6.el6_4.x86_64                                                                                                                                 7/7

Installed:
  nfs-utils.x86_64 1:1.2.3-36.el6                                                                                                                                               

Dependency Installed:
  keyutils.x86_64 0:1.4-4.el6      libevent.x86_64 0:1.4.13-4.el6    libgssglue.x86_64 0:0.1-11.el6    libtirpc.x86_64 0:0.2.1-6.el6_4    nfs-utils-lib.x86_64 0:1.1.5-6.el6  
  rpcbind.x86_64 0:0.2.0-11.el6  

Complete!
[root@centos-0 ~]#

 

[root@centos-1 ~]# /etc/rc.d/init.d/nfs restart
Shutting down NFS daemon: [FAILED]
Shutting down NFS mountd: [FAILED]
Shutting down NFS quotas: [FAILED]
Starting NFS services:  [  OK  ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[FAILED]
Starting NFS mountd: [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)
rpc.nfsd: unable to set any sockets for nfsd
[FAILED]


开启rpcbind
[root@centos-1 ~]# /etc/init.d/rpcbind start
Starting rpcbind: [  OK  ]


开启nfs
[root@centos-1 ~]#  /etc/init.d/nfs start
Starting NFS services:  [  OK  ]
Starting NFS quotas: [  OK  ]
Starting NFS mountd: [  OK  ]
Starting NFS daemon: [  OK  ]
[root@centos-1 ~]# showmount
Hosts on centos-1.msdomain:
2013/11/11

[root@centos-1 ~]# chkconfig rpcbind on
[root@centos-1 ~]# chkconfig nfs on

[root@centos-1 ~]# showmount
clnt_create: RPC: Program not registered

[root@centos-1 ~]#  /etc/init.d/nfs restart

[root@centos-1 ~]# showmount
Hosts on centos-1.msdomain:

 

可以mount本地一个目录到另外一个目录,以便提供NFS
mount --bind /home/bigdir /mnt/nfsdir

fstab 中加入如下内容,以便开机启动挂载
/mnt/nfsdir /home/bigdir none rw,bind 0 0

/etc/exports中加入如下内容,以便导出NFS列表
/mnt/nfsdir 192.168.0.1/24(rw,sync,no_root_squash)

192.168.0.1/24 指192.168.0.x网段可访问,也可指定固定IP地址

ro 只读访问
rw 读写访问
sync 所有数据在请求时写入共享
async NFS在写入数据前可以相应请求
secure NFS通过1024以下的安全TCP/IP端口发送
insecure NFS通过1024以上的端口发送
wdelay 如果多个用户要写入NFS目录,则归组写入(默认)
no_wdelay 如果多个用户要写入NFS目录,则立即写入,当使用async时,无需此设置。
hide 在NFS共享目录中不共享其子目录
no_hide 共享NFS目录的子目录
subtree_check 如果共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认)
no_subtree_check 和上面相对,不检查父目录权限
all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
no_all_squash 保留共享文件的UID和GID(默认)
root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)
no_root_squas root用户具有根目录的完全管理访问权限
anonuid=xxx 指定NFS服务器/etc/passwd文件中匿名用户的UID


客户机/etc/fstab加入如下内容,以便启动自动挂载

ServerA:/mnt/nfsdir /mnt/nfsdir nfs rw,timeo=300,retrans=5,hard,intr,bg,suid
其中,
ServerA - NFS 服务器的计算机名
rw - 读和写访问
timeo=300 - 如果 nfs 服务器在规定时间内没有响应(以十分之一秒为单位),则允许内核超时
retrans=5 - 设置在返回错误之前重复的请求数
hard - 当服务器挂起时,客户机将被阻塞,直到服务器重新处于活动状态
intr - 客户机(用户)可以中断会导致错误的被阻塞的操作
bg - 如果装配失败,系统继续在后台重试,然后继续
suid - 允许 set-user-identifier 或 set-group-identifier 生效

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章