【背景】
需要去研究NFS功能。
在一个远程Ubuntu系统的服务器上面尝试开通NFS==Network File System,然后使得别的地方可以访问远程服务器的文件。
【折腾过程】
1.通过SSH2登陆服务器,然后发现,貌似已经开通了NFS了?
root@chantyou:~# nfsiostat Linux 3.10.0-123.9.3.el7.x86_64 (chantyou.com) 07/22/2015 _x86_64_ (1 CPU) Filesystem: rkB_nor/s wkB_nor/s rkB_dir/s wkB_dir/s rkB_svr/s wkB_svr/s ops/s rops/s wops/s root@chantyou:~#
2.自己先去搜了搜nfs:
root@iZ23lqgttauZ:~# uname -a Linux iZ23lqgttauZ 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux root@iZ23lqgttauZ:~# apt-get search nfs E: Invalid operation search root@iZ23lqgttauZ:~# apt apt apt-extracttemplates aptitude-create-state-bundle apt-mark apt-cache apt-ftparchive aptitude-curses apt-sortpkgs apt-cdrom apt-get aptitude-run-state-bundle apt-config aptitude apt-key root@iZ23lqgttauZ:~# apt- apt-cache apt-config apt-ftparchive apt-key apt-sortpkgs apt-cdrom apt-extracttemplates apt-get apt-mark root@iZ23lqgttauZ:~# apt-cache search nfs backuppc - high-performance, enterprise-grade system for backing up PCs initramfs-tools - tools for generating an initramfs libfile-fcntllock-perl - Perl module for file locking with fcntl(2) liblockfile1 - NFS-safe locking library libnfsidmap-dev - header files and docs for libnfsidmap libnfsidmap2 - NFS idmapping library libtirpc-dev - transport-independent RPC library - development files libtirpc1 - transport-independent RPC library manpages - Manual pages about using a GNU/Linux system nbd-client - Network Block Device protocol - client nbd-server - Network Block Device protocol - server nfs-common - NFS support files common to client and server nfs-kernel-server - support for NFS kernel server quota - disk quota management tools sysstat - system performance tools for Linux tcpdump - command-line network traffic analyzer texlive-latex-base - TeX Live: LaTeX fundamental packages texlive-latex-extra - TeX Live: LaTeX additional packages bootcd - run your system from cd without need for disks collectd-core - statistics collection and monitoring daemon (core system) collectl - Utility to collect Linux performance data daemonfs - real time monitoring software diod - I/O forwarding server for 9P dracut - A new initramfs infrastructure dracut-network - A new initramfs infrastucture dsniff - Various tools to sniff network traffic for cleartext insecurities fai-nfsroot - Fully Automatic Installation nfsroot package fam - File Alteration Monitor gfarm-client - Gfarm file system clients gfarm-doc - Gfarm file system documentation gfmd - Gfarm file system metadata server gfsd - Gfarm file system daemon gnats-user - problem report management system - client tools gnome-system-tools - Cross-platform configuration utilities for GNOME goto-fai - Scripts to integrate GOto with FAI hydra - very fast network logon cracker hydra-gtk - very fast network logon cracker - GTK+ based GUI jftp - Java GUI client for FTP, SMB, SFTP and NFS kdenetwork-filesharing - network filesharing configuration module libfile-nfslock-perl - perl module to do NFS (or not) locking libgfarm-dev - Gfarm file system development files libgfarm1 - Gfarm file system runtime library libio-aio-perl - asynchronous IO module for Perl libnfs-dev - NFS client library (development files) libnfs1 - NFS client library (shared library) libsys-gamin-perl - Perl interface to Gamin (File Access Monitor implementation) libyanfs-java - Yet Another NFS - a Java NFS library manpages-de - German manpages manpages-fr - French version of the manual pages about using GNU/Linux manpages-pl - Polish man pages manpages-pt - Portuguese Versions of the Manual Pages manpages-tr - Turkish version of the manual pages mb2md - Converting Mbox mailboxes to Maildir format mhddfs - file system for unifying several mount points into one nagios-plugins-contrib - Plugins for nagios compatible monitoring systems nfs4-acl-tools - Commandline and GUI ACL utilities for the NFSv4 client nfswatch - Program to monitor NFS traffic for the console nmon - performance monitoring tool for Linux petitboot - ncurses version of petitboot, a kexec based bootloader petitboot-twin - Twin GUI version of petitboot, a kexec based bootloader plptools - Access EPOC device (Psion PDA) over a serial link portsentry - Portscan detection daemon python-django-localeurl - Django application allows the language be set in the URL python-flufl.lock - NFS-safe file-based lock with timeouts (Python 2) python-flufl.lock-doc - NFS-safe file-based lock with timeouts (common documentation) python-reconfigure - simple config file management library python3-flufl.lock - NFS-safe file-based lock with timeouts (Python 3) ruby-lockfile - create NFS-safe lockfiles sbrsh - Scratchbox Remote Shell client sbrshd - Scratchbox Remote Shell daemon slack - configuration management program for lazy admins texlive-plain-extra - TeX Live: Plain TeX packages tiger-otheros - Scripts to run Tiger in other operating systems udpcast - multicast file transfer tool unburden-home-dir - Remove or move cache files automatically from user's home unionfs-fuse - Fuse implementation of unionfs vbackup - modular backup utility root@iZ23lqgttauZ:~#
3.搜:
ubuntu nfs
参考:
ubuntu 12.04 nfs-server/client安装配置-liujunwei1234-ChinaUnix博客
讲解安装Ubuntu nfs配置系统 – 51CTO.COM
基本明白了一点:
想要作为NFS服务器,上面是安装nfs的server
而别的电脑,别的服务器,要访问NFS服务器的话,则是作为NFS的client,所以要去安装:nfs的client
4.此处,先去给NFS的server去安装server:
root@iZ23lqgttauZ:~# apt-get install nfs-kernel-server Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libevent-2.0-5 libgssglue1 libnfsidmap2 libtirpc1 nfs-common rpcbind Suggested packages: open-iscsi watchdog The following NEW packages will be installed: libevent-2.0-5 libgssglue1 libnfsidmap2 libtirpc1 nfs-common nfs-kernel-server rpcbind 0 upgraded, 7 newly installed, 0 to remove and 53 not upgraded. Need to get 553 kB of archives. After this operation, 2,218 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main libevent-2.0-5 amd64 2.0.21-stable-1ubuntu1.14.04.1 [126 kB] Get:2 http://mirrors.aliyun.com/ubuntu/ trusty/main libgssglue1 amd64 0.4-2ubuntu1 [19.7 kB] Get:3 http://mirrors.aliyun.com/ubuntu/ trusty/main libnfsidmap2 amd64 0.25-5 [32.2 kB] Get:4 http://mirrors.aliyun.com/ubuntu/ trusty/main libtirpc1 amd64 0.2.2-5ubuntu2 [71.3 kB] Get:5 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main rpcbind amd64 0.2.1-2ubuntu2.1 [37.0 kB] Get:6 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main nfs-common amd64 1:1.2.8-6ubuntu1.1 [182 kB] Get:7 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main nfs-kernel-server amd64 1:1.2.8-6ubuntu1.1 [85.6 kB] Fetched 553 kB in 0s (3,747 kB/s) Selecting previously unselected package libevent-2.0-5:amd64. (Reading database ... 68166 files and directories currently installed.) Preparing to unpack .../libevent-2.0-5_2.0.21-stable-1ubuntu1.14.04.1_amd64.deb ... Unpacking libevent-2.0-5:amd64 (2.0.21-stable-1ubuntu1.14.04.1) ... Selecting previously unselected package libgssglue1:amd64. Preparing to unpack .../libgssglue1_0.4-2ubuntu1_amd64.deb ... Unpacking libgssglue1:amd64 (0.4-2ubuntu1) ... Selecting previously unselected package libnfsidmap2:amd64. Preparing to unpack .../libnfsidmap2_0.25-5_amd64.deb ... Unpacking libnfsidmap2:amd64 (0.25-5) ... Selecting previously unselected package libtirpc1:amd64. Preparing to unpack .../libtirpc1_0.2.2-5ubuntu2_amd64.deb ... Unpacking libtirpc1:amd64 (0.2.2-5ubuntu2) ... Selecting previously unselected package rpcbind. Preparing to unpack .../rpcbind_0.2.1-2ubuntu2.1_amd64.deb ... Unpacking rpcbind (0.2.1-2ubuntu2.1) ... Selecting previously unselected package nfs-common. Preparing to unpack .../nfs-common_1%3a1.2.8-6ubuntu1.1_amd64.deb ... Unpacking nfs-common (1:1.2.8-6ubuntu1.1) ... Selecting previously unselected package nfs-kernel-server. Preparing to unpack .../nfs-kernel-server_1%3a1.2.8-6ubuntu1.1_amd64.deb ... Unpacking nfs-kernel-server (1:1.2.8-6ubuntu1.1) ... Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Processing triggers for ureadahead (0.100.0-16) ... Setting up libevent-2.0-5:amd64 (2.0.21-stable-1ubuntu1.14.04.1) ... Setting up libgssglue1:amd64 (0.4-2ubuntu1) ... Setting up libnfsidmap2:amd64 (0.25-5) ... Setting up libtirpc1:amd64 (0.2.2-5ubuntu2) ... Setting up rpcbind (0.2.1-2ubuntu2.1) ... Removing any system startup links for /etc/init.d/rpcbind ... rpcbind start/running, process 31795 Processing triggers for ureadahead (0.100.0-16) ... Setting up nfs-common (1:1.2.8-6ubuntu1.1) ... Creating config file /etc/idmapd.conf with new version Creating config file /etc/default/nfs-common with new version Adding system user `statd' (UID 106) ... Adding new user `statd' (UID 106) with group `nogroup' ... Not creating home directory `/var/lib/nfs'. statd start/running, process 32032 gssd stop/pre-start, process 32066 idmapd start/running, process 32116 Processing triggers for ureadahead (0.100.0-16) ... Setting up nfs-kernel-server (1:1.2.8-6ubuntu1.1) ... Creating config file /etc/exports with new version Creating config file /etc/default/nfs-kernel-server with new version * Not starting NFS kernel daemon: no exports. Processing triggers for libc-bin (2.19-0ubuntu6.6) ... Processing triggers for ureadahead (0.100.0-16) ... root@iZ23lqgttauZ:~#
看到有:
Not starting NFS kernel daemon: no exports.
所以去搞懂为何:
【已解决】安装NFS服务器nfs-kernel-server后启动失败:Not starting NFS kernel daemon: no exports
继续折腾。
5.创建配置文件:/etc/exports
发现已经存在过了:
root@iZ23lqgttauZ:~# vi /etc/exports # /etc/exports: the access control list for filesystems which may be exported # to NFS clients. See exports(5). # # Example for NFSv2 and NFSv3: # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) # # Example for NFSv4: # /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check) # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check) # ~
6.继续编辑:
先去添加最简单的配置:
/home/share/image *(rw,sync)
等正常可以工作后,再去添加其他配置。
然后重启nfs:
root@iZ23lqgttauZ:image# service nfs status nfs: unrecognized service root@iZ23lqgttauZ:image# service --status-all [ + ] aegis [ - ] agentwatch [ ? ] aliyun-rdate [ + ] apache2 [ + ] apparmor [ ? ] console-setup [ + ] cron [ - ] dbus [ ? ] dns-clean [ + ] friendly-recovery [ - ] grub-common [ ? ] irqbalance [ ? ] killprocs [ ? ] kmod [ ? ] mysql [ ? ] networking [ - ] nfs-kernel-server [ + ] nscd [ + ] ntp [ ? ] ondemand [ ? ] pppd-dns [ - ] procps [ ? ] rc.local [ + ] resolvconf [ + ] rpcbind [ - ] rsync [ + ] rsyslog [ ? ] sendsigs [ - ] ssh [ - ] sudo [ - ] sysstat [ + ] udev [ ? ] umountfs [ ? ] umountnfs.sh [ ? ] umountroot [ - ] urandom root@iZ23lqgttauZ:image# service nfs-kernel-server status nfsd not running root@iZ23lqgttauZ:image# service nfs-kernel-server restart * Stopping NFS kernel daemon [ OK ] * Unexporting directories for NFS kernel daemon... [ OK ] * Exporting directories for NFS kernel daemon...
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/home/share/image". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x [ OK ] * Starting NFS kernel daemon [ OK ] root@iZ23lqgttauZ:image# service nfs-kernel-server status nfsd running root@iZ23lqgttauZ:image#
7.然后自己先上传了点图片,用于后续测试nfs时用:
root@iZ23lqgttauZ:image# ll total 248 drwxr-xr-x 2 root root 4096 Jul 23 15:16 ./ drwxr-xr-x 3 root root 4096 Jul 22 14:42 ../ -rw-r--r-- 1 root root 70545 May 28 2013 mmexport1369703131812.jpg -rw-r--r-- 1 root root 82168 Sep 12 2013 mmexport1378988706739.jpeg -rw-r--r-- 1 root root 85510 Nov 18 2013 p_large_0fOT_43d9000068f01263.jpg root@iZ23lqgttauZ:image# pwd /home/share/image
导出后重启:
root@iZ23lqgttauZ:image# exportfs -a exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/home/share/image". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x root@iZ23lqgttauZ:image# service nfsd restart nfsd: unrecognized service root@iZ23lqgttauZ:image# service nfs-kernel-server restart * Stopping NFS kernel daemon [ OK ] * Unexporting directories for NFS kernel daemon... [ OK ] * Exporting directories for NFS kernel daemon... exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/home/share/image". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x [ OK ] * Starting NFS kernel daemon [ OK ] root@iZ23lqgttauZ:image#
8.然后再去另一个服务器上,作为NFS的client,去安装NFS的客户端:
去安装nfs-utils:
root@chantyou:~# yum search nfs Loaded plugins: langpacks ========================================================= N/S matched: nfs ========================================================= nfs4-acl-tools.x86_64 : The nfs4 ACL tools sblim-cmpi-nfsv3.i686 : SBLIM nfsv3 instrumentation libnfsidmap.i686 : NFSv4 User and Group ID Mapping Library nfs-ganesha.x86_64 : NFS-Ganesha is a NFS Server running in user space nfs-utils.x86_64 : NFS utilities and supporting clients and daemons for the kernel NFS server nfsometer.noarch : NFS Performance Framework Tool perl-File-NFSLock.noarch : Perl module to do NFS (or not) locking sblim-cmpi-nfsv4.i686 : SBLIM nfsv4 instrumentation libnfsidmap.x86_64 : NFSv4 User and Group ID Mapping Library libnfsidmap-devel.i686 : Development files for the libnfsidmap library libnfsidmap-devel.x86_64 : Development files for the libnfsidmap library nfs-ganesha-ceph.x86_64 : The NFS-GANESHA's CEPH FSAL nfs-ganesha-gluster.x86_64 : The NFS-GANESHA's GLUSTER FSAL nfs-ganesha-nullfs.x86_64 : The NFS-GANESHA's NULLFS Stackable FSAL nfs-ganesha-proxy.x86_64 : The NFS-GANESHA's PROXY FSAL nfs-ganesha-utils.x86_64 : The NFS-GANESHA's util scripts nfs-ganesha-vfs.x86_64 : The NFS-GANESHA's VFS FSAL nfs-ganesha-xfs.x86_64 : The NFS-GANESHA's XFS FSAL nfstest.noarch : NFS Testing Tool sblim-cmpi-nfsv3.x86_64 : SBLIM nfsv3 instrumentation sblim-cmpi-nfsv3-test.x86_64 : SBLIM Nfsv3 Instrumentation Testcases sblim-cmpi-nfsv4.x86_64 : SBLIM nfsv4 instrumentation sblim-cmpi-nfsv4-test.x86_64 : SBLIM Nfsv4 Instrumentation Testcases texlive-mfnfss-doc.noarch : Documentation for mfnfss texlive-psnfss-doc.noarch : Documentation for psnfss fedfs-utils-devel.i686 : Development files for the FedFS nfs-plugin fedfs-utils-devel.x86_64 : Development files for the FedFS nfs-plugin fedfs-utils-lib.i686 : The FedFS nfs-plugin run-time library fedfs-utils-lib.x86_64 : The FedFS nfs-plugin run-time library nfs-ganesha-mount-9P.x86_64 : a 9p mount helper texlive-mfnfss.noarch : Packages to typeset oldgerman and pandora fonts in LaTeX texlive-psnfss.noarch : Font support for common PostScript fonts Name and summary matches only, use "search all" for everything. root@chantyou:~# yum install nfs-utils Loaded plugins: langpacks base | 3.6 kB 00:00:00 epel | 4.4 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/2): updates/7/x86_64/primary_db | 2.5 MB 00:00:00 (2/2): epel/x86_64/primary_db | 3.7 MB 00:00:00 (1/2): epel/x86_64/updateinfo | 441 kB 00:00:00 (2/2): epel/x86_64/pkgtags | 1.6 MB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package nfs-utils.x86_64 1:1.3.0-0.8.el7 will be installed --> Processing Dependency: libtirpc >= 0.2.3-1 for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: gssproxy >= 0.3.0-0 for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: rpcbind for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: libnfsidmap for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: libevent for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: keyutils for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Processing Dependency: libevent-2.0.so.5()(64bit) for package: 1:nfs-utils-1.3.0-0.8.el7.x86_64 --> Running transaction check ---> Package gssproxy.x86_64 0:0.3.0-10.el7 will be installed --> Processing Dependency: libverto-tevent for package: gssproxy-0.3.0-10.el7.x86_64 --> Processing Dependency: libini_config.so.3(INI_CONFIG_1.1.0)(64bit) for package: gssproxy-0.3.0-10.el7.x86_64 --> Processing Dependency: libref_array.so.1()(64bit) for package: gssproxy-0.3.0-10.el7.x86_64 --> Processing Dependency: libini_config.so.3()(64bit) for package: gssproxy-0.3.0-10.el7.x86_64 --> Processing Dependency: libcollection.so.2()(64bit) for package: gssproxy-0.3.0-10.el7.x86_64 --> Processing Dependency: libbasicobjects.so.0()(64bit) for package: gssproxy-0.3.0-10.el7.x86_64 ---> Package keyutils.x86_64 0:1.5.8-3.el7 will be installed ---> Package libevent.x86_64 0:2.0.21-4.el7 will be installed ---> Package libnfsidmap.x86_64 0:0.25-11.el7 will be installed ---> Package libtirpc.x86_64 0:0.2.4-0.5.el7 will be installed ---> Package rpcbind.x86_64 0:0.2.0-26.el7 will be installed --> Running transaction check ---> Package libbasicobjects.x86_64 0:0.1.1-24.el7 will be installed ---> Package libcollection.x86_64 0:0.6.2-24.el7 will be installed ---> Package libini_config.x86_64 0:1.1.0-24.el7 will be installed --> Processing Dependency: libpath_utils.so.1(PATH_UTILS_0.2.1)(64bit) for package: libini_config-1.1.0-24.el7.x86_64 --> Processing Dependency: libpath_utils.so.1()(64bit) for package: libini_config-1.1.0-24.el7.x86_64 ---> Package libref_array.x86_64 0:0.1.4-24.el7 will be installed ---> Package libverto-tevent.x86_64 0:0.2.5-4.el7 will be installed --> Processing Dependency: libtevent.so.0(TEVENT_0.9.9)(64bit) for package: libverto-tevent-0.2.5-4.el7.x86_64 --> Processing Dependency: libtalloc.so.2(TALLOC_2.0.2)(64bit) for package: libverto-tevent-0.2.5-4.el7.x86_64 --> Processing Dependency: libtevent.so.0()(64bit) for package: libverto-tevent-0.2.5-4.el7.x86_64 --> Processing Dependency: libtalloc.so.2()(64bit) for package: libverto-tevent-0.2.5-4.el7.x86_64 --> Running transaction check ---> Package libpath_utils.x86_64 0:0.2.1-24.el7 will be installed ---> Package libtalloc.x86_64 0:2.1.1-1.el7 will be installed ---> Package libtevent.x86_64 0:0.9.21-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Installing: nfs-utils x86_64 1:1.3.0-0.8.el7 base 362 k Installing for dependencies: gssproxy x86_64 0.3.0-10.el7 base 81 k keyutils x86_64 1.5.8-3.el7 base 54 k libbasicobjects x86_64 0.1.1-24.el7 base 24 k libcollection x86_64 0.6.2-24.el7 base 40 k libevent x86_64 2.0.21-4.el7 base 214 k libini_config x86_64 1.1.0-24.el7 base 50 k libnfsidmap x86_64 0.25-11.el7 base 46 k libpath_utils x86_64 0.2.1-24.el7 base 27 k libref_array x86_64 0.1.4-24.el7 base 26 k libtalloc x86_64 2.1.1-1.el7 base 30 k libtevent x86_64 0.9.21-3.el7 base 31 k libtirpc x86_64 0.2.4-0.5.el7 base 85 k libverto-tevent x86_64 0.2.5-4.el7 base 9.0 k rpcbind x86_64 0.2.0-26.el7 base 55 k Transaction Summary ==================================================================================================================================== Install 1 Package (+14 Dependent packages) Total download size: 1.1 M Installed size: 2.9 M Is this ok [y/d/N]: y Downloading packages: (1/15): gssproxy-0.3.0-10.el7.x86_64.rpm | 81 kB 00:00:00 (2/15): keyutils-1.5.8-3.el7.x86_64.rpm | 54 kB 00:00:00 (3/15): libbasicobjects-0.1.1-24.el7.x86_64.rpm | 24 kB 00:00:00 (4/15): libcollection-0.6.2-24.el7.x86_64.rpm | 40 kB 00:00:00 (5/15): libnfsidmap-0.25-11.el7.x86_64.rpm | 46 kB 00:00:00 (6/15): libini_config-1.1.0-24.el7.x86_64.rpm | 50 kB 00:00:00 (7/15): libevent-2.0.21-4.el7.x86_64.rpm | 214 kB 00:00:00 (8/15): libpath_utils-0.2.1-24.el7.x86_64.rpm | 27 kB 00:00:00 (9/15): libref_array-0.1.4-24.el7.x86_64.rpm | 26 kB 00:00:00 (10/15): libtevent-0.9.21-3.el7.x86_64.rpm | 31 kB 00:00:00 (11/15): libverto-tevent-0.2.5-4.el7.x86_64.rpm | 9.0 kB 00:00:00 (12/15): rpcbind-0.2.0-26.el7.x86_64.rpm | 55 kB 00:00:00 (13/15): nfs-utils-1.3.0-0.8.el7.x86_64.rpm | 362 kB 00:00:00 (14/15): libtalloc-2.1.1-1.el7.x86_64.rpm | 30 kB 00:00:00 (15/15): libtirpc-0.2.4-0.5.el7.x86_64.rpm | 85 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------ Total 1.5 MB/s | 1.1 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libref_array-0.1.4-24.el7.x86_64 1/15 Installing : libcollection-0.6.2-24.el7.x86_64 2/15 Installing : libtalloc-2.1.1-1.el7.x86_64 3/15 Installing : libtirpc-0.2.4-0.5.el7.x86_64 4/15 Installing : libbasicobjects-0.1.1-24.el7.x86_64 5/15 Installing : rpcbind-0.2.0-26.el7.x86_64 6/15 Installing : libtevent-0.9.21-3.el7.x86_64 7/15 Installing : libverto-tevent-0.2.5-4.el7.x86_64 8/15 Installing : libpath_utils-0.2.1-24.el7.x86_64 9/15 Installing : libini_config-1.1.0-24.el7.x86_64 10/15 Installing : gssproxy-0.3.0-10.el7.x86_64 11/15 Installing : libnfsidmap-0.25-11.el7.x86_64 12/15 Installing : keyutils-1.5.8-3.el7.x86_64 13/15 Installing : libevent-2.0.21-4.el7.x86_64 14/15 Installing : 1:nfs-utils-1.3.0-0.8.el7.x86_64 15/15 Verifying : 1:nfs-utils-1.3.0-0.8.el7.x86_64 1/15 Verifying : libbasicobjects-0.1.1-24.el7.x86_64 2/15 Verifying : libverto-tevent-0.2.5-4.el7.x86_64 3/15 Verifying : libtirpc-0.2.4-0.5.el7.x86_64 4/15 Verifying : libtalloc-2.1.1-1.el7.x86_64 5/15 Verifying : libevent-2.0.21-4.el7.x86_64 6/15 Verifying : libtevent-0.9.21-3.el7.x86_64 7/15 Verifying : keyutils-1.5.8-3.el7.x86_64 8/15 Verifying : rpcbind-0.2.0-26.el7.x86_64 9/15 Verifying : libnfsidmap-0.25-11.el7.x86_64 10/15 Verifying : libcollection-0.6.2-24.el7.x86_64 11/15 Verifying : gssproxy-0.3.0-10.el7.x86_64 12/15 Verifying : libref_array-0.1.4-24.el7.x86_64 13/15 Verifying : libpath_utils-0.2.1-24.el7.x86_64 14/15 Verifying : libini_config-1.1.0-24.el7.x86_64 15/15 Installed: nfs-utils.x86_64 1:1.3.0-0.8.el7 Dependency Installed: gssproxy.x86_64 0:0.3.0-10.el7 keyutils.x86_64 0:1.5.8-3.el7 libbasicobjects.x86_64 0:0.1.1-24.el7 libcollection.x86_64 0:0.6.2-24.el7 libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.1.0-24.el7 libnfsidmap.x86_64 0:0.25-11.el7 libpath_utils.x86_64 0:0.2.1-24.el7 libref_array.x86_64 0:0.1.4-24.el7 libtalloc.x86_64 0:2.1.1-1.el7 libtevent.x86_64 0:0.9.21-3.el7 libtirpc.x86_64 0:0.2.4-0.5.el7 libverto-tevent.x86_64 0:0.2.5-4.el7 rpcbind.x86_64 0:0.2.0-26.el7 Complete! root@chantyou:~#
查看远程NFS服务器共享出来的文件夹:
果然可以看到:
root@chantyou:~# showmount --help Usage: showmount [-adehv] [--all] [--directories] [--exports] [--no-headers] [--help] [--version] [host] root@chantyou:~# showmount -e 121.41.120.185 Export list for 121.41.120.185: /home/share/image *
然后继续去测试:
root@chantyou:~# ls httpd.conf.backup_20150604 root@chantyou:~# ls -l total 12 -rw-r--r-- 1 root root 11753 Jun 4 15:48 httpd.conf.backup_20150604 root@chantyou:~# mkdir nfs_client_root root@chantyou:~# cd nfs_client_root/ root@chantyou:nfs_client_root# ls -l total 0 root@chantyou:nfs_client_root# pwd /root/nfs_client_root root@chantyou:nfs_client_root# mount -t nfs 121.41.120.185:/home/share/image /root/nfs_client_root/ root@chantyou:nfs_client_root# ls -l total 0 root@chantyou:nfs_client_root# pwd /root/nfs_client_root root@chantyou:nfs_client_root# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 2.2G 17G 12% / devtmpfs 489M 0 489M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 50M 447M 11% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup 121.41.120.185:/home/share/image 20G 1.8G 17G 10% /root/nfs_client_root root@chantyou:nfs_client_root# mount -t nfs root@chantyou:nfs_client_root# cd .. root@chantyou:~# mount -t nfs root@chantyou:~# service --status-all Aegis is running /etc/init.d/agentwatch: line 152: status: command not found netconsole module not loaded Configured devices: lo eth0 eth1 Currently active devices: lo eth0 eth1 root@chantyou:~# umount /root/nfs_client_root/ root@chantyou:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 2.2G 17G 12% / devtmpfs 489M 0 489M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 50M 447M 11% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup root@chantyou:~# mount -t nfs 121.41.120.185:/home/share/image /root/nfs_client_root/ root@chantyou:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 2.2G 17G 12% / devtmpfs 489M 0 489M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 50M 447M 11% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup 121.41.120.185:/home/share/image 20G 1.8G 17G 10% /root/nfs_client_root root@chantyou:~# touch ^C root@chantyou:~# cd /root/nfs_client_root/ root@chantyou:nfs_client_root# ls -l total 240 -rw-r--r-- 1 root root 70545 May 28 2013 mmexport1369703131812.jpg -rw-r--r-- 1 root root 82168 Sep 12 2013 mmexport1378988706739.jpeg -rw-r--r-- 1 root root 85510 Nov 18 2013 p_large_0fOT_43d9000068f01263.jpg root@chantyou:nfs_client_root# touch test_client_write.txt touch: cannot touch ‘test_client_write.txt’: Permission denied root@chantyou:nfs_client_root# sudo touch test_client_write.txt touch: cannot touch ‘test_client_write.txt’: Permission denied root@chantyou:nfs_client_root#
很明显,第一次mount没有刷新出来服务器端的文件。
后来再次重新mount才能看到。
但是却没有权限去写入到服务器啊,然后去解决:
【已解决】NFS客户端写入NFS共享文件夹出错:Permission denied
9.然后再去NFS客户端的mount动作,尝试加到启动项,让开机自动mount:
root@chantyou:nfs_client_root# vi /etc/fstab # # /etc/fstab # Created by anaconda on Fri Nov 21 18:16:53 2014 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=6634633e-001d-43ba-8fab-202f1df93339 / ext4 defaults,barrier=0 1 1 121.41.120.185:/home/share/image /root/nfs_client_root/ nfs auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800 0 0 "/etc/fstab" 12L, 412C written root@chantyou:nfs_client_root#
再去看看fstab的语法:
【整理】Linux中fstab的语法和参数含义和mount NFS时相关参数含义
然后去重启NFS客户端的服务器:
root@chantyou:~# reboot
看看是否自动挂载了,结果没有:
Last login: Thu Jul 23 15:21:17 2015 from 121.238.253.76 Welcome to aliyun Elastic Compute Service! root@chantyou:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 2.0G 17G 11% / devtmpfs 488M 0 488M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 6.5M 490M 2% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup root@chantyou:~# ls /root/nfs_client_root/ -l total 0
所以就是:
【已解决】CentOS 7中fstab中添加了系统启动时自动挂载NFS但无效
【总结】
最终终于实现了,(在NFS服务端)用NFS共享文件夹,供别人(NFS的客户端)去访问,并且NFS客户端中,添加NFS的mount到启动项,确保开机就自动挂载。
再整理一下:
要在服务器上面建立NFS服务器,供别人访问其上面的文件的话,需要搞懂:
【NFS的背景知识】
- 需要先有个NFS的服务器
- 上面开通了NFS server的功能:一般叫做nfs-kernel-server(support for NFS kernel server)
- 共享出别人可以访问的文件夹(和文件)
- 其他的,别人,作为NFS的客户端
- 也要先去安装NFS client客户端的软件:一般叫做nfs-common(NFS support files common to client and server)
- 然后去mount挂载远程NFS服务器对应的文件夹到本地某个目录上
然后NFS客户端就可以像操作本地的文件夹一样去操作NFS远程服务器上面的文件夹和文件了:
新建文件
删除文件
等等。
具体操作步骤是:
【NFS服务器】
1.安装NFS服务器端软件:
apt-get install nfs-kernel-server
2.编辑配置文件,导出对应要共享的文件夹:
vi /etc/exports
加上配置参数,比如:
/home/share/image *(rw,sync,no_subtree_check)
编辑后,导出配置:
exportfs -a
然后记得重启nfs:
service nfs-kernel-server restart
然后可以通过:
service nfs-kernel-server status
确认NFS服务已正常运行。
【NFS客户端】
CentOS:
yum install nfs-utils
Ubuntu:
apt-get install nfs-common
然后去查看远程NFS服务器共享出来的文件夹:
showmount -e 121.41.120.185
然后去把远程NFS服务器的共享文件夹挂载到本地:
mount -t nfs 121.41.120.185:/home/share/image /root/nfs_client_root/
【关于NFS客户端如何开机自动挂载(远程NFS服务器共享出来的文件夹)】
如果想要NFS客户端,每次开机启动都自动挂载,则可以去编辑:
vi /etc/fstab
加上如下配置:
121.41.120.185:/home/share/image /root/nfs_client_root/ nfs auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800 0 0
即可。
其中具体的参数的含义,详见:
【整理】Linux中fstab的语法和参数含义和mount NFS时相关参数含义
需要注意的是当CentOS 7时,默认可能会由于rc.local没有权限而导致自动挂载配置失效。
详见: