Centos6.4搭建NFS 服务器实例:
服务器系统 |
角色 |
IP |
CentOS-64-121-server1 |
NFS服务器端 |
192.168.1.121 |
CentOS-64-129-client |
NFS客户端 |
192.168.1.129 |
共享CentOS-64-121-server1中/data/bbs目录,使192.168.1.1 IP段所有主机都可以访问
配置服务端:
首先创建实验环境目录
[[email protected] ~]# mkdir /data/bbs –p [[email protected] bbs]# chown -Rnfsnobody.nfsnobody /data/bbs [[email protected] bbs]# ls -ld /data/bbs drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Jan19 17:08 /data/bbs
- 检查服务器系统信息
[[email protected] ~]# cat /etc/redhat-release CentOS release 6.4 (Final) [[email protected] ~]# uname -n 64server1 [[email protected] ~]# uname -r 2.6.32-358.el6.x86_64 [[email protected] ~]# uname -m x86_64 [[email protected] ~]# uname -a Linux 64server1 2.6.32-358.el6.x86_64 #1SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [[email protected] ~]# [[email protected] ~]# ifconfig eth0 Link encap:Ethernet HWaddr00:0C:29:03:A5:40 inet addr:192.168.1.121 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe03:a540/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:163 errors:0 dropped:0 overruns:0 frame:0 TX packets:126 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:14926 (14.5 KiB) TXbytes:13877 (13.5 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0b)
分别查看服务端的相关信息,如ip,主机名等等
- 检查NFS软件
[[email protected] ~]# rpm -aq|egrep"nfs-utils|rpcbind" nfs-utils-1.2.3-36.el6.x86_64 nfs-utils-lib-1.1.5-6.el6.x86_64 rpcbind-0.2.0-11.el6.x86_64
- 查看服务器的centos中5.8 portmap、6.4 rpcbind服务有没有启动和检查nfs、启动nfs
[[email protected] ~]# /etc/init.d/rpcbindstatus rpcbind (pid 1100) is running... [[email protected] ~]# /etc/init.d/nfs status rpc.svcgssd is stopped rpc.mountd is stopped nfsd is stopped rpc.rquotad is stopped [[email protected] ~]# /etc/init.d/nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS mountd: [ OK ] Stopping RPC idmapd: [ OK ] Starting RPC idmapd: [ OK ] Starting NFS daemon: [ OK ] [[email protected] ~]# /etc/init.d/nfsstatus rpc.svcgssd is stopped rpc.mountd (pid 1606) is running... nfsd (pid 1671 1670 1669 1668 1667 16661665 1664) is running... rpc.rquotad (pid 1602) is running...
- 配置NFS及portmap(Centos6.4下为rpcbind)服务开机自启动
[[email protected] ~]# echo "#NFS6.4Server start at dingjian to2014.01.19">>/etc/rc.local [[email protected] ~]# echo "/etc/init.d/rpcbindstart" >>/etc/rc.local [[email protected] ~]# echo"/etc/init.d/nfs start" >>/etc/rc.local [[email protected] ~]# tail -3 /etc/rc.local #NFS6.4 Server start at dingjianto2014.01.19 /etc/init.d/rpcbind start /etc/init.d/nfs start
- 配置NFS服务
[[email protected] ~]# echo "#NFS shared/data/bbs 2014.01.19">>/etc/exports [[email protected] ~]# echo "/data/bbs/192.168.1.1/24(rw,sync)">>/etc/exports [[email protected] ~]# tail -2 /etc/exports #NFS shared /data/bbs 2014.01.19 /data/bbs/ 192.168.1.1/24(rw,sync)
六、/etc/init.d/nfs reload 或exportfs -rv进行nfs重新加载
七、showmount -e localhost show一下自己,看服务端有没有配置好
[[email protected] bbs]# showmount -elocalhost Export list for localhost: /data/bbs 192.168.1.1/24
八、授权nfsnobody于/data/bbs 让客户端挂载后可写可读
[[email protected] ~]# chown nfsnobody:nfsnobody/data/bbs -R [[email protected] ~]# ls -ld /data/bbs drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Feb16 18:30 /data/bbs
客户端配置:
- 检查系统环境
[[email protected] ~]# cat /etc/redhat-release CentOS release 6.4 (Final) [[email protected] ~]# uname -a Linux 64client 2.6.32-358.el6.x86_64 #1 SMPFri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [[email protected] ~]# uname -n 64client [[email protected] ~]# uname -r 2.6.32-358.el6.x86_64 [[email protected] ~]# uname -m x86_64
2.检查和启动rpcbind(Centos5.8为portmap)服务(注意无需启动NFS服务)
[[email protected] ~]# rpm -aq|grep rpcbind rpcbind-0.2.0-11.el6.x86_64 [[email protected] ~]# /etc/init.d/rpcbindstatus rpcbind (pid 1115) is running...
3.把rpcbind加入开机自启动
[[email protected] ~]# echo "#NFS Clientstart at dingjian 2014.01.19">>/etc/rc.local [[email protected] ~]# echo"/etc/init.d/rpcbind start">>/etc/rc.local [[email protected] ~]# tail -2 /etc/rc.local #NFS Client start at dingjian 2014.01.19 /etc/init.d/rpcbind start
4扫描NFS服务器的文件共享例表
[[email protected] ~]# showmount -e192.168.1.121 Export list for 192.168.1.121: /data/bbs 192.168.1.1/24
5.挂载NFS服务器共享目录到本地系统
[[email protected] ~]# mount -t nfs192.168.1.121:/data/bbs /mnt [[email protected] ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 18375548 1511476 15930648 9% / tmpfs 118188 0 118188 0% /dev/shm /dev/sda1 198337 28568 159529 16% /boot 192.168.1.121:/data/bbs 18375552 1503872 15938240 9% /mnt
6.配置开机自动挂载NFS共享目录
[[email protected] ~]# echo "mount -t nfs192.168.1.121:/data/bbs /mnt">>/etc/rc.local [[email protected] ~]# tail -3 /etc/rc.local #NFS Client start at dingjian 2014.01.19 /etc/init.d/rpcbind start mount -t nfs 192.168.1.121:/data/bbs /mnt
7.测试数据
[[email protected] ~]# cd /data/bbs [[email protected] bbs]# touch aa [[email protected] ~]# ls /mnt aa
提示: 1.配置NFS服务端后,不用重启NFS服务,只要使用exportfs -rv或/etc/init.d/nfs reload重新加载就可以了
2.rpc主程序Centos5.8下为portmap 、Centos6.4下为rpcbind
3.NFS共享目录不要授权于777权限,可以改所属主和组为nfsnobody,因为nfsnobody权限不是很大,也不能登陆
时间: 2024-10-05 20:19:35