您的位置:首页 > 其它

12.NFS搭建配置

2016-04-13 20:29 183 查看
参考博客:http://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html
1.关闭防火墙和SELINUX

$ service iptables status #查看防火墙运行状态
$ service iptables stop #停止防火墙
$ chkconfig iptables off #禁用防火墙
$ vim /etc/selinux/config #修改SELinux配置,重启
SELINUX=disabled
SELINUX禁用后需要重启后生效
$reboot
2.配置网卡,改成静态IP
$ cd /etc/sysconfig/network-scripts/
$ mkdir bak
$ cp ifcfg-* bak #备份网卡配置
$ vim ifcfg-p2p1 #修改网卡配置(每个电脑网卡名估计不同,ifcfg-eth0,ifcfg-em1.....)
内容:

DEVICE="eth0"


BOOTPROTO="static"


DNS1="1.2.4.8"


DNS2="114.114.114.114"


GATEWAY="172.29.1.254"


HOSTNAME="kvm-03-110"


HWADDR="52:54:00:63:43:28"


IPADDR="172.29.1.109"


IPV6INIT="yes"


MTU="1500"


NETMASK="255.255.255.0"


NM_CONTROLLED="yes"


ONBOOT="yes"


TYPE="Ethernet"


UUID="5857d9ac-ff3d-431a-af96-3a2e14b0fb58"


3.安装必须的软件包
$ rpm -qa | grep nfs #检查软件是否安装
$ rpm -qa | grep portmap #检查是否安装portmap;centos6好像改名了叫portreserve
$ rpm -qa | grep portreserve #检查是否安装portreserve

$ 一般系统ISO镜像中就有这些包,默认是安装的,如果没安装可以挂在光盘找到此rpm包
$ mount /dev/cdrom /mnt/cdrom/ #挂在光驱
$ cd /mnt/cdrom/CentOS/
$ rpm -ivh portmap*.rpm
$ rpm -ivh nfs-utils*.rpm
或者yum源安装
$ yum -y install portreserve portmap nfs-utils
4.配置NFS共享目录
$ vim /etc/exports

/opt/mirrors/src/*(rw,async,no_root_squash,no_subtree_check)


NFS命令和配置目录:

/etc/exports NFS服务的主要配置文件
/usr/sbin/exportfs NFS服务的管理命令
/usr/sbin/showmount 客户端的查看命令
/var/lib/nfs/etab 记录NFS分享出来的目录的完整权限设定值
/var/lib/nfs/xtab 记录曾经登录过的客户端信息

$启动NFS和端口映射
$ service portmap start #高版本centos没有portmap
$ service portreserve start #高版本centos没有portmap可以启动这个,名字不同而已
$ service nfs start #启动NFS服务
$ service portreserve status #查看服务状态
$ service nfs status #查看NFS服务状态
配置服务开机自启
$ chkconfig --level 35 portmap on
$ chkconfig --level 35 portreserve on
$ chkconfig --level 35 nfs on
配置hosts主机名
$ vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 hadoop1


::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


$ showmount -e #查看nfs服务共享了哪些目录

用其他机器挂在此共享NFS(挂在的/home/mount必须存在)
$ mount 192.168.10.10:/opt/mirrors/src /home/mount
$ df -h #客户机查看挂在哪些文件系统



$ showmount -a #显示已经与客户端连接上的目录信息
$ showmount -e NFS服务器IP #客户端使用showmount命令查询NFS的共享状态
$ mount |grep nfs #客户端查看nfs挂在目录信息
$ umount /home/mount #客户端卸载挂在目录
开机客户机自动挂在NFS
$ vim /etc/rc.local

#!/bin/sh


#


# This script will be executed *after* all the other init scripts.


# You can put your own initialization stuff in here if you don't


# want to do the full Sys V style init stuff.




touch /var/lock/subsys/local


mount 192.168.10.10:/opt/mirrors/src /home/mount


也可以这样自动开机挂载

格式:<server>:</remote/export> </local/directory> nfs < options> 0 0
$ vim /etc/fstab



开机查看是否自动挂在
$ mount

来自为知笔记(Wiz)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: