


What is NFS? Share to implement NFS sharing on CentOS7
1. Introduction
NFS 是Network File System的缩写,即网络文件系统。一种使用于分散式文件系统的协定,功能是让客户端通过网络访问不同主机上磁盘里的数据,主要用在类Unix系统上实现文件共享的一种方法。 NFS在文件传送或信息传送过程中依赖于RPC协议。RPC,远程过程调用 (Remote Procedure Call) 是能使客户端执行其他系统中程序的一种机制。NFS本身是没有提供信息传输的协议和功能的,但NFS却能让我们通过网络进行资料的分享,这是因为NFS使用了一些其它的传输协议。而这些传输协议用到这个RPC功能的。可以说NFS本身就是使用RPC的一个程序。或者说NFS也是一个RPC SERVER。所以只要用到NFS的地方都要启动RPC服务,不论是NFS SERVER或者NFS CLIENT。这样SERVER和CLIENT才能通过RPC来实现PROGRAM PORT的对应。可以这么理解RPC和NFS的关系:NFS是一个文件系统,而RPC是负责负责信息的传输。
2. Server configuration
1. Turn off the system firewall and selinux
#查看系统防火墙的状态,可以看到防火墙是开着的 [root@bogon ~]#systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: active (running) since Sat 2017-06-03 09:38:00 CST; 8s ago Docs: man:firewalld(1) Main PID: 24067 (firewalld) CGroup: /system.slice/firewalld.service └─24067 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Jun 03 09:37:58 bogon systemd[1]: Starting firewalld - dynamic firewall daemon... Jun 03 09:38:00 bogon systemd[1]: Started firewalld - dynamic firewall daemon. #关闭防火墙 [root@bogon ~]#systemctl stop firewalld #再次查看防火墙,可以看到已经关闭了 [root@bogon ~]#systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) Jun 01 11:33:35 localhost systemd[1]: Starting firewalld - dynamic firewall daemon... Jun 01 11:33:44 localhost systemd[1]: Started firewalld - dynamic firewall daemon. Jun 03 09:11:32 bogon systemd[1]: Stopping firewalld - dynamic firewall daemon... Jun 03 09:11:34 bogon systemd[1]: Stopped firewalld - dynamic firewall daemon. Jun 03 09:37:58 bogon systemd[1]: Starting firewalld - dynamic firewall daemon... Jun 03 09:38:00 bogon systemd[1]: Started firewalld - dynamic firewall daemon. Jun 03 09:38:34 bogon systemd[1]: Stopping firewalld - dynamic firewall daemon... Jun 03 09:38:36 bogon systemd[1]: Stopped firewalld - dynamic firewall daemon. #查看selinux的运行模式,现在为强制模式 [root@bogon share]#getenforce Enforcing #把selinux设为许可模式 [root@bogon share]#setenforce 0 #再次查看selinux的运行模式,已经变为许可模式 [root@bogon share]#getenforce Permissive #要想禁用selinux,则需要编辑selinux的配置文件,把SELINUX设置成disabled,然后重启生效 [root@bogon share]#vi /etc/sysconfig/selinux [root@bogon share]#cat /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=disabled # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
2. Install the required software packages
[root@bogon ~]#yum install -y rpc-bind nfs-utils
3. Server configuration
NFS服务的主要配置文件为 /etc/exports. /etc/exports文件内容格式: 客户端(选项:访问权限,用户映射,其他] 输出目录是指NFS系统中所定义的共享给客户端使用的文件系统 客户端是定义网络中可以访问这个NFS共享目录的IP地址或网段或域名等 客户端常用的指定方式 指定ip地址的主机:192.168.100.1 指定一个子网:192.168.100.0/24 也可以写成:192.168.100.0/255.255.255.0 指定域名的主机:david.bsmart.cn 指定域中的所有主机:*.bsmart.cn 所有主机:* 选项用来设置输出目录的访问权限、用户映射等。 NFS主要有3类选项: 设置输出目录只读:ro 设置输出目录读写:rw 用户映射选项 all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody); no_all_squash:与all_squash取反(默认设置); root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置); no_root_squash:与rootsquash取反; anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx); anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx); 其它选项 secure:限制客户端只能从小于1024的tcp/ip端口连接nfs服务器(默认设置); insecure:允许客户端从大于1024的tcp/ip端口连接服务器; sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性; async:将数据先保存在内存缓冲区中,必要时才写入磁盘; wdelay:检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率(默认设置); no_wdelay:若有写操作则立即执行,应与sync配合使用; subtree:若输出目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置); no_subtree:即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;
Modify the /etc/exports file and define NFS share
#修改NFS配置文件,定义共享 [root@bogon ~]#vi /etc/exports #定义向所有客户端共享/share目录,共享方式为可读可写 [root@bogon ~]#cat /etc/exports /share *(rw,sync) #创建/share这个共享目录 [root@bogon ~]#mkdir /share #把共享目录的权限设定为所有用户都可读可写权限 [root@bogon ~]#chmod 766 /share #把NFS加入到开机自启动选项中 [root@bogon ~]#systemctl enable nfs Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service. #开启NFS服务 [root@bogon ~]#systemctl start nfs #把RPCbind加入开机处启动选项中 [root@bogon ~]#systemctl enable rpcbind #启动RPCbind [root@bogon ~]#systemctl start rpcbind #查看NFS服务的状态 ,可以看到NFS服务已经在运行中 [root@bogon ~]#systemctl status nfs ● nfs-server.service - NFS server and services Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled) Active: active (exited) since Sat 2017-06-03 09:22:02 CST; 37min ago Main PID: 23967 (code=exited, status=0/SUCCESS) CGroup: /system.slice/nfs-server.service Jun 03 09:22:02 bogon systemd[1]: Starting NFS server and services... Jun 03 09:22:02 bogon systemd[1]: Started NFS server and services. #查看本机共享的文件系统 [root@bogon ~]#exportfs /share <world></world>
3. Client configuration:
1. Close the firewall on the client With selinux, the method is the same as above.
2. Install the NFS software package on the client and set the NFS service to start automatically at boot. The method is the same as above.
3. Mount the shared NFS file system
#把192.168.16.29这个主机上的共享目录挂载到本机的/media上 [root@bogon ~]#mount 192.168.16.29:/share /media #查看是否已经挂载成功 [root@bogon ~]#mount | grep media 192.168.16.29:/share on /media type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.16.177,local_lock=none,addr=192.168.16.29) #把共享目录写入系统挂载文件系统 [root@bogon ~]#vi /etc/fstab [root@bogon ~]#cat /etc/fstab | grep media 192.168.16.29:/share /media nfs4 defaults 0 0
4. Test:
1. Create a 10M file in the server shared directory
[root@bogon media]#cd /share [root@bogon share]#ls #在NFS共享目录上新建一个10M大小的文件,提示成功 [root@bogon share]#dd if=/dev/zero of=/share/f1 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.0351504 s, 298 MB/s [root@bogon share]#ll -h total 10M -rw-r--r--. 1 root root 10M Jun 3 10:14 f1
2. Create another file f2 on the client and try at the same time Delete another file f1
[root@bogon ~]#cd /media [root@bogon media]#ls f1 #在共享目录上新建一个文件f2,未报错 [root@bogon media]#touch f2 #删除存在的文件f1,未报错 [root@bogon media]#rm -f f1
3. View the files in the shared directory on the server
[root@bogon share]#ls f2
The above is the detailed content of What is NFS? Share to implement NFS sharing on CentOS7. For more information, please follow other related articles on the PHP Chinese website!

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools