ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

05 - Ubuntu 18.04如何共享图片存储--NFS安装配置

2022-06-03 11:02:23  阅读:187  来源: 互联网

标签:tpc 18.04 05 -- webapps system6 nfs docs ROOT


Ubuntu 18.04如何共享图片存储--NFS安装配置

如果遇到  stale file handle nfs   如果主服务器把相应的共享目录关闭, 或者主服务器重启, 如果从服务器 df -h 找不到共享盘,  执行  sudo mount -t nfs 10.3.0.13:/tpc/webapps/system6/ROOT/docs   /tpc/webapps/system6/ROOT/docs  命令时 

遇到  cannot access '/tpc/webapps/system6/ROOT/docs': Stale file handle

要在从服务器上先  sudo umount /tpc/webapps/system6/ROOT/docs

再 sudo mount -t nfs 10.3.0.13:/tpc/webapps/system6/ROOT/docs /tpc/webapps/system6/ROOT/docs 可解决问题  http://blog.51cto.com/11374450/1866111

 

  如果运行命令 df -h  没有发现共享目录,则执行如下的命令:

 Master

  sudo /etc/init.d/rpcbind restart 重启rpcbind 服务。

  sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务。

Slave
  sudo mount -t nfs 10.3.0.13:/tpc/webapps/system6/ROOT/docs   /tpc/webapps/system6/ROOT/docs

可能存在的问题是Master 服务器的nfs-kernel-server 没有启动成功, 解决方法:在重新启动Slaver服务器前, /etc/init.d/nfs-kernel-server status 查看一下状态,然后启动Master的nfs服务  sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务。 然后重新启动从服务   What do you get from '/etc/init.d/nfs-kernel-server status' when you first boot up? Since it reports OK, it sounds like the server is starting on boot. If that isn't the case, you can add it with 'update-rc.d nfs-kernel-server defaults' but it should automatically be added once you install it. You should also check the status of the portmap service with '/etc/init.d/portmap status' and add that too if it is missing.  

1、在主服务器10.3.0.13 上执行命令:sudo apt-get install nfs-kernel-server ;

2、执行命令:sudo  mkdir  -p /tpc/webapps/system6/ROOT/docs  建立一个nfs服务的专有的图片共享文件夹;

   如下不是必须的

  #让任何用户都能访问该目录 

  #sudo chown nobody:nogroup /tpc/webapps/system6/ROOT/docs 

  # 都有读写权限

  #sudo chmod 777 /tpc/webapps/system6/ROOT/docs 

3、建立好文件夹后,接着执行命令:sudo vi /etc/exports 配置nfs;

4、在文章的最后一行添加:

#directory_to_share       client(share_option1,...,share_optionN)

#/home 111.111.111.111(rw,sync,no_root_squash,no_subtree_check)
#/var/nfs    111.111.111.111(rw,sync,no_subtree_check)

/tpc/webapps/system6/ROOT/docs 10.3.0.14(rw,sync,no_root_squash,no_subtree_check)

 


#/tpc/webapps/system6/ROOT/docs *(rw,sync,no_root_squash,no_subtree_check)这一行的含义是:
/tpc/webapps/system6/ROOT/docs:与nfs服务客户端共享的目录,这个路径必须和你前面设置的文件的路径一致!


*:允许所有的网段访问,也可以使用具体的IP, 如 10.3.0.14


rw:挂接此目录的客户端对该共享目录具有读写权限  This option gives the client computer both read and write access to the volume.


sync:资料同步写入内存和硬盘 This option forces NFS to write changes to disk before replying. This results in a more stable and consistent environment, since the reply reflects the actual state of the remote volume.


no_root_squash:root用户具有对根目录的完全管理访问权限。  By default, NFS translates requests from a root user remotely into a non-privileged user on the server. This was supposed to be a security feature by not allowing a root account on the client to use the filesystem of the host as root. This directive disables this for certain shares.


no_subtree_check:不检查父目录的权限。  This option prevents subtree checking, which is a process where the host must check whether the file is actually still available in the exported tree for every request. This can cause many problems when a file is renamed while the client has it opened. In almost all cases, it is better to disable subtree checking.

5、修改完上述配置文件保存退出。

6、执行命令:sudo /etc/init.d/rpcbind restart 重启rpcbind 服务。nfs是一个RPC程序,使用它前,需要映射好端口,通过rpcbind 设定。

7、执行命令:sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务。

 

 

8、在另外一台服务器103.0.14上如何挂载NFS图片共享目录指令:

install nfs-common

# sudo apt-get install nfs-common

 

#sudo mkdir -p /tpc/webapps/system6/ROOT/docs
sudo mount -t nfs 10.3.0.13:/tpc/webapps/system6/ROOT/docs   /tpc/webapps/system6/ROOT/docs

这样挂载后 只有/tpc/webapps/system6/ROOT/docs 是各台服务器共享的,而其他的目录如/tpc/webapps/system6/ROOT/xyz  是各台服务器分立的,非共享的,达到了性能要求。


到任意一台服务器中执行挂载指令,则可以将指定ip服务器上的共享路径,挂载到本地。

注:nfs只是一种文件目录共享模式,以本地方式进行访问。而HDFS是一种分布式的文件系统,能够在服务器中进行数据的负载均衡。

如果取消挂载

sudo umount /tpc/webapps/system6/ROOT/docs

9、开机自动挂载:
把 上述指令

 sudo mount -t nfs 10.3.0.13:/tpc/webapps/system6/ROOT/docs   /tpc/webapps/system6/ROOT/docs 写到 /etc/rc.local 文件中

但是要注意的问题是:主服务器一定要在从服务器之前启动完成,否则挂载文件失败。从而导致共享失败。如果出现这种情况可以等主服务器启动完成后执行该语句从而完成影射

 sudo mount -t nfs 10.3.0.13:/tpc/webapps/system6/ROOT/docs   /tpc/webapps/system6/ROOT/docs

也可以通过fstab 挂载

通过‘fstab’也可以配置 NFS 和 SMB 的共享目录。由于涉及到的可选项很重要,并且需要了解一些协议的工作情况,您得先阅读 Samba 和 NFS 。

Step 8 — Mounting the Remote NFS Directories at Boot

We can mount the remote NFS shares automatically at boot by adding them to /etc/fstab file on the client.

Open this file with root privileges in your text editor:

  • sudo vi /etc/fstab

At the bottom of the file, we're going to add a line for each of our shares. They will look like this:

 

10.3.0.13:/tpc/webapps/system6/ROOT/docs    /tpc/webapps/system6/ROOT/docs   nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

 

 

 

 

但是要注意的问题是:主服务器一定要在从服务器之前启动完成,否则挂载文件失败。从而导致共享失败。

 如果从服务器启动时,主服务器还没有启动,那么挂载会失败, 文件会写入本机的/tpc/webapps/docs 里。可以重新启动本机,或者用利用命令手动挂载,挂载后原有的本机无法看到。

可以在手动挂载前先把相关文件

  mv   ./docs/*  ./temp/ ,等挂载后再把文件拷贝回来。 

 

section index top

然后重启mount服务: subo mount -a

 

fstab中存放了与分区有关的重要信息,其中每一行为一个分区记录,每一行又可分为六个部份,下面以/dev/hda7 / ext2 defaults 1 1为例逐个说明:

1. 第一项是您想要mount的储存装置的实体位置,如hdb或/dev/hda6。

2. 第二项就是您想要将其加入至哪个目录位置,如/home或/,这其实就是在安装时提示的挂入点。

3. 第三项就是所谓的local filesystem,其包含了以下格式:如ext、ext2、msdos、iso9660、nfs、swap等,或如ext2,可以参见/prco/filesystems说明。

4. 第四项就是您mount时,所要设定的状态,如ro(只读)或defaults(包括了其它参数如rw、suid、exec、auto、nouser、async),可以参见「mount nfs」。

5. 第五项是提供DUMP功能,在系统DUMP时是否需要BACKUP的标志位,其内定值是0。

6. 第六项是设定此filesystem是否要在开机时做check的动作,除了root的filesystem其必要的check为1之外,其它皆可视需要设定,内定值是0。

 

 

 

 

附录:NFS常用参数如下:
ro 只读访问
rw 读写访问sync 所有数据在请求时写入共享
async nfs在写入数据前可以响应请求
secure nfs通过1024以下的安全TCP/IP端口发送
insecure nfs通过1024以上的端口发送
wdelay 如果多个用户要写入nfs目录,则归组写入(默认)
no_wdelay 如果多个用户要写入nfs目录,则立即写入,当使用async时,无需此设置。
hide 在nfs共享目录中不共享其子目录
no_hide 共享nfs目录的子目录
subtree_check 如果共享/usr/bin之类的子目录时,强制nfs检查父目录的权限(默认)
no_subtree_check 和上面相对,不检查父目录权限
all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
no_all_squash 保留共享文件的UID和GID(默认)
root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)
no_root_squas root用户具有根目录的完全管理访问权限
anonuid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的UID
anongid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的GID

标签:tpc,18.04,05,--,webapps,system6,nfs,docs,ROOT
来源: https://www.cnblogs.com/shadowzhang/p/Ubuntu_NFS_share.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有