标签:nfs服务器客户机的配置
1、场景
某单位需要配置NFS服务器,为另外一台运行Oracle数据库的Linux服务器提供备份存储。
主机名 | IP地址 |
nfs1.abc.local | 192.168.188.11 |
db1.abc.local | 192.168.188.13 |
2、实验环境
[root@localhost ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.4 (Santiago) [root@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服务器组件
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom mount: block device /dev/sr0 is write-protected, mounting read-only [root@localhost ~]# cd /mnt/cdrom/Packages/ [root@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 [root@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服务,设置为自动启动
[root@localhost Packages]# chkconfig rpcbind on
开启nfs功能,结果failed,是因为NFS依赖rpcbind服务,必须先启动rpcbind服务才能启动nfs
[root@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服务:
[root@localhost Packages]# service rpcbind start Starting rpcbind: [ OK ]
再启动nfs服务:
[root@localhost Packages]# service nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS mountd: [ OK ] Starting NFS daemon: [ OK ]
设置NFS为自动启动
[root@localhost Packages]# chkconfig nfs on
3.3 配置NFS服务器
查看共享的NFS信息
[root@localhost Packages]# showmount -e localhost Export list for localhost: [root@localhost Packages]# mkdir /nfsdata [root@localhost Packages]# ll -ld /nfsdata/ drwxr-xr-x 2 root root 4096 Sep 11 05:03 /nfsdata/
为目录/nfsdata增加写权限
[root@localhost Packages]# chmod a+w /nfsdata/ [root@localhost Packages]# ll -ld /nfsdata/ drwxrwxrwx 2 root root 4096 Sep 11 05:03 /nfsdata/
配置export文件
[root@localhost Packages]# vi /etc/exports /nfsdata * (rw,root_squash,no_all_squash,sync)
重启nfs服务
[root@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 ] [root@localhost Packages]# showmount -e localhost Export list for localhost: /nfsdata *
连接一下自己,测试一下
[root@localhost Packages]# mkdir /mnt/nfs [root@localhost Packages]# mount 127.0.0.1:/nfsdata /mnt/nfs [root@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)
检查目录是否可以写入
[root@localhost ~]# touch /mnt/nfs/testfile1.txt [root@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包。
[root@chenzhou ~]# showmount -e 192.168.188.11 Export list for 192.168.188.11: /nfsdata * [root@chenzhou ~]# mkdir /mnt/nfs [root@chenzhou ~]# mount 192.168.188.11:/nfsdata /mnt/nfs [root@chenzhou ~]# ls /mnt/nfs -l total 0 -rw-r--r-- 1 nfsnobody nfsnobody 0 Sep 18 01:41 testfile1.txt [root@chenzhou ~]# echo test >> /mnt/nfs/testfile1.txt [root@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里的设定
标签:nfs服务器客户机的配置
原文地址:http://wanyi.blog.51cto.com/9273880/1554673