【Linux网络文件系统--Network File System搭建】

一、NFS简介

NFS是网络文件系统(Network File System)的简称,是分布式计算机系统的一个组成部分,可实现在异构网络上共享和装配远程文件系统。

1、设置Linux系统之间的文件共享(Linux与Windows中间文件共享采用SAMBA服务);

2、NFS只是一种文件系统,本身没有传输功能,是基于RPC协议实现的,才能达到两个Linux系统之间的文件目录共享;

3、NFS为C/S架构;

 

二、NFS应用

1、我的服务器磁盘满了,而我又不能停机添加硬盘或者更换容量更大的服务器,硬盘热插拔服务器除外。

2、配置SSH免密码登录,需要把两台机器的SSH加密串copy到authorzied_keys文件中,例如配置hadoop应用,hadoop允许新添加DataNode节点,如果没有NFS那么各个节点配置SSH免密码登录,两三个节点还好说,万一有一千个节点,今天坏掉一个节点,又新加一个,明天又扩容一个节点,配置SSH免密码真是牵一发而动全身,有了NFS各个节点可以把加密串配置到NFS共享目录中

 

三、安装软件

    在192.168.1.104上共享一个目录给其他主机使用,因此1.104作为服务器端,需要检查服务器端软件安装情况,并完成软件安装。

1、检查软件是否安装

[root@bogon ~]# rpm -q nfs-utils portmap

nfs-utils-1.2.3-36.el6.i686

package portmap is not installed

 

2、下载安装portmap

[root@bogon ~]# wget ftp://ftp.pbone.net/mirror/archive.download.redhat.com/pub/redhat/linux/6.1/en/os/i386/RedHat/RPMS/portmap-4.0-17.i386.rpm

Connecting to ftp.pbone.net|85.14.85.4|:21... connected.

Logging in as anonymous ... Logged in!

==> SYST ... done.    ==> PWD ... done.

==> TYPE I ... done.  ==> CWD (1) /mirror/archive.download.redhat.com/pub/redhat/linux/6.1/en/os/i386/RedHat/RPMS ... done.

==> SIZE portmap-4.0-17.i386.rpm ... 30245

==> PASV ... done.    ==> RETR portmap-4.0-17.i386.rpm ... done.

Length: 30245 (30K) (unauthoritative)

 

100%[======================================>] 30,245      59.1K/s   in 0.5s    

[root@bogon ~]# ls

anaconda-ks.cfg  install.log  install.log.syslog  portmap-4.0-17.i386.rpm

[root@bogon ~]# rpm -ivh portmap-4.0-17.i386.rpm 

Preparing...                ########################################### [100%]

   1:portmap                ########################################### [100%]

[root@bogon ~]#  service portmap start

Starting portmapper: portmap: relocation error: portmap: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference

                                                           [FAILED]

[root@bogon ~]# yum install libc.so.6

Loaded plugins: fastestmirror, security

Loading mirror speeds from cached hostfile

 * base: mirrors.163.com

 * extras: mirrors.163.com

 * updates: mirrors.163.com

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package glibc.i686 0:2.12-1.107.el6 will be updated

--> Processing Dependency: glibc = 2.12-1.107.el6 for package: glibc-common-2.12-1.107.el6.i686

---> Package glibc.i686 0:2.12-1.166.el6_7.7 will be an update

--> Running transaction check

---> Package glibc-common.i686 0:2.12-1.107.el6 will be updated

---> Package glibc-common.i686 0:2.12-1.166.el6_7.7 will be an update

--> Finished Dependency Resolution

Complete!

[root@bogon ~]#  service portmap start

Starting portmapper: portmap: relocation error: portmap: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference

                                                           [FAILED]

[root@bogon ~]# yum install libc.so.6 libnsl.so.1

Package glibc-2.12-1.166.el6_7.7.i686 already installed and latest version

Package glibc-2.12-1.166.el6_7.7.i686 already installed and latest version

Package glibc-2.12-1.166.el6_7.7.i686 already installed and latest version

Nothing to do

[root@bogon ~]#  service portmap start

Starting portmapper: portmap: relocation error: portmap: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference

                                                           [FAILED]

[root@bogon ~]# yum install glibc

Loaded plugins: fastestmirror, security

Complete!

[root@bogon ~]# 

[root@bogon ~]#  service portmap start

Starting portmapper: portmap: relocation error: portmap: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference

                                                           [FAILED]

[root@bogon ~]# reboot

 

Broadcast message from root@bogon

        (/dev/pts/0) at 4:04 ...

 

The system is going down for reboot NOW!

[root@bogon ~]# Last login: Fri Feb 26 03:46:42 2016 from 192.168.1.103

[root@bogon ~]# wget ftp://carroll.aset.psu.edu/pub/.mirrors/1/rh-mirror.redhat.com/redhat/linux/5.0/en/os/i386/RedHat/RPMS/portmap-4.0-7.i386.rpm

==> SYST ... done.    ==> PWD ... done.

==> TYPE I ... done.  ==> CWD (1) /mirror/archive.download.redhat.com/pub/redhat/linux/5.0/en/os/i386/RedHat/RPMS ... done.

==> SIZE portmap-4.0-7.i386.rpm ... 23064

==> PASV ... done.    ==> RETR portmap-4.0-7.i386.rpm ... done.

Length: 23064 (23K) (unauthoritative)

 

100%[=====================================>] 23,064      54.6K/s   in 0.4s    

2016-02-26 04:07:42 (54.6 KB/s) - portmap-4.0-7.i386.rpm saved [23064]

[root@bogon ~]# clear

[root@bogon ~]# ls

anaconda-ks.cfg  install.log  install.log.syslog  portmap-4.0-17.i386.rpm  portmap-4.0-7.i386.rpm

[root@bogon ~]# rpm -q portmap

portmap-4.0-17.i386

[root@bogon ~]# rpm -e portmap-4.0-17.i386

[root@bogon ~]# rpm -ivh portmap-4.0-7.i386.rpm

Preparing...                ########################################### [100%]

   1:portmap                ########################################### [100%]

[root@bogon ~]#  service portmap start

Starting portmapper:                                       [  OK  ]

[root@bogon ~]# 

[root@bogon ~]# rpm -q nfs-utils portmap

nfs-utils-1.2.3-64.el6.i686

portmap-4.0-7.i386

[root@bogon ~]#  service nfs status

rpc.svcgssd is stopped

rpc.mountd is stopped

nfsd is stopped

rpc.rquotad is stopped

[root@bogon ~]#  service nfs start

Starting NFS services:                                     [  OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

[root@bogon ~]#                                            [  OK  ]

 

四、服务器端配置

把1.104的/opt/share_nfs共享给1.105机器,配置如下:

root@bogon ~]# mkdir /opt/share_nfs

[root@bogon ~]# vi /etc/exports

/opt/share_nfs 192.168.1.105(rw)

[root@bogon ~]# service portmap restart

Stopping portmap services:                                 [FAILED]

Starting portmapper:                                       [  OK  ]

[root@bogon ~]# service nfs restart

Shutting down NFS daemon:                                  [  OK  ]

Shutting down NFS mountd:                                  [  OK  ]

Shutting down NFS quotas:                                  [  OK  ]

Starting NFS services:                                     [  OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

[root@bogon ~]# exportfs                                   [  OK  ]

/opt/share_nfs  192.168.1.105

[root@bogon ~]# 

[root@bogon ~]# service portmap restart

Stopping portmap services:                                 [FAILED]

Starting portmapper:                                       [  OK  ]

[root@bogon ~]# service nfs restart

Shutting down NFS daemon:                                  [  OK  ]

Shutting down NFS mountd:                                  [  OK  ]

Shutting down NFS quotas:                                  [  OK  ]

Starting NFS services:                                     [  OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

[root@bogon ~]# exportfs                                   [  OK  ]

/opt/share_nfs  192.168.1.105

 

五、客户端配置以及验证

[root@bogon ~]#  showmount -e 192.168.1.104

Export list for 192.168.1.104:

/opt/share_nfs 192.168.1.105

[root@bogon ~]# cd /m

media/ misc/  mnt/   

[root@bogon ~]# mount 192.168.1.104:/opt/share_nfs  /mnt/ 

[root@bogon ~]# echo "gaojingsong write nfslog in 1.105" >/mnt/test.log

-bash: /mnt/test.log: Permission denied(解决方案,修改服务器目录权限)

[root@bogon ~]# echo "gaojingsong write nfslog in 1.105" >/mnt/test.log

[root@bogon ~]# cat /mnt/test.log

gaojingsong write nfslog in 1.105

[root@bogon ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:10:37:75  

 

          inet addr:192.168.1.105  Bcast:192.168.1.255  Mask:255.255.255.0

 

 

错误解决方案:

1、客服端Permission denied(解决方案,修改1.104服务器目录权限)

[root@bogon ~]# chmod 777 -R  /opt/share_nfs

[root@bogon ~]# cd /opt/share_nfs

[root@bogon share_nfs]# ls -l

total 4

-rw-r--r--. 1 nfsnobody nfsnobody 34 Feb 26 04:21 test.log

[root@bogon share_nfs]# cat test.log 

gaojingsong write nfslog in 1.105

[root@bogon share_nfs]# hostname -i

hostname: Unknown host

[root@bogon share_nfs]# ifconfig

eth1      Link encap:Ethernet  HWaddr 00:0C:29:2B:F8:93  

          inet addr:192.168.1.104  Bcast:192.168.1.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe2b:f893/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:956 errors:0 dropped:0 overruns:0 frame:0

          TX packets:745 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:127238 (124.2 KiB)  TX bytes:91020 (88.8 KiB)

          Interrupt:19 Base address:0x2000 

2、服务器端安装portmap 软件后重启报错

[root@bogon ~]#  service portmap start

Starting portmapper: portmap: relocation error: portmap: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference[FAILED]

解决方案:检查portmap 是否对应支持相应的操作系统

你可能感兴趣的:(【Linux网络文件系统--Network File System搭建】)