centOS6.4 64位下安装nfs文件共享系统

网友投稿 770 2023-03-20

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

centOS6.4 64位下安装nfs文件共享系统

不知道谁装的服务器,默认自带,以下内容摘自互联网,配置部分按教程执行成功

一、环境介绍:

服务器:centos 192.168.1.225

客户端:centos 192.168.1.226

二、安装:

NFS的安装配置:centos 5 :

yum -y install nfs-utils portmap

yum -y install nfs-utils portmap

centos 6(在CentOS 6.3当中,portmap服务由rpcbind负责) :

yum -y install nfs-utils rpcbind

yum -y install nfs-utils rpcbind

三、服务器端配置:

1、创建共享目录:

[root@centos2 /]# mkdir /usr/local/test

[root@centos2 /]# mkdir /usr/local/test

2、NFS文件配置:

[root@centos2 /]# vi /etc/exports #增加一行:/usr/local/test/ 192.168.1.226(rw,no_root_squash,no_all_squash,sync)

[root@centos2 /]# vi /etc/exports #增加一行:/usr/local/test/ 192.168.1.226(rw,no_root_squash,no_all_squash,sync)

:x保存退出;

使配置生效:

[root@centos2 /]# exportfs -r

[root@centos2 /]# exportfs -r

注:配置文件说明:

3、启动:

centos6:

[root@centos2 /]# service rpcbind start

Starting rpcbind:                                          [  OK  ][root@centos2 /]# service nfs startStarting NFS services:                                     [  OK  ]Starting NFS quotas:                                       [  OK  ]Starting NFS mountd:                                       [  OK  ]Stopping RPC idmapd:                                       [  OK  ]Starting RPC idmapd:                                       [  OK  ]Starting NFS daemon:                                       [  OK  ][root@centos2 /]# 

Starting rpcbind: [ OK ][root@centos2 /]# service nfs startStarting NFS services: [ OK ]Starting NFS quotas: [ OK ]Starting NFS mountd: [ OK ]Stopping RPC idmapd: [ OK ]Starting RPC idmapd: [ OK ]Starting NFS daemon: [ OK ][root@centos2 /]#

centos 5

[root@centos2 /]# service portmap start[root@centos2 /]# service nfs start[root@centos2 /]# 

[root@centos2 /]# service portmap start[root@centos2 /]# service nfs start[root@centos2 /]#

四、客户端挂载:

1、创建需要挂载的目录:

[root@localhost ~]# mkdir /usr/local/test[root@localhost ~]# 

[root@localhost ~]# mkdir /usr/local/test[root@localhost ~]#

2、测试挂载:

[root@localhost ~]# showmount -e 192.168.1.225Export list for 192.168.1.225:/usr/local/test 192.168.1.226[root@localhost ~]# 

[root@localhost ~]# showmount -e 192.168.1.225Export list for 192.168.1.225:/usr/local/test 192.168.1.226[root@localhost ~]#

如果显示:rpc mount export: RPC: Unable to receive; errno = No route to host,则需要在服务端关闭防火墙(稍候会详细说)。

3、挂载:

[root@localhost ~]# mount -t nfs 192.168.1.225:/usr/local/test /usr/local/test

[root@localhost ~]# 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)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)nfsd on /proc/fs/nfsd type nfsd (rw)192.168.1.225:/usr/local/test on /usr/local/test type nfs (rw,vers=4,addr=192.168.1.225,clientaddr=192.168.1.226)[root@localhost ~]# 

[root@localhost ~]# 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)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)nfsd on /proc/fs/nfsd type nfsd (rw)192.168.1.225:/usr/local/test on /usr/local/test type nfs (rw,vers=4,addr=192.168.1.225,clientaddr=192.168.1.226)[root@localhost ~]#

如果信息如上显示则挂载成功!

4、测试:

客户端生成一个文件:

[root@centos2 /]# cd /usr/local/test/[root@centos2 test]# echo "hello nfs test">>test[root@centos2 test]# lltotal 4-rw-r--r-- 1 root root 15 Apr  9 13:24 test[root@centos2 test]# 

[root@centos2 /]# cd /usr/local/test/[root@centos2 test]# echo "hello nfs test">>test[root@centos2 test]# lltotal 4-rw-r--r-- 1 root root 15 Apr 9 13:24 test[root@centos2 test]#

服务端检查:

[root@centos2 /]# cd /usr/local/test/[root@centos2 test]# lltotal 4-rw-r--r-- 1 root root 15 Apr  9 13:24 test[root@centos2 test]# 

[root@centos2 /]# cd /usr/local/test/[root@centos2 test]# lltotal 4-rw-r--r-- 1 root root 15 Apr 9 13:24 test[root@centos2 test]#

挂载成功!

五、解除挂载:

[root@localhost ~]# umount /usr/local/test

[root@localhost ~]# 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)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)nfsd on /proc/fs/nfsd type nfsd (rw)[root@localhost ~]# 

[root@localhost ~]# 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)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)nfsd on /proc/fs/nfsd type nfsd (rw)[root@localhost ~]#

如果遇到:umount.nfs: /usr/local/test: device is busy

可能用命令:

[root@localhost /]# fuser -m -v /usr/local/test

                     用户     进程号 权限   命令/usr/local/test/:              root       2798 ..c.. bash                     root       2996 ..c.. su[root@localhost /]# kill -9 2798[root@localhost /]# kill -9 2996[root@localhost /]# umount /usr/local/test[root@localhost /]#

用户 进程号 权限 命令/usr/local/test/: root 2798 ..c.. bash root 2996 ..c.. su[root@localhost /]# kill -9 2798[root@localhost /]# kill -9 2996[root@localhost /]# umount /usr/local/test[root@localhost /]#

六、服务器端防火墙设置(NFS 开启防墙配置):

1、修改/etc/service,添加以下内容(端口号必须在1024以下,且未被占用)

# Local services      mountd 1011/tcp #rpc.mountd      mountd 1011/udp #rpc.mountd      rquotad 1012/tcp #rpc.rquotad      rquotad 1012/udp #rpc.rquotad

2、重起Linux NFS服务    service nfs restart

3、此时rpc相关端口已经被固定,可以为Linux NFS添加防火墙规则    #portmap      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p tcp --dport 111 -j ACCEPT      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p udp --dport 111 -j ACCEPT      #nfsd      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p tcp --dport 2049 -j ACCEPT      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p udp --dport 2049 -j ACCEPT      #mountd      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p tcp --dport 1011 -j ACCEPT      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p udp --dport 1011 -j ACCEPT      #rquotad      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p tcp --dport 1012 -j ACCEPT      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p udp --dport 1012 -j ACCEPT      #rpc.statd      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p tcp --dport 32768 -j ACCEPT      /sbin/iptables -A INPUT -s 192.168.1.0/254 -p udp --dport 32768 -j ACCEPT ---TCP方法成功--------------------------------------------A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 1011 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 1012 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 32768 -j ACCEPT

客户端在挂载的时候遇到的一个问题如下,可能是网络不太稳定,NFS默认是用UDP协议,换成TCP协议即可:

mount -t nfs 192.168.1.225:/usr/local/test /usr/local/test  -o proto=tcp -o nolock

上一篇:智能运维场景驱动技术方案(智能运维场景驱动技术方案设计)
下一篇:Linux Shell经典实例解析:Oracle启动脚本
相关文章

 发表评论

暂时没有评论,来抢沙发吧~