Linux 红帽 NFS服务器配置
Linux 红帽 NFS服务器配置
什么是FNS?
NFS是1980年由SUN发展出来在UNIX/Linux系统间实现磁盘文件共享的一种方法,支持应用程序在客户端通过网络存取位于服务器磁盘中数据的一种文件系统协议。
1. 场景
某单位需要配置NFS 服务器,为另外一台运行Oracle 数据库的Linux 服务器提供备份存储。
主机名 | IP地址 | 您实验环境的IP地址 |
nfs1.adc.local | 192.168.1.241 | |
ab1.abc.local | 192.16.1.242 |
2. 实验环境
2.1. 操作系统安装
根据《01 RHEL 安装‐文本最小化安装.docx》进行的最小化安装。
安装了core 及base 两个组。
# cat /etc/redhat-release |
Red Hat Enterprise Linux Server release 6.4 (Santiago)
# uname -a |
Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29
11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
2.2. 服务器基本配置
修改IP 地址。(注意:根据您的实现环境进行配置)
# vi /etc/sysconfig/network-scripts/ifcfg-eth0 |
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.241
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
修改主机名
# vi /etc/sysconfig/network |
NETWORKING=yes
#HOSTNAME=localhost.localdomain
HOSTNAME=nfs1.abc.local
# service network restart |
为了方便实验,将防火墙关闭。
# service iptables stop |
# chkconfig iptables off |
同时关闭 selinux。
# vi /etc/sysconfig/selinux |
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
重新启动以便生效。
# reboot |
3.1. 安装NFS 服务器组件
3.1.1. 方法1:通过RPM 来进行安装
# mkdir /mnt/cdrom |
# mount /dev/cdrom /mnt/cdrom/ |
mount: block device /dev/sr0 is write-protected, mounting read-only
# cd /mnt/cdrom/Packages/ |
# ls nfs* |
nfs4-acl-tools-0.3.3-6.el6.x86_64.rpm
nfs-utils-1.2.3-36.el6.x86_64.rpm
nfs-utils-lib-1.1.5-6.el6.i686.rpm
nfs-utils-lib-1.1.5-6.el6.x86_64.rpm
安装 RPM 包
# rpm -ivh nfs-utils-1.2.3-36.el6.x86_64.rpm |
error: Failed dependencies:
keyutils >= 1.4‐4 is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libevent is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libevent‐1.4.so.2()(64bit) is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libgssglue is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libgssglue.so.1()(64bit) is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libgssglue.so.1(libgssapi_CITI_2)(64bit) is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libnfsidmap.so.0()(64bit) is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libtirpc is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
libtirpc.so.1()(64bit) is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
nfs‐utils‐lib >= 1.1.0‐3 is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
rpcbind is needed by nfs‐utils‐1:1.2.3‐36.el6.x86_64
解决包的依赖性
# rpm -ivh nfs-utils-1.2.3-36.el6.x86_64.rpm \ nfs-utils-lib-1.1.5-6.el6.x86_64.rpm \ rpcbind-0.2.0-11.el6.x86_64.rpm keyutils-1.4-4.el6.x86_64.rpm \ libevent-1.4.13-4.el6.x86_64.rpm \ libgssglue-0.1-11.el6.x86_64.rpm \ libtirpc-0.2.1-5.el6.x86_64.rpm |
Preparing... ########################################### [100%]
5
1:libgssglue ########################################### [ 14%]
2:libtirpc ########################################### [ 29%]
3:rpcbind ########################################### [ 43%]
4:libevent ########################################### [ 57%]
5:keyutils ########################################### [ 71%]
6:nfs‐utils‐lib ########################################### [ 86%]
7:nfs‐utils ########################################### [100%]
3.1.2. 方法2:通过YUM 来进行安装
通过YUM 来解决包的相关性。
# mkdir /mnt/cdrom |
# mount /dev/cdrom /mnt/cdrom/ |
mount: block device /dev/sr0 is write-protected, mounting read-only
# vi /etc/yum.repos.d/rhel-dvd.repo |
创建新的文件,添加如下内容:
[rhel-dvd]
name=Red Hat Enterprise Linux $releasever - $basearch - DVD
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
# yum list | grep nfs |
nfs-utils.x86_64 1:1.2.3-36.el6 rhel-dvd
nfs-utils-lib.i686 1.1.5-6.el6 rhel-dvd
nfs-utils-lib.x86_64 1.1.5-6.el6 rhel-dvd
nfs4-acl-tools.x86_64 0.3.3-6.el6 rhel-dvd
sblim-cmpi-nfsv3.i686 1.1.1-1.el6 rhel-dvd
sblim-cmpi-nfsv3.x86_64 1.1.1-1.el6 rhel-dvd
sblim-cmpi-nfsv4.i686 1.1.0-1.el6 rhel-dvd
sblim-cmpi-nfsv4.x86_64 1.1.0-1.el6 rhel-dvd
# yum -y install nfs-utils |
很方便地就安装完毕了
3.2. 启动NFS 服务
NFS 依赖rpcbind 服务,设置为其自动启动
# chkconfig rpcbind on |
# service rpcbind start |
# service nfs start |
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
在日志文件/var/log/messages 中,会看到如下信息:
rpc.mountd[1797]: Version 1.2.3 starting
kernel: NFSD: Using /var/lib/nfs/v4recovery as the NFSv4 state
recovery directory
kernel: NFSD: starting 90-second grace period
# chkconfig nfs on |
3.3. 配置NFS 服务器
查看当前共享的NFS 信息
# showmount -e localhost |
Export list for localhost: 空白无输出
下面,做一个最基础的测试。创建 export 目录,分配权限
# mkdir /nfsdata |
# ll /nfsdata/ -d |
drwxr-xr-x 2 root root 4096 Jul 31 15:16 /nfsdata/
# chmod a+w /nfsdata/ |
# ll /nfsdata/ -d |
drwxrwxrwx 2 root root 4096 Jul 31 15:16 /nfsdata/
配置 export 文件
# vi /etc/exports |
添加如下内容,注意选项中逗号之间没有空格!
/nfsdata *(rw,root_squash,no_all_squash,sync)
# exportfs -r |
Tip: ‐r Reexport all directories, synchronizing /var/lib/nfs/etab with /etc/exports. This option
removes entries in /var/lib/nfs/etab which have been deleted from /etc/exports, and removes
any entries from the kernel export table which are no longer valid.
7
# showmount -e localhost |
Export list for localhost:
/nfsdata *
自己连接一下自己,测试一下。
# mkdir /mnt/nfs |
# mount 127.0.0.1:/nfsdata/ /mnt/nfs |
查看mount 的信息
# 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)
/dev/sr0 on /mnt/cdrom type iso9660 (ro)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
127.0.0.1:/nfsdata/ on /mnt/nfs type nfs (rw,vers=4,addr=127.0.0.1,clientaddr=127.0.0.1)
检查目录是否可以写入。
# touch /mnt/nfs/testfile1.txt |
# ll /mnt/nfs/testfile1.txt |
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jul 31 15:28 /mnt/nfs/testfile1.txt
3.4. 配置NFS 客户机
NFS 客户机也需要安装nfs‐utils 包。
# showmount -e 192.168.1.241 |
Export list for 192.168.1.241:
/nfsdata *
# mount 192.168.1.241:/nfsdata /mnt/nfs/ |
# ls /mnt/nfs/ -l |
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jul 31 15:28 testfile1.txt
# echo test >> /mnt/nfs/testfile1.txt |
# ls /mnt/nfs/testfile1.txt |
/mnt/nfs/testfile1.txt
# ls /mnt/nfs/testfile1.txt -l |
-rw-r--r-- 1 nfsnobody nfsnobody 5 Jul 31 15:47 /mnt/nfs/testfile1.txt
4. 排错
4.1. 启动NFS 服务时出错
# service nfs start |
Starting NFS services: [ OK ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive;
errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[FAILED]
Starting NFS mountd: [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111
(Connection refused)
rpc.nfsd: unable to set any sockets for nfsd
[FAILED]
原因是 rpcbind 没有启动。
# service rpcbind start |
Starting rpcbind: [ OK ]
# service nfs start |
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
# chkconfig rpcbind on
4.2. 权限出错
# mkdir /mnt/nfs |
# mount 127.0.0.1:/nfsdata/ /mnt/nfs |
查看mount 信息
# mount |
/dev/mapper/VolGroup‐lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
9
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)
/dev/sr0 on /mnt/cdrom type iso9660 (ro)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
127.0.0.1:/nfsdata/ on /mnt/nfs type nfs (rw,vers=4,addr=127.0.0.1,clientaddr=127.0.0.1)
# touch /mnt/nfs/testfile1.txt |
touch: cannot touch `/mnt/nfs/testfile1.txt‘: Permission denied
是文件系统的权限不足,造成的
# ll /nfsdata/ -d |
drwxr-xr-x 2 root root 4096 Jul 31 15:16 /nfsdata/
# chmod a+w /nfsdata/ |
# ll /nfsdata/ -d |
drwxrwxrwx 2 root root 4096 Jul 31 15:16 /nfsdata/
# touch /mnt/nfs/testfile1.txt |
# ll /mnt/nfs/testfile1.txt |
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jul 31 15:28 /mnt/nfs/testfile1.txt
4.3. 客户端程序出错
# showmount |
-bash: showmount: command not found
# mount -t nfs 192.168.1.241:/nfsdata /mnt/nfs |
mount: wrong fs type, bad option, bad superblock on
192.168.1.241:/nfsdata,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so
客户端也需要安装 nfs-utils
# ls /sbin/mount.* |
/sbin/mount.tmpfs
# yum -y install nfs-utils |
安装之后,会增加针对ntfs 文件系统的mount 命令
# ls /sbin/mount.* |
/sbin/mount.nfs /sbin/mount.nfs4 /sbin/mount.tmpfs
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。