NFS配置
来源:互联网 发布:fifa18淘宝 编辑:程序博客网 时间:2024/05/16 01:14
一. CentOS 6 NFS的安装配置
NFS的安装配置:
centos 5 :
yum install nfs-utils portmap
centos 6 :
yum install nfs-utils rpcbind
本节是使用centos 6的配置过程:
设备:两台 centos6 OS 安装的时候选择的是"Basic Server"软件配置包。
首先,让两台机器都安装NFS的 软件包,如下显示的是服务器端:
[root@roothomes /home]$ yum install nfs-utils rpcbind
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Setting up Install Process
Package rpcbind-0.2.0-8.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.2.3-15.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Updating:
nfs-utils x86_64 1:1.2.3-15.el6 base 308 k
Transaction Summary
================================================================================
Install 0 Package(s)
Upgrade 1 Package(s)
Total download size: 308 k
Is this ok [y/N]: y
Downloading Packages:
nfs-utils-1.2.3-15.el6.x86_64.rpm | 308 kB 00:10
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
base/gpgkey | 3.3 kB 00:00 ...
Importing GPG key 0xC105B9DE "CentOS-6 Key (CentOS 6 Official Signing Key) <cent os-6-key@centos.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : 1:nfs-utils-1.2.3-15.el6.x86_64 1/2
Cleanup : 1:nfs-utils-1.2.2-7.el6.x86_64 2/2
Updated:
nfs-utils.x86_64 1:1.2.3-15.el6
Complete!
[root@roothomes /home]$
服务器端:
###(建立挂载的目录,并且挂载目录。)
[root@roothomes /etc]$ mkdir /opt/centos6
[root@roothomes /etc]$ cd /opt/centos6/
[root@roothomes /opt/centos6]$ mkdir thisISnfsFile
[root@roothomes /opt/centos6]$ ls
thisISnfsFile
[root@roothomes /etc]$ vi /etc/exports
[root@roothomes /opt/centos6]$ cat /etc/exports
/opt/centos6 192.168.1.0/24(ro,no_root_squash)
### 备注:/opt/centos6表示nfs共享的目录 192.168.1.0-192.168.1.254区间的IP可以访问,访问权限是自读,root 用户
###(启动对应的服务)
[root@roothomes /opt/centos6]$ chkconfig nfs on
[root@roothomes /opt/centos6]$ /etc/init.d/rpcbind start
[root@roothomes /opt/centos6]$ /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@roothomes /opt/centos6]$ service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
客户端:
[root@roothomes /home]$ yum install nfs-utils rpcbind
安装完毕!
[root@vmBS00 ~]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
###查看是否能访问nfs服务
[root@vmBS00 ~]# showmount -e 192.168.1.75
Export list for 192.168.1.75:
/opt/centos6 192.168.1.0/24
[root@vmBS00 ~]# mkdir /opt/centos6
[root@vmBS00 ~]# mount -t nfs 192.168.1.75:/opt/centos6/ /opt/centos6/
[root@vmBS00 ~]# ls /opt/centos6/
thisISnfsFile
###配置开机自动挂载
[root@vmBS00 ~]# vi /etc/fstab
### 添加 #192.168.1.75:/opt/centos6/ /opt/centos6/ nfs nodev,ro,rsize=32768,wsize=32768 0 0
[root@vmBS00 ~]# init 6
[root@vmBS00 ~]#
login as: root
root@192.168.1.116's password:
Last login: Mon Mar 5 17:29:04 2012 from 192.168.1.23
[root@vmBS00 ~]# ls /opt/centos6/
thisISnfsFile
[root@vmBS00 ~]#
二. Ubuntu NFS配置
NFS可以完成共享的任务,是网络运行的基础。那么,这里我们就来讲解一下Linux NFS配置的相关知识。那么我们是知道的,对于NFS(Network File System, 网络文件系统)可以通过网络将分享不同主机(不同的OS)的目录——可以通过NFS挂载远程主机的目录, 访问该目录就像访问本地目录一样!一般而言, 使用nfs能够方便地使各unix-like系统之间实现共享. 但如果需要在unix-like和windows系统之间共享, 就得使用samba了!Linux NFS运行在SUN的RPC(Remote Procedure Call, 远程过程调用)基础上, RPC定义了一种与系统无关的方法来实现进程间通信. 由此,NFS Server也可以看作是RPC server.
正因为NFS是一个RPC服务程序, 所以在使用它之前, 先要映射好端口——通过portmap设定. 比如: 某个NFS client发起NFS服务请求时, 它需要先得到一个端口(port). 所以它先通过portmap得到port number. (不仅NFS, 所有的RPC服务程序启动之前, 都需要设定好portmap)
与Linux NFS相关的几个文件, 命令
1, /etc/exports
对NFS卷的访问是由exports来批准, 它枚举了若干有权访问NFS服务器上文件系统的主机名.
2, /sbin/exportfs
维护NFS的资源共享. 可以通过它重新设定 /etc/exports 的共享目录, 卸载NFS Server共享的目录或者重新共享等.
3, /usr/sbin/showmount
用在NFS Server 端,而 showmount 则主要用在 Client 端. showmount 可以用來查看NFS共享的目录资源.
4, /var/lib/nfs/xtab
NFS的记录文档: 通过它可以查看有哪些Client 连接到NFS主机的记录.
下面这几个并不直接负责NFS, 实际上它们负责所有的RPC
5, /etc/default/portmap
实际上, portmap负责映射所有的RPC服务端口, 它的内容非常非常之简单(后面详述)
6, /etc/hosts.deny
设定拒绝portmap服务的主机
7, /etc/hosts.allow
设定允许portmap服务的主机
安装Linux NFS
Debian/Ubuntu上默认是没有安装NFS服务器的,首先要安装NFS服务程序:
$ sudo apt-get install nfs-kernel-server
(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap)
这样,宿主机就相当于NFS Server.
同样地,目标系统作为NFS的客户端,需要安装NFS客户端程序.如果是Debian/Ubuntu系统,则需要安装nfs-common.
$ sudo apt-get install nfs-commmon
nfs-common和nfs-kernel-server都依赖于portmap!
配置Linux NFS
配置portmap
方法1: 编辑/etc/default/portmap, 将 -i 127.0.0.1 去掉.
方法2: $ sudo dpkg-reconfigure portmap , 对Should portmap be bound to the loopback address? 选N.
配置/etc/hosts.deny
(禁止任何host(主机)能和你的NFS服务器进行NFS连接),加入:
- ###NFSDAEMONS
- portmap:ALL
- lockd:ALL
- mountd:ALL
- rquotad:ALL
- statd:ALL
配置/etc/hosts.allow
允许那些你想要的主机和你的NFS服务器建立连接.下列步骤将允许任何IP地址以192.168.2开头的主机(连 接到NFS服务器上),也可以指定特定的IP地址.参看man页 hosts_access(5), hosts_options(5).加入:
- ###NFSDAEMONS
- portmap: 192.168.2.
- lockd: 192.168.2.
- rquotad: 192.168.2.
- mountd: 192.168.2.
- statd: 192.168.2.
/etc/hosts.deny 和 /etc/hosts.allow 设置对portmap的访问. 采用这两个配置文件有点类似"mask"的意思. 现在/etc/hosts.deny中禁止所有用户对portmap的访问. 再在/etc/hosts.allow 中允许某些用户对portmap的访问.
运行 $ sudo /etc/init.d/portmap restart 重启portmap daemon.
配置/etc/exports
Linux NFS挂载目录及权限由/etc/exports文件定义
比如我要将将我的home目录中的/home/zp/share目录让192.168.2.*的IP共享, 则在该文件末尾添加下列语句:
/home/zp/share 192.168.2.*(rw,sync,no_root_squash)
或者:/home/zp/share 192.168.2.0/24(rw,sync,no_root_squash)
192.168.2.* 网段内的NFS客户端能够共享NFS服务器/home/zp/share目录内容.且有读,写权限, 并且该用户进入/home/zp/share目录后的身份为root。最好加上sync, 否则 $ sudo exportfs -r 时会给出警告, sync是NFS的默认选项.
(运行 $ showmount -e 查看NFS server的export list.
若更改了/etc/exports, 运行 $ sudo exportfs -r 更新
运行 $ sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务)
/etc/exports实际上就是nfs服务器的核心配置文件了.
测试Linux NFS
可以尝试一下挂载本地磁盘(假设本地主机IP地址为:192.128.2.1,将/home/zp/share挂载到/mnt)
$ sudo mount 192.168.2.1:/home/zp/share /mnt
运行 $ df 看看结果
$ sudo umount /mnt
注意被拷贝文件的读写权限!
另外, 可以使用一定的参数:
使用加参数的办法:mount -o nolock,rsize=1024,wsize=1024,timeo=15 192.168.2.130:/tmp/ /tmp/
- NFS配置
- NFS配置
- NFS配置
- NFS配置
- NFS配置
- nfs配置
- NFS 配置
- 配置NFS
- 配置NFS
- nfs 配置
- nfs 配置
- NFS配置
- nfs 配置
- nfs配置
- 配置NFS
- NFS 配置
- NFS配置
- NFS配置
- 用Python开始机器学习(5:文本特征抽取与向量化)
- c# DataGridView绑定DataTable数据源并指定对应
- 青春不是过渡
- 【c++程序】运算符的重载
- 第20章 重定向与负载均衡
- NFS配置
- 基于DSP的彩色TFT-LCD数字图像显示技术研究
- Android事件传递机制
- 第21章 日志记录与使用情况跟踪
- GLFW入门学习
- php常用方法
- OC第十课
- armeabi与armeabi-v7a
- [SHOI2014]神奇化合物解题报告