centos服务器怎么安装nfs
⑴ centos7配置nfs共享存储服务
nfs服务端需要确定这两个包正确安装 nfs-utils rpcbind
若是ubuntu服务器,则是nfs-common,nfs-kernel-server两个包,rpcbind是默认安装的。
yum -y install nfs-utils rpcbind
编辑共享目录配置文件 /etc/exports
/var/www/html 192.168.10.0/24(rw,async,no_root_squash) 192.168.20.0/24(ro)
#多个网段或主机之间用空格分开
/var/www 192.168.10.0/24(ro,sync,root_squash)
参数:ro表示只读,rw表示可读写,sync同步写*即同时写入内存和硬盘,async异步*暂存于内存,no_root_squash表示如果客户端连接过来的用户是root,则对服务端的目录同样是root权限****请不要开启,好危险的,root_squash表示客户端是root则将其转为匿名用户的权限***建议开启。
启动nfs服务,并设为开机自启动
service rpcbind start #或则 systemctl start rpcbind
service nfs start #或则 systemctl start nfs
######ubuntu服务器则是 service startnfs-kernel-server start
chkconfig rpcbind on #或则 systemctl enable rpcbind
chkconfig nfs on #或则 systemctl enable nfs
配置防火墙,放行响应端口或服务
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload
firewall-cmd --list-all #查看firewalld方向的资源
客户端挂载
showmount -e nfs_server_ip: 查看nfs服务端的可用挂载点
客户端挂载操作
mount -t nfs nfs_server:/var/www/html /bendikongmulu
或者
mount -t nfs nfs_server:/var/www/html /bendikongmulu -o proto=tcp
无报错便成功,当然客户端可以使用 df -h 来查看是否挂载过来了;这里客户端切换到本地挂载点便可以看见服务端的文件了(注意若,服务端共享的目录为空,客户端是无法查看的)网页链接
⑵ 如何在Centos 6上设置NFS挂载目录
设置NFS至少需要两台服务器,一台是提供共享文件夹的服务端,一台客户端。
假设服务器和客户端IP地址:
服务器: 192.168.1.100
客户端: 192.168.1.101
一、搭建 NFS 服务端
1、首先使用 yum 安装 NFS 软件。
至此步,即可完成在Centos 6上设置NF挂载目录。
⑶ 如何在centos上配置nfs服务
方法/步骤
Step 1:检查是否安装NFS和rpcbind两个软件。
打开linux终端,通过rpm -qa命令查看是否安装这两个包,如没有安装,请通过yum或源码包进行安装,这里不再说明安装方法。如图:
Step 2:修改配置文件:
用su切换成root用户,编辑/etc/exports文件,指定共享目录及权限等。 如图所示。我们来分析一下exports文件内容。
第一列是服务器要输出的共享目录。在本例中,共享目录是/db2Backup。
第二列指定允许哪些ip第一列的共享目录。
括号内的参数意义描述如下:
rw:读/写权限,只读权限的参数为ro;
sync:数据同步写入内存和硬盘,async,此时数据会先暂存于内存中,而不立即写入硬盘。
no_root_squash:NFS 服务器共享目录用户的属性,如果用户是 root,那么对于这个共享目录来说就具有 root 的权限。修改文件后,保存退出。
Stet 3 :启动服务
在启动NFS服务器,要先启动portmap服务,然后再启动NFS服务。操作方法如图所示:
在启动服务时,要用root。
Step 4:挂载目录
在另一台电脑上面,查看能否访问NFS服务,如果能访问,则挂载,如图所示。
首先查看能否访问NFS,命令返回的结果是可以正常访问。然后在本地建立/home/nfs文件夹,并把nfs挂载到该文件夹下面。mount -f参数指明了挂载类型是nfs。
5
Step 5:测试
经过以上4步,已经成功搭建了NFS服务,并加载到了本地文件系统中,接下来我们测试一下。cd到/home/nfs目录,mkdir一个文件夹,假设文件名是hello,然后进入到nfs服务器上,应该能看到hello文件。
6
以上就是简单的配置NFS服务的方法,未涉及防火墙等内容。如果在第4步时出现错误,请检查防火墙的设置。欢迎大家多多交流。
⑷ NFS服务搭建及数据无缝迁移
五一节办公室要停电,机房虽有UPS,但也支撑不了8小时。
因生产环境有业务系统挂了办公室机房的NAS存储,故需要进行迁移,步骤记录如下:
先闲谈下技术-----------------------
NFS和samba的区别
samba是混合型网络中的共享服务,windows服务器可建samba服务,linux服务器也可建samba服务
nfs只面向unix、linux间的共享,linux服务器可建nfs服务(winodws系统也可以挂载nfs,就是有点不稳定)
NFS服务器上的操作--------------------------
nfs服务器操作系统版本:
[root@c7110 ~]# more /etc/system-release
CentOS Linux release 7.9.2009 (Core)
nfs服务器安装nfs服务
[root@c7110 ~]# yum -y install nfs-utils rpcbind
创建nfs目录,并授权
[root@c7110 ~]# mkdir /opt/nfs-test
[root@c7110 ~]# chmod 777 /opt/nfs-test
编辑nfs服务配置文件
[root@c7110 ~]# vi /etc/exports
内容如下:
/opt/nfs-test *(rw,root_squash,all_squash,sync)
重新加载nfs配置:
[root@c7110 ~]# exportfs -r
nfs服务设置开机启动
[root@c7110 ~]# systemctl enable rpcbind
[root@c7110 ~]# systemctl enable nfs
[root@c7110 ~]# systemctl enable nfs-lock
[root@c7110 ~]# systemctl enable nfs-idmap
启动nfs服务
[root@c7110 ~]# systemctl start rpcbind
[root@c7110 ~]# systemctl start nfs
[root@c7110 ~]# systemctl start nfs-lock
[root@c7110 ~]# systemctl start nfs-idmap
查看nfs服务启动后,所监听的端口信息:
[root@c7110 ~]# rpcinfo -p
linux服务器服务器上操作-------------------------------
业务服务器安装nfs软件客户端
[root@c7111 ~]# yum -y install nfs-utils
建立一个挂载目录
[root@c7111 ~]# mkdir /opt/test-m
挂载nfs服务器共享出来的目录
[root@c7111 ~]# mount -t nfs 10.x.x.10:/opt/nfs-test /opt/test-m/
查看下已挂载的nfs
[root@c7111 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.5G 0 1.5G 0% /dev
tmpfs 1.5G 0 1.5G 0% /dev/shm
tmpfs 1.5G 8.8M 1.5G 1% /run
tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/mapper/centos-root 97G 2.3G 95G 3% /
/dev/sda1 1014M 171M 844M 17% /boot
tmpfs 297M 0 297M 0% /run/user/0
10.x.x.6:/opt/nfs-test 97G 4.1G 93G 5% /opt/test-m
经测试,数据可读可写,证明nas服务没有问题,于是进行数据同步,数据同步用rsync命令。
rsync -avp gdsz@10.87.5.6::nas_6 /mnt/guidang/ --password-file=/root/rsync_pass --bwlimit=100000
数据同步完,通知研发进行挂载切换。研发同事在测试时,发现文件属性中的uid及gid与原来的不一致,有些担心,于是又小完善了一下NFS服务。
编辑nfs服务配置文件
[root@c7110 ~]# vi /etc/exports
内容如下:
/opt/nfs-test *(no_all_squash,anonuid=600,anongid=600)
重新加载nfs配置:
[root@c7110 ~]# exportfs -r
⑸ centos7安装nfs挂载
下面记录了NFS服务器和客户端的安装步骤,并进行NFS共享,服务器和客户端都使用在CentOS 7系统。
服务端安装
准备一个要共享的目录:
编辑/etc/exports:
添加一行:(输入一下,按i键进入编辑,按Esc退出,再输入:wq保存)
更新配置文件,使之生效:
/var/nfs:共享的NFS目录
192.168.0.0/24: 客户端 IP 范围,* 代表所有,即没有限制。
rw: 权限设置,可读可写。
sync: 同步共享目录。
no_root_squash: 可以使用 root 授权。
no_all_squash: 可以使用普通用户授权。
启动相关服务:
重启 NFS 服务
可以检查一下本地的共享目录
防火墙需要打开 rpc-bind 和 nfs 的服务
二种二选一都试试
1、
2、
客户端安装
安装NFS:
(设置启动,也可能不需要设置这个步骤)
创建一个目录,做为NFS共享目录的挂载点:
挂载NFS共享目录:
查看所有挂载点:
客户端自动挂载
在结尾添加类似如下配置
由于修改了 /etc/fstab,需要重新加载 systemctl。
此时已经启动好了。如果实在不放心,可以重启一下客户端的操作系统,之后再查看一下。
⑹ centos7 挂载群辉nas文件夹
1、开启群辉上的nfs服务
2、将cnetos机器ip加入到nfs的白名单
注意:有时候ip可能经过了nat,我们要配置成 * ,允许所有ip访问。
3、在centos中创建目录例如 :mkdir /home/mnt/NFStest
4、centos系统安装nfs服务:并启动服务
5、使用命令挂载 mount -t nfs 192.168.XXX.225:/volume1/test /home/mnt/NFStest
具体根据实际情况 修改IP地址和路径
6、开启开机挂载 :vi /etc/fstab
192.168.XXX.225:/volume1/test /NFSfile nfs defaults 0 0
7、验证挂载:192.168.x.188:/volume1/test 35T 6.6T 29T 19% /home/mnt/NFStest
⑺ 如何Centos上挂载Synology的一个NFS共享文件夹
为什么要挂载Synology的NFS,是因为不想用Rsync进行同步备份。
现在的配置是在Centos上挂载Synology的一个NFS共享文件夹,然后利用Centos的的计划任务,进行定时备份。
准备:
1.打开Synology的控制面板,NFS服务,点击启动NFS服务,保存。
2.安装nfs相关的插件(未知实际是否需要,做过测试的朋友,可以的话请告诉结果小弟,谢谢)
yum install -y nfs*
到这里,准备工作已经完成。
挂载
将Synology的文件夹信息加入到fstab中
vi /etc/fstab
插入
172.16.1.12:/volume/usbshare/Websback /www/backup nfs defaults 0 0
保存并挂载
mount -a
⑻ NFS笔记(二)NFS服务器配置实例
一、NFS服务器配置实例
实验拓扑
二、实验要求及环境
2.1实验环境
NFS服务器 IP:192.168.8.5
环境:
[root@server7 ~]# uname -a
Linux server7.ctos.zu 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux
[root@server7 ~]# cat /etc/redhat-release
CentOS release 7.3.1611 (AltArch)
客户端IP:192.168.8.7
环境:
[root@client-A ~]# uname -a
Linux client-A.ctos.zu 2.6.32-696.el6.i686 #1 SMP Tue Mar 21 18:53:30 UTC 2017 i686 i686 i386 GNU/Linux
[root@client-A ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
2.2、实验要求
NFS服务器
1、/home/share 目录可读写,并且不限制用户身份,共享给192.168.8.0/24网段不的所有主机;
2、/home/data 这个目录仅共享给192.168.8.7这台主机,以供该主机上面的这个用户来使用,
也就是说在192.168.8.5和192.168.8.7上均有账号,且账号均为;
3、/home/upload 这个目录做为192.168.8.0/24网段的数据上传目录,其中/home/upload
的用户和所属组为nfs-upload这个名字,它的UID和GID均为222;
4、/home/nfs 这个目录的属性为只读,可提供除了网段内的工作站外,向Internet也提供数据内容。
三、服务器端设置
1、 编辑/etc/exports内容
[root@server7 etc]# cat /etc/exports
/home/share 192.168.8.0/24(rw,no_root_squash)
/home/data 192.168.8.7(rw)
/home/upload 192.168.8.0/24(rw,all_squash,anonuid=222,anongid=222)
/home/nfs 192.168.8.0/24(ro) *(ro,all_squash)
2、按要求建立每个对应目录
2.1、创建/home/share目录 任何人都可以在 /home/share内新增、修改文件,但
仅有该文件/目录的建立者与root能够删除自己的目录或文件。
[root@server7 etc]# mkdir -p /home/share
[root@server7 etc]# ll -d /home/share/
drwxr-xr-x. 2 root root 6 9月 5 15:50 /home/share/
[root@server7 etc]# chmod 1777 /home/share/
[root@server7 etc]# ll -d /home/share/
drwxrwxrwt. 2 root root 6 9月 5 15:50 /home/share/
2.2、创建/home/nfs
[root@server7 etc]# ll -d /home/nfs/
drwxr-xr-x. 2 root root 6 9月 5 16:52 /home/nfs/
2.3、创建/home/data目录
[root@server7 etc]# mkdir -v /home/data
mkdir: 已创建目录 "/home/data"
[root@server7 etc]# ll -d /home/data/
drwxr-xr-x. 2 root root 6 9月 5 16:57 /home/data/
[root@server7 etc]# useradd
root@server7 etc]# passwd
更改用户 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@server7 etc]# cat /etc/passwd | grep
:x:1000:1000::/home/:/bin/bash
[root@server7 etc]# chmod 700 /home/data/
[root@server7 etc]# chown -R : /home/data/
[root@server7 etc]# ll -d /home/data/
drwx------. 2 6 9月 5 16:57 /home/data/
2.4、创建/home/upload目录
#先建立对应账号与组名及UID
[root@server7 etc]# groupadd -g 222 nfs-upload
[root@server7 etc]# useradd -g 222 -u 222 -M nfs-upload
[root@server7 etc]# cat /etc/passwd|grep nfs
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nfs-upload:x:222:222::/home/nfs-upload:/bin/bash
#创建目录,修改属主
[root@server7 etc]# mkdir /home/upload
[root@server7 etc]# chown -R nfs-upload:nfs-upload /home/upload/
[root@server7 etc]# ll -d /home/upload/
drwxr-xr-x. 2 nfs-upload nfs-upload 6 9月 6 08:38 /home/upload/
2.5、重启NFS服务
[root@server7 etc]# systemctl restart nfs
[root@server7 etc]# systemctl status nfs
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Active: active (exited) since 三 2017-09-06 08:41:40 CST; 8s ago
Process: 9171 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
Process: 9169 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
Process: 9168 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
Process: 9181 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 9180 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 9181 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service
9月 06 08:41:40 server7.ctos.zu systemd[1]: Starting NFS server and services...
9月 06 08:41:40 server7.ctos.zu systemd[1]: Started NFS server and services.
[root@server7 etc]# tail /var/log/messages
Sep 6 08:41:40 server7 systemd: Started NFS Mount Daemon.
Sep 6 08:41:40 server7 rpc.mountd[9178]: Version 1.3.0 starting
Sep 6 08:41:40 server7 systemd: Started NFSv4 ID-name mapping service.
Sep 6 08:41:40 server7 systemd: Starting NFS server and services...
Sep 6 08:41:40 server7 kernel: NFSD: starting 90-second grace period (net c0c932c0)
Sep 6 08:41:40 server7 systemd: Started NFS server and services.
Sep 6 08:41:40 server7 systemd: Starting Notify NFS peers of a restart...
Sep 6 08:41:40 server7 sm-notify[9198]: Version 1.3.0 starting
Sep 6 08:41:40 server7 sm-notify[9198]: Already notifying clients; Exiting!
Sep 6 08:41:40 server7 systemd: Started Notify NFS peers of a restart.
2.6、查看NFS服务器共享出来目录
2.7、关闭防火墙、selinux
2.8查看配置
[root@server7 ~]# exportfs -v
/home/data 192.168.8.7(rw,wdelay,root_squash,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
/home/share 192.168.8.0/24(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/home/upload 192.168.8.0/24(rw,wdelay,root_squash,all_squash,no_subtree_check,anonuid=222,anongid=222,sec=sys,rw,secure,root_squash,all_squash)
/home/nfs 192.168.8.0/24(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
/home/nfs <world>(ro,wdelay,root_squash,all_squash,no_subtree_check,sec=sys,ro,secure,root_squash,all_squash)
四、客户端配置
4.1、客户端也要安装nfs-utils和rcpbind软件包
[root@client-A ~]# yum install nfs-utils rpcbind -y
4.2、启动RPC
[root@client-A ~]# service rpcbind start /systemctl start rpcbind
Starting rpcbind: [ OK ]
[root@client-A ~]# service rpcbind status
rpcbind (pid 1926) is running...
[root@client-A ~]# chkconfig --list |grep rpcbind
4.3、客户端关闭防火墙、selinux
[root@client-A ~]# service iptables stop /systemctl stop firewalld
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading moles: [ OK ]
4.4测试网络
[root@client-A ~]# ping 192.168.8.5
PING 192.168.8.5 (192.168.8.5) 56(84) bytes of data.
64 bytes from 192.168.8.5: icmp_seq=1 ttl=64 time=2.16 ms
64 bytes from 192.168.8.5: icmp_seq=2 ttl=64 time=0.697 ms
64 bytes from 192.168.8.5: icmp_seq=3 ttl=64 time=0.346 ms
64 bytes from 192.168.8.5: icmp_seq=4 ttl=64 time=0.336 ms
64 bytes from 192.168.8.5: icmp_seq=5 ttl=64 time=0.335 ms
64 bytes from 192.168.8.5: icmp_seq=6 ttl=64 time=0.317 ms
64 bytes from 192.168.8.5: icmp_seq=7 ttl=64 time=0.512 ms
64 bytes from 192.168.8.5: icmp_seq=8 ttl=64 time=0.320 ms
^C
--- 192.168.8.5 ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7555ms
rtt min/avg/max/mdev = 0.317/0.629/2.169/0.595 ms
4.5 在客户端查看NFS服务器共享出来目录
[root@client-A ~]# showmount -e 192.168.8.5
Export list for 192.168.8.5:
/home/nfs (everyone)
/home/upload 192.168.8.0/24
/home/share 192.168.8.0/24
/home/data 192.168.8.7
4.6、挂载NFS服务器上/home/nfs目录到本地/opt/data目录下
#临时挂载
#永久挂载
编辑、/etc/fstab文件,新增如下条目:
192.168.8.5:/home/nfs /opt/data/ nfs4 defaults 0 0
更多信息参考 nfs参数详解
#查看信息
[root@client-A data] # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
6.5G 644M 5.6G 11% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/sda1 477M 26M 426M 6% /boot
192.168.8.5:/home/nfs
8.0G 1.6G 6.5G 20% /opt/data
[root@client-A data]# 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.8.5:/home/nfs on /opt/data type nfs (rw,vers=4,addr=192.168.8.5,clientaddr=192.168.8.7)
#创建文件测试
[root@client-A data]# touch testabc
touch: cannot touch `testabc': Read-only file system
4.7挂载/home/upload 目录到客户端/opt/upload目录下
#挂载
[root@client-A data]# mkdir /opt/upload
[root@client-A data]# mount -t nfs 192.168.8.5:/home/upload /opt/upload/
#查看挂载是否成功
[root@client-A data]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
6.5G 644M 5.6G 11% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/sda1 477M 26M 426M 6% /boot
192.168.8.5:/home/nfs
8.0G 1.6G 6.5G 20% /opt/data
192.168.8.5:/home/upload
8.0G 1.6G 6.5G 20% /opt/upload
#客户端创建nfs-upload用户
[root@client-A ~]# groupadd -g 222 nfs-upload
[root@client-A ~]# useradd -g 222 -u 222 -m nfs-upload
#测试,可以看到创建的文件及目录默认属主为nfs-upload属组为nfs-upload
[@client-A upload]$ pwd
/opt/upload
[@client-A upload]$ ll
total 0
#测试创建文件
[@client-A upload]$ touch test123
测试创建目录
[@client-A upload]$ mkdir testdir
[@client-A upload]$ ll -a
total 4
drwxr-xr-x 3 nfs-upload nfs-upload 36 Sep 6 10:28 .
drwxr-xr-x. 4 root root 4096 Sep 6 18:22 ..
-rw-rw-r-- 1 nfs-upload nfs-upload 0 Sep 6 10:28 test123
drwxrwxr-x 2 nfs-upload nfs-upload 6 Sep 6 10:28 testdir
# 在客户端用root用户创建文件测试
root@client-A upload]# touch testabc
[root@client-A upload]# ll
total 0
-rw-r--r-- 1 root root 0 Sep 6 10:31 nfstest123
-rw-r--r-- 1 nfs-upload nfs-upload 0 Sep 6 10:32 testabc
drwxrwxr-x 2 nfs-upload nfs-upload 6 Sep 6 10:28 testdir
可以看到用root用户创建的文件属主仍是nfs-upload
#测试删除文件
[@client-A upload]$ rm test123
[@client-A upload]$ ll
total 0
drwxrwxr-x 2 nfs-upload nfs-upload 6 Sep 6 10:28 testdir
⑼ linux配置nfs步骤
NFS的配置过程很简单。在服务器端中编辑 /etc/exports 文件,添加如下内容: /home/nfs-share 192.168.1.122 (rw,sync)
第一项是要共享的目录,后者为共享的配置参数一般为: (rw,sync,no_root_squash,no_all_squash,no_subtree_check)
然后开启NFS和portmap服务:
/etc/init.d/nfs start //用service nfs start也可以 /etc/init.d/portmap start //用service portmap stasrt也可以
在centos6.5中portmap已经改为rpcbind 在客户端,用mount –t nfs 192.168.123:/home/nfs-share /home/remote_file挂载服务器端的共享目录到本地的/home/remote-file挂载点,然后我们就可以在客户端上应用到远程主机上的/home/nfs-share目录了。想要系统在开机时自动挂载,修改/etc/fstab文件,把NFS服务器的共享目录添加进去就可以了,这个不用多说。
如何知道远程主机上的共享目录情况呢?使用showmount命令,这个命令需要root权限。它有三个选项(记住这三个选项代表的含义: showmount –a IP 显示指定NFS服务器的客户端以及服务器端在客户端的挂载点 showmount –d IP 显示指定NFS服务器在客户端的挂载点 showmount –e IP 显示指定NFS服务器上的共享目录列表(或者叫输出列表) 我们输入命令showmount –a 192.168.1.123:
图片客户端中出现的mount clntudp_create: RPC: Program not registered错误是怎么回事?噢,我刚才重启了一下服务器端,重启后NFS服务没有开启。 我们开启服务器端的NFS服务,再从客户端上查看一下NFS服务器的情况:
Showmount –a显示出NFS服务器192.168.1.123的共享目录被客户端192.168.122挂载到/home中;
在showmount -e IP,出现clnt_create: RPC: Port mapper failure - Timed out报错
解决方案:
被访问的NFS服务器上的防火墙没有添加规则,向iptables里面添加以下查看的所有端口即可(目前解决的方法,当然你也可以关闭防火墙,不过这样是比较不安全的,如果你的nfs作用不大,建议你另选别的应用来替代吧!毕竟开那么多的端口,比较不安全呀!)
通过#rpcinfo -p 10.10.209.148
[root@rh01 /]# rpcinfo -p 10.10.209.148program vers proto port service100000 4 tcp 111 portmapper100000 3 tcp 111 portmapper100000 2 tcp 111 portmapper100000 4 udp 111 portmapper100000 3 udp 111 portmapper100000 2 udp 111 portmapper100024 1 udp 52943 status100024 1 tcp 37706 status100011 1 udp 875 rquotad100011 2 udp 875 rquotad100011 1 tcp 875 rquotad100011 2 tcp 875 rquotad100003 2 tcp 2049 nfs100003 3 tcp 2049 nfs100003 4 tcp 2049 nfs100227 2 tcp 2049 nfs_acl100227 3 tcp 2049 nfs_acl100003 2 udp 2049 nfs100003 3 udp 2049 nfs100003 4 udp 2049 nfs100227 2 udp 2049 nfs_acl100227 3 udp 2049 nfs_acl100021 1 udp 37438 nlockmgr100021 3 udp 37438 nlockmgr100021 4 udp 37438 nlockmgr100021 1 tcp 46331 nlockmgr100021 3 tcp 46331 nlockmgr100021 4 tcp 46331 nlockmgr100005 1 udp 57177 mountd100005 1 tcp 43147 mountd100005 2 udp 49154 mountd100005 2 tcp 54810 mountd100005 3 udp 55707 mountd100005 3 tcp 58309 mountd
[root@rh01 /]#
刚才在重启NFS服务的时候,细心的话可以注意到,我们在输入命令/etc/init.d/nfs start开启nfs服务时,系统还自作主张地开启了NFS quotas等其它3个服务。
怎么回事?我们只输入了一条启动NFS服务的命令,它怎么额外的启动了3个服务?后面的启动portmap服务又是怎么回事? 我们首先要了解一点:NFS文件系统要提供服务单靠本身的NFS服务是不够的,还需要调用其它服务,这个其它服务就是RPC(remote procere call,远程过程调用)服务和portmap服务。由于NFS服务本身不提供文件传输功能,我们要远程使用NFS文件系统就需要RPC服务的支持;而portmap服务用来为RPC服务进行动态端口分配和映射,所以portmap服务也是NFS服务所必须的。
我们查看一下服务的启动情况:
所遇错误:
/etc/init.d/nfs-kernel-server: 没有那个文件或目录
解决方案:
没有配置、安装NFS
Linux 下配置NFS服务
1、安装
2、配置
3、客户端
所遇问题:centos6.5
portmap: 未被识别的服务
解决方案:
由于在6系列里面,portmap已经改名了 ,6系列需要使用 service rpcbind start启动[root@unix-big-bang ~]# service portmap start
portmap: 未被识别的服务
[root@unix-big-bang ~]# service rpcbind status
rpcbind (pid 1312) is running...
[root@unix-big-bang ~]#
好文共赏:
linux nfs文件共享
◆一、概念
NFS是网络文件系统(Network File System)的简称,是分布式计算机系统的一个组成部分,可实现在异构网络上共享和装配远程文件系统。
NFS由SUN公司开发,目前已成为文件服务的一种标准(RFC1904,RFC1813)。其最大的功能就是可以通过网络,让不同 操作系统 的计算机可以共享数据,所以也可以看作是一个文件服务器。NFS是除了SAMBA之外Windows与Linux及Unix与Linux之间通信的方法。
理想条件下的NFS 网络拓扑结构
1、设置Linux系统之间的文件共享(Linux与Windows中间文件共享采用SAMBA服务);
2、NFS只是一种文件系统,本身没有传输功能,是基于RPC协议实现的,才能达到两个Linux系统之间的文件目录共享;
3、NFS为C/S 架构 ;
◆二、服务器配置
1、配置文件
主要配置文件为:/etc/exports
格式为: 共享目录 可mount主机IP(参数1,参数2,……)
如:/var/nfs 172.20. . (rw,sync,no_rootl_squash)
说明:必须注意nfs/目录的访问权限,必须设置成777权限;父目录/var权限无要求,普通的755即可;
2、启动相关服务
然后依次启动相关服务:portmap,nfslock,nfs
service portmap start
service nfslock start
service nfs start
关闭顺序相反。
3、检查共享目录
随后可以采用showmount –e查看一下,看看共享的目录情况:
[root@ns var]# showmount -e
Export list for ns.osserver:
/var/nfs 172.20. .
OK,到此为止,NFS服务器搭建完毕;
◆三、客户端配置
1、确保portmap运行
客户端必须确保RPC协议相应的portmap正常运行,否则mount将失败;
2、挂载/var/nfs目录(本地挂载点为/mnt/nfs)
mount -t nfs 172.20.65.16:/var/nfs /mnt/nfs
成功mount以后,即可同本地目录一样随意操作;
◆四、其它相关命令
1、当修改了/etc/exports文件后,可以不用重新启动nfs服务,直接采用exports –rv 即可重新导出共享目录;
该命令格式如下:
exportfs [-aruv]
-a :全部mount或者unmount /etc/exports中的内容
-r :重新mount /etc/exports中分享出来的目录
-u :umount 目录
-v :在 export 的时候,将详细的信息输出到屏幕上。
具体例子:
[root@ns var]# showmount -e
Export list for ns.osserver:
/var/nfs 172.20. .
[root@ns var]# exportfs –au #全部卸载
[root@ns var]# showmount -e
Export list for ns.osserver:
[root@ns var]# exportfs –rv #全部重新 export 一次
exporting 172.20. . :/var/nfs
[root@ns var]#
2、showmout命令对于NFS的操作和查错有很大的帮助,所以我们先来看一下showmount的用法
showmout
-a :这个参数是一般在NFS SERVER上使用,是用来显示已经mount上本机nfs目录的cline机器。
-e :显示指定的NFS SERVER上export出来的目录。
例如:
[root@localhost ~]# showmount -e 172.20.16.139
Export list for 172.20.16.139 :/root/share 172.20.16.137
[root@ns var]# showmount -a
All mount points on localhost.localdomain: :/root/share,172.20. . :/root/share,172.20.16. :/root/share,172.20.16.139:/nfsshare,172.20.16.139:/root/share172.20.16.137: 172.20.16.137:,172.20. . 172.20.16.137:,172.20.16. 172.20.16.137:/root/share172.20.16.139: 172.20.16.139:,172.20. . 172.20.16.139:,172.20.16. 172.20.16.139:,172.20.16.139172.20.16.139:DEFAULT
◆五、常见问题解答
1、提示:mount to NFS server 餄.20.67.203' failed: server is down.
解决方案:可能是NFS服务器的防火墙有问题;
2、提示:mount: RPC: Timed out
解决方案:由于RPC协议没运行;启动portmap服务;
也有可能是防火墙问题;Server/Client均有可能。
⑽ 如何在Centos 6上设置NFS挂载目录
NFS共享服务设置(服务端):
第1步:创建NFS服务端的共享目录。
清空iptables默认的规则链:
[root@linuxprobe ~]# iptables -F
保存清空后的iptables规则:
[root@linuxprobe ~]# service iptables save
创建nfsfile共享目录:
[root@linuxprobe ~]# mkdir /nfsfile
写入一个文件,用于NFS客户端读取:
[root@linuxprobe ~]# echo "welcome to linuxprobe.com" > /nfsfile/readme
NFS服务端配置文件是"/etc/exports",用于定义要共享的目录以及相应权限。
[root@linuxprobe ~]# vim /etc/exports
//格式为:共享目录的绝对路径 允许访问NFS资源的客户端(权限参数)
/nfsfile 192.168.10.* (rw,sync,root_squash)
NFS配置共享的参数有:
参数 作用
ro 只读默认
rw 读写模式
root_squash 当NFS客户端使用root用户访问时,映射为NFS服务端的匿名用户。
no_root_squash 当NFS客户端使用root用户访问时,映射为NFS服务端的root用户。
all_squash 不论NFS客户端使用任何帐户,均映射为NFS服务端的匿名用户。
sync 同时将数据写入到内存与硬盘中,保证不丢失数据。
async 优先将数据保存到内存,然后再写入硬盘,效率更高,但可能造成数据丢失。
第2步:启动NFS服务端
刚刚讲到NFS服务是依赖于RPC服务的,但在红帽RHEL7系统中RPC服务已经默认运行(active)了,所以无需再配置RPC服务啦。
[root@linuxprobe ~]# systemctl status rpcbind
启动nfs-server程序:
[root@linuxprobe ~]# systemctl start nfs-server
设置NFS服务端为开机启动:
[root@linuxprobe ~]# systemctl enable nfs-server
将共享挂载到客户端
第3步:配置NFS客户端
如果NFS客户端也是红帽RHEL7系统,那么软件包nfs-utils一定也是已经默认安装,直接挂载共享就可以了。
showmount命令用于查询NFS服务端共享信息,格式为:“showmount [参数] [远程主机]”。
参数 作用
-e 显示NFS服务端的共享列表
-a 显示本机挂载NFS资源的情况
-v 显示版本号
查询远程NFS服务端中可用的共享资源:
[root@linuxprobe ~]# showmount -e 192.168.10.10
Export list for 192.168.10.10:
/nfsfile (everyone)
创建本地挂载目录:
[root@linuxprobe ~]# mkdir /nfsfile
[root@linuxprobe ~]# mount -t nfs 192.168.10.10:/nfsfile /nfsfile
顺利查看到刚刚写入文件内容:
[root@linuxprobe ~]# cat /nfsfile/readme
welcome to linuxprobe.com
如果希望开机后自动将NFS资源挂载到本地,那么就可以通过修改fstab文件来实现:
[root@linuxprobe ~]# vim /etc/fstab
192.168.10.10:/nfsfile /nfsfile nfs defaults 0 0
具体过程和截图可以参看一下这篇文章:http://www.linuxprobe.com/chapter-11/#113_NFS