阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

NFS部署应用实例

399次阅读
没有评论

共计 7117 个字符,预计需要花费 18 分钟才能阅读完成。

一、NFS 的安装准备
关闭 iptables
service iptables stop
chkconfig iptables off
设置 selinux
sed -i’s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config

二、NFS 服务端的安装
1. 安装 nfs 服务
[root@allentuns~]# yum -y install  nfs-utils rpcbind

2. 启动 nfs 服务
[root@allentuns~]# /etc/init.d/rpcbind start
Starting
rpcbind:                                         
[OK]
[root@allentuns~]# /etc/init.d/nfs start
Starting
NFS
services:                                   
[OK]
Starting
NFS
mountd:                                     
[OK]
Starting
NFS
daemon:                                     
[OK]
Starting
RPC
idmapd:                                     
[OK]

3. 创建共享目录
[root@allentuns~]# mkdir -pv /web/htdocs
mkdir:
created directory `/web’
mkdir:
created directory `/web/htdocs’
[root@allentuns~]# ll -d /web/htdocs/
drwxr-xr-x.
2 root root 4096 May  3 18:50 /web/htdocs/

4. 添加共享目录其它用户有写权限
[root@allentuns~]# chmod o+w /web/htdocs
[root@allentuns~]# ll -d /web/htdocs/
drwxr-xrwx.
2 root root 4096 May  3 18:50 /web/htdocs/

5. 修改配置文件,设置共享目录或者分区
[root@allentuns~]# vim /etc/exports
# 增加一行
/web/htdocs 192.168.1.5(rw)

6. 重读 exports 文件,使立刻生效
[root@allentuns~]# exportfs -r

7. 查看服务器共享的文件。前提需要域名解析,否则报错
[root@allentuns~]# uname -n
allentuns
[root@allentuns~]# echo “127.0.0.1 allentuns” >> /etc/hosts
[root@allentuns~]# showmount -e
Export
list for allentuns:
/web/htdocs 192.168.1.5

三、NFS 客户端的安装
1. 安装 showmount
  [root@allentuns ~]# yum -y install showmount

2. 查看服务器共享
[root@allentuns ~]# showmount -e 192.168.1.4
Export
list for 192.168.1.4:
/web/htdocs 192.168.1.5

3. 客户端挂载到本地
[root@allentuns ~]# ll /mnt/
total
0
[root@allentuns ~]# mount -t nfs 192.168.1.4:/web/htdocs /mnt/

四、验证 NFS 是否成功
服务器端 —–>> 客户端
1. 服务器端
[root@allentuns~]# ifconfig |grep “Bcast”
inetaddr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0
[root@allentuns~]# cd /web/htdocs/
[root@allentunshtdocs]# ls
[root@allentunshtdocs]# cat /etc/issue >>  index.html
[root@allentunshtdocs]# ll
total4
-rw-r–r–. 1 rootroot 47 May  3 19:06 index.html

2. 查看是否同步到客户端
[root@allentuns~]# ifconfig |grep “Bcast”
inet
addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
[root@allentuns~]# cd /mnt/
[root@allentuns mnt]# ll
total
4
-rw-r–r–.
1 root root 47 May  3 19:06 index.html

客户端 —–>> 服务器端
1. 客户端创建文件
[root@allentuns mnt]# ifconfig |grep “Bcast”
inet
addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
[root@allentuns mnt]# touch test.php
[root@allentuns mnt]# ll
total
4
-rw-r–r–.
1 root      root      47
May  3 19:06 index.html
-rw-r–r–.
1 nfsnobody nfsnobody  0 May  3 19:10 test.php

2. 服务器端看是否已经同步
[root@allentuns htdocs]# ifconfig |grep “Bcast”
inet
addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0
[root@allentuns htdocs]# ll
total
4
-rw-r–r–.
1 root      root      47
May  3 19:06 index.html
-rw-r–r–.
1 nfsnobody nfsnobody  0 May  3 19:10 test.php
以上两点证明:nfs 服务器端到客户端是双向同步的!!!

五、深入应用 NFS
以下实验大家用主机名来区分服务器端和客户端,
服务器端为 NFS_Server ip-192.168.1.4;
客户端为  NFS_Client ip-192.168.1.5;

 
实例一:
将 /tmp 分享给大家使用,让所有的人都可以存取,让 root 写入档案还是具有 root 的权限
[NFS
Server]
[root@NFS_Server~]# ll -d /tmp/  #目录 tmp 文件系统本身具有读写权限
drwxrwxrwt.
3 root root 4096 May  3 21:39 /tmp/
[root@NFS_Server~]# vim /etc/exports
/tmp 192.168.1.5(rw,root_squash)
[root@NFS_Server~]# exportfs -r #重新载入配置文件
[root@NFS_Server~]# ll /tmp
total
0
-rw——-.
1 root      root      0 Apr
23 15:05 yum.log
[NFS Client]
[root@NFS_Client~]# mkdir /share1 #创建挂载目录
[root@NFS_Client~]# ll /share1/
total
0
[root@NFS_Client~]# mount -t nfs 192.168.1.4:/tmp/ /share1/  #挂载
[root@NFS_Client share1]# ll #已同步到客户端的 /share1 目录
total
0
-rw——-.
1 root root 0 Apr 23 15:05 yum.log
[root@NFS_Client share1]# whoami #查看当前用户
root
[root@NFS_Client share1]# touch a.sh  #以 root 用户创建一个测试文件
[root@NFS_Client share1]# ll #查看 a.sh 的宿主宿组都是 root
total
0
-rw-r–r–.
1 root root 0 May  3  2014 a.sh
-rw——-.
1 root root 0 Apr 23 15:05 yum.log
[NFS Server]
[root@NFS_Server tmp]# ll  #查看 a.sh 是否同步,查看 a.sh 的宿主宿组是否是 root
total
0
-rw-r–r–.
1 root root 0 May  3 22:15 a.sh
-rw——-.
1 root root 0 Apr 23 15:05 yum.log
—End—

实验一总结:主要的就是共享权限 no_root_squash
要想明白 no_root_squash 就要先明白 root_squash 的意思
root_squash:如果客户端是以 root 身份进行对 nfs 分区操作,那么会被 root_squash 压缩成 nfsnobody。
no_root_squash:与 root_squash 意思相反,就是不压缩,仍然是以 root 用户进行进行操作 nfs 分区,安全性没有保证
例题二、
同一目录针对不同范围开放不同的权限
我们将一个公共的目录 /www/onair 公开出去,但是我们只限定我的局域网络 192.168.1.0/24 这个网且加入 Allentunsgroup 的用户才能够读写,其它来源则只能读取
[ON Server]
[root@NFS_Server ~]# mkdir /www/onair -pv
mkdir:
created directory `/www’
mkdir:
created directory `/www/onair’
[root@NFS_Server~]# touch /www/onair/a.sh
[root@NFS_Server~]# groupadd -g 500 Allentunsgroup
[root@NFS_Server~]# useradd -g Allentunsgroup -r 500 Allentuns
[root@NFS_Server~]# setfacl -m g:Allentunsgroup:rwx /www/onair  #设置 Allentunsgroup 组对 /www/onair 文件的读写执行权限
[root@NFS_Server~]# ll -d /www/onair/
drwxrwxr-x+
2 root root 4096 May  4 01:45 /www/onair/
[root@NFS_Server~]# cat /etc/group |grep Allentunsgroup #查看对应的 gid 后面会用到
Allentunsgroup:x:500:
[root@NFS_Server~]# vim /etc/exports
/www/onair        192.168.1.0/24(rw) 
*(ro)
[root@NFS_Server~]# exportfs -r
 
[ON Client]
[root@NFS_Client~]# mkdir /usr/local/onair
[root@NFS_Client~]# showmount -e 192.168.1.4
Export
list for 192.168.1.4:
/www/onair (everyone)
[root@NFS_Client~]# mount -t nfs 192.168.1.4:/www/onair /usr/local/onair/
[root@NFS_Client~]# cd /usr/local/onair/
[root@NFS_Client
onair]# ll
total
0
-rw-r–r–.
1 root root 0 May  4 01:45 a.sh
[root@NFS_Client onair]# whoami
root
[root@NFS_Clien onair]# touch b.sh #拒绝
touch:
cannot touch `b.sh’: Permission denied
root 用户拒绝写入
然后创建一个新账号,并加入到 Allentunsgroup 组中测试是否有写入权限
[root@NFS_Client~]# groupadd -g 500 Allentunsgroup
[root@NFS_Client~]# cat /etc/group |grep Allentunsgroup
Allentunsgroup:x:500:
[root@NFS_Client~]# useradd -g Allentunsgroup scott
[root@NFS_Client~]# id scott
uid=500(scott)
gid=500(Allentunsgroup) groups=500(Allentunsgroup)
[root@NFS_Client~]# passwd scott
Changing
password for user scott.
New
password:
BAD
PASSWORD: it is too short
BAD
PASSWORD: is too simple
Retype
new password:
passwd:
all authentication tokens updated successfully.
[root@NFS_Client onair]# su scott
[scott@NFS_Client onair]$ whoami
scott
[scott@NFS_Client onair]$ ll
total
0
-rw-r–r–.
1 root root 0 May  4 01:45 a.sh
[scott@NFS_Client onair]$ touch b.sh #写入成功
[scott@NFS_Client onair]$ ll
total
0
-rw-r–r–.
1 root 
root          0 May  4
01:45 a.sh
-rw-r–r–.
1 nobody Allentunsgroup 0 May  4  2014 b.sh
 
[ON Server]
[root@NFS_Server ~]# ll /www/onair/
total
0
-rw-r–r–.
1 root     
root          0 May  4
01:45 a.sh
-rw-r–r–.
1 Allentuns Allentunsgroup 0 May  4 02:11 b.sh
已经同步到 Server 端,并且同步到 server 端的用户是 Allentuns, 用户组为 Allentunsgroup
setfacl 的用法
setfacl 命令可以用来细分 linux 下的文件权限。
chmod 命令可以把文件权限分为 u,g,o 三个组,
而 setfacl 可以对每一个文件或目录设置更精确的文件权限。
比较常用的用法如下:
setfacl
–m u:apache:rwx  file 设置 apache 用户对 file 文件的 rwx 权限
setfacl
–m g:market:rwx  file  设置 market 用户组对 file 文件的 rwx 权限
setfacl
–x g:market file  删除 market 组对 file 文件的所有权限
getfacl  file  查看 file 文件的权限
Error1
[root@NFS_Server onair]# service rpcbind stop
shell-init:
error retrieving current directory: getcwd: cannot access parent directories:
No such file or directory
chdir:
error retrieving current directory: getcwd: cannot access parent directories:
No such file or directory
Stopping
rpcbind:
解决办法
退出当前目录,重新执行此命令
—End—

 

————————————– 分割线 ————————————–

Ubuntu 12.04 安装 NFS server http://www.linuxidc.com/Linux/2012-09/70728.htm

NFS 服务器安装配置实现 Ubuntu 12.04 与 ARM 文件共享 http://www.linuxidc.com/Linux/2012-10/73159.htm

Ubuntu 搭建 nfs 服务器 http://www.linuxidc.com/Linux/2012-10/71930.htm

文件服务器 NFS 配置详解 http://www.linuxidc.com/Linux/2013-06/86542.htm

Ubuntu 下搭建 NFS 网络文件系统服务器 http://www.linuxidc.com/Linux/2013-07/87367.htm

Heartbeat_ldirector+LB+NFS 实现 HA 及 LB、文件共享 http://www.linuxidc.com/Linux/2013-06/85292.htm

CentOS 5.5 配置 NFS 服务器教程 http://www.linuxidc.com/Linux/2013-03/81737.htm

Ubuntu 12.10 下 NFS 的安装使用 http://www.linuxidc.com/Linux/2013-03/80478.htm

————————————– 分割线 ————————————–

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-04/115645.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计7117字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19350
评论数
4
阅读量
7960924
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
告别Notion焦虑!这款全平台开源加密笔记神器,让你的隐私真正“上锁”

告别Notion焦虑!这款全平台开源加密笔记神器,让你的隐私真正“上锁”

  告别 Notion 焦虑!这款全平台开源加密笔记神器,让你的隐私真正“上锁” 引言 在数字笔记工...
4盘位、4K输出、J3455、遥控,NAS硬件入门性价比之王

4盘位、4K输出、J3455、遥控,NAS硬件入门性价比之王

  4 盘位、4K 输出、J3455、遥控,NAS 硬件入门性价比之王 开篇 在 NAS 市场中,威...
多服务器管理神器 Nexterm 横空出世!NAS/Win/Linux 通吃,SSH/VNC/RDP 一站式搞定

多服务器管理神器 Nexterm 横空出世!NAS/Win/Linux 通吃,SSH/VNC/RDP 一站式搞定

多服务器管理神器 Nexterm 横空出世!NAS/Win/Linux 通吃,SSH/VNC/RDP 一站式搞...
飞牛NAS玩转Frpc并且配置,随时随地直连你的私有云

飞牛NAS玩转Frpc并且配置,随时随地直连你的私有云

飞牛 NAS 玩转 Frpc 并且配置,随时随地直连你的私有云 大家好,我是星哥,最近在玩飞牛 NAS。 在数...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
150元打造低成本NAS小钢炮,捡一块3865U工控板

150元打造低成本NAS小钢炮,捡一块3865U工控板

150 元打造低成本 NAS 小钢炮,捡一块 3865U 工控板 一块二手的熊猫 B3 工控板 3865U,搭...
浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍

浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍

浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍 前言 在 AI 自动化快速发展的当下,浏览器早已不再只是...
12.2K Star 爆火!开源免费的 FileConverter:右键一键搞定音视频 / 图片 / 文档转换,告别多工具切换

12.2K Star 爆火!开源免费的 FileConverter:右键一键搞定音视频 / 图片 / 文档转换,告别多工具切换

12.2K Star 爆火!开源免费的 FileConverter:右键一键搞定音视频 / 图片 / 文档转换...
星哥带你玩飞牛NAS硬件 01:捡垃圾的最爱双盘,暴风二期矿渣为何成不老神话?

星哥带你玩飞牛NAS硬件 01:捡垃圾的最爱双盘,暴风二期矿渣为何成不老神话?

星哥带你玩飞牛 NAS 硬件 01:捡垃圾的最爱双盘,暴风二期矿渣为何成不老神话? 前言 在选择 NAS 用预...
颠覆 AI 开发效率!开源工具一站式管控 30+大模型ApiKey,秘钥付费+负载均衡全搞定

颠覆 AI 开发效率!开源工具一站式管控 30+大模型ApiKey,秘钥付费+负载均衡全搞定

  颠覆 AI 开发效率!开源工具一站式管控 30+ 大模型 ApiKey,秘钥付费 + 负载均衡全...