|
1、场景
某单位需要配置NFS服务器,为另外一台运行Oracle数据库的Linux服务器提供备份存储。
| 主机名 | IP地址 | | nfs1.abc.local | 192.168.188.11 | db1.abc.local | 192.168.188.13 | 2、实验环境
1
2
3
4
| [iyunv@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[iyunv@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
|
3、NFS服务器安装与配置
3.1 安装NFS服务器组件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| [iyunv@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[iyunv@localhost ~]# cd /mnt/cdrom/Packages/
[iyunv@localhost Packages]# ls *nfs*
nfs4-acl-tools-0.3.3-6.el6.x86_64.rpm sblim-cmpi-nfsv3-1.1.1-1.el6.i686.rpm
nfs-utils-1.2.3-36.el6.x86_64.rpm sblim-cmpi-nfsv3-1.1.1-1.el6.x86_64.rpm
nfs-utils-lib-1.1.5-6.el6.i686.rpm sblim-cmpi-nfsv4-1.1.0-1.el6.i686.rpm
nfs-utils-lib-1.1.5-6.el6.x86_64.rpm sblim-cmpi-nfsv4-1.1.0-1.el6.x86_64.rpm
[iyunv@localhost Packages]# rpm -Uvh nfs-utils-1.2.3-36.el6.x86_64.rpm libevent-1.4.13-4.el6.x86_64.rpm keyutils-1.4-4.el6.x86_64.rpm rpcbind-0.2.0-11.el6.x86_64.rpm libgssglue-0.1-11.el6.x86_64.rpm nfs-utils-lib-1.1.5-6.el6.x86_64.rpm libtirpc-0.2.1-5.el6.x86_64.rpm
warning: nfs-utils-1.2.3-36.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:libgssglue ########################################### [ 14%]
2:libtirpc ########################################### [ 29%]
3:rpcbind ########################################### [ 43%]
4:keyutils ########################################### [ 57%]
5:libevent ########################################### [ 71%]
6:nfs-utils-lib ########################################### [ 86%]
7:nfs-utils ########################################### [100%]
|
3.2 启动NFS服务
NFS依赖rpcbind服务,设置为自动启动
1
| [iyunv@localhost Packages]# chkconfig rpcbind on
|
开启nfs功能,结果failed,是因为NFS依赖rpcbind服务,必须先启动rpcbind服务才能启动nfs
1
2
3
4
5
6
7
8
9
| [iyunv@localhost Packages]# service nfs start
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服务:
1
2
| [iyunv@localhost Packages]# service rpcbind start
Starting rpcbind: [ OK ]
|
再启动nfs服务:
1
2
3
4
5
| [iyunv@localhost Packages]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
|
设置NFS为自动启动
1
| [iyunv@localhost Packages]# chkconfig nfs on
|
3.3 配置NFS服务器
查看共享的NFS信息
1
2
3
4
5
| [iyunv@localhost Packages]# showmount -e localhost
Export list for localhost:
[iyunv@localhost Packages]# mkdir /nfsdata
[iyunv@localhost Packages]# ll -ld /nfsdata/
drwxr-xr-x 2 root root 4096 Sep 11 05:03 /nfsdata/
|
为目录/nfsdata增加写权限
1
2
3
| [iyunv@localhost Packages]# chmod a+w /nfsdata/
[iyunv@localhost Packages]# ll -ld /nfsdata/
drwxrwxrwx 2 root root 4096 Sep 11 05:03 /nfsdata/
|
配置export文件
1
2
| [iyunv@localhost Packages]# vi /etc/exports
/nfsdata * (rw,root_squash,no_all_squash,sync)
|
重启nfs服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| [iyunv@localhost Packages]# service nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: exportfs: No options for /nfsdata *: suggest *(sync) to avoid warning
exportfs: No host name given with /nfsdata (rw,root_squash,no_all_squash,sync), suggest *(rw,root_squash,no_all_squash,sync) to avoid warning
exportfs: incompatible duplicated export entries:
exportfs: *:/nfsdata (0x424) [IGNORED]
exportfs: *:/nfsdata (0x425)
[ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
[iyunv@localhost Packages]# showmount -e localhost
Export list for localhost:
/nfsdata *
|
连接一下自己,测试一下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| [iyunv@localhost Packages]# mkdir /mnt/nfs
[iyunv@localhost Packages]# mount 127.0.0.1:/nfsdata /mnt/nfs
[iyunv@localhost Packages]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sdb1 on /test_qu type ext4 (rw,usrquota)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /mnt/cdrom type iso9660 (ro)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
127.0.0.1:/nfsdata on /mnt/nfs type nfs (rw,vers=4,addr=127.0.0.1,clientaddr=127.0.0.1)
|
检查目录是否可以写入
1
2
3
| [iyunv@localhost ~]# touch /mnt/nfs/testfile1.txt
[iyunv@localhost ~]# ll /mnt/nfs/testfile1.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 Sep 18 01:41 /mnt/nfs/testfile1.txt
|
3.4 配置NFS客户机
NFS客户机也需要安装nfs-utils包。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@chenzhou ~]# showmount -e 192.168.188.11
Export list for 192.168.188.11:
/nfsdata *
[iyunv@chenzhou ~]# mkdir /mnt/nfs
[iyunv@chenzhou ~]# mount 192.168.188.11:/nfsdata /mnt/nfs
[iyunv@chenzhou ~]# ls /mnt/nfs -l
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Sep 18 01:41 testfile1.txt
[iyunv@chenzhou ~]# echo test >> /mnt/nfs/testfile1.txt
[iyunv@chenzhou ~]# ls /mnt/nfs/testfile1.txt -l
-rw-r--r-- 1 nfsnobody nfsnobody 5 Sep 18 02:01 /mnt/nfs/testfile1.txt
|
4.总结
对于NFS,服务器和客户机都需要安装nfs-utils包。
showmount -e +主机 显示当前主机/etc/exports里的共享目录
exportfs -r 重新挂载/etc/exports里的设定
|