NFS shared network experiment--multi-service experiment

1. NFS shared network experiment

1. NFS network sharing experiment

Install the NFS service on server2, provide the shared directory /share, create the file index.html in the /share directory, and customize the file content. Mount the /share directory of server2 to the /var/www/html directory of server1 through NFS, so that PC1 can display customized content when accessing the Web service

2. Background

1) Prepare 3 virtual machines, a Windows virtual machine PC1 (not limited to win7 or win10), a Linux server server1 (IP is 172.16.100.100/24) and an empty virtual machine server2. The virtual machine network uses host-only mode.
2) Server1 provides DHCP service to assign IP addresses of corresponding network segments to PC1 and server2.
3) Server1 provides PXE service, which enables server2 to automatically install Centos7 Linux operating system.
4) Install and start the httpd service on server1 to provide external Web services, and build a DNS service to resolve the address www.kgc.com, so that PC1 can use the domain name www.kgc.com to access the Web server.
5) Install the NFS service on server2, provide the shared directory /share, create the file index.html in the /share directory, and customize the file content. Mount the /share directory of server2 to the /var/www/html directory of server1 through NFS, so that PC1 can display customized content when accessing the Web service.
In the case where the first 4 conditions are all met, the NFS sharing experiment operation is carried out.

Insert picture description here
The IP address of the virtual machine is automatically obtained as 172.16.100.102
Insert picture description here

Two, concrete operation

1. Install the local yum source (because this virtual machine is just installed by PXE, there is no Yum source warehouse)

Related operation commands:

[root@localhost ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir repos.bak
[root@localhost yum.repos.d]# mv *.repo repos.bak
[root@localhost yum.repos.d]# vim local.repo
[root@localhost yum.repos.d]# yum clean all && yum makecache

Specific operation screenshot

Insert picture description here

2. Install nfs and rpcbind services

Related operation commands:

yum -y install nfs-utils rpcbind

Specific steps
Insert picture description here

3. Set up a shared directory

Related operation commands:

mkdir -p /opt/share
chmod 777 /opt/share/

vim /etc/exports
/opt/share 192.168.163.0/24(rw,sync,no_root_squash)

客户机地址可以是主机名、IP 地址、网段地址,允许使用“*”、“?”通配符。
常用选项
“rw” 表示允许读写,“ro” 表示为只读;

sync :表示同步写入到内存与硬盘中。
async :将数据先保存在内存缓冲区中,必要时才写入磁盘。

no_root_squash : 表示当客户机以root身份访问时赋予本地root权限(默认是root_squash)。
root_squash :表示客户机用root用户访问该共享目录时,将root用户映射成匿名用户。
all_squash :所有访问用户都映射为匿名用户或用户组。

subtree_check(默认):若输出目录是一个子目录,则nfs服务器将检查其父目录的权限。
no_subtree_check :即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率。

Specific steps:
Insert picture description here

4. Start the NFS service program

  • When manually loading the NFS sharing service, you should start rpcbind first, and then start the nfs
    related operation commands
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs

netstat  -anpt  |  grep  111     #查看rpcbind端口111是否开启, rpcbind默认使用tcp端口111

Specific steps:
Insert picture description here
Insert picture description here

5. Create relevant files and edit

Related operation commands:

cd /opt/share
touch indel.html
 vim index.html 


Insert picture description here

6. Publish and view the shared directory published by this machine

Related operation commands

exportfs -rv			#发布共享
showmount -e            #查看共享

Specific steps:

Insert picture description here

7. Turn off the firewall

Related operation commands

systemctl stop firewalld.service 
setenforce 0

Specific steps:
Insert picture description here

Three, configure the client server1

The above is the relevant configuration of SERVER2, so the experiment needs to mount the /share directory of server2 to the /var/www/html directory of server1 through NFS, so that PC1 can display customized content when accessing the Web service. So here back to the server of 172.16.100.100 to configure.

1. Install the nfs-utils and rpcbind packages and turn off the firewall to view the shared directory

Configure on server1 (172.16.100.100)
Related operation commands:

rpm -q rpcbind nfs-utils 
yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl enable rpcbind

systemctl stop firewalld.service 
setenforce 0

#查看 NFS 服务器端共享了哪些目录
showmount -e 172.16.100.102

Specific steps:
Insert picture description here

2. Mount the NFS shared directory

Related operation commands:

 mount 172.16.100.102:/opt/share /var/www/html/
 #把

Specific steps:
Insert picture description here
Insert picture description here

It is found here that the contents of the file have been synchronized.
Insert picture description here

3. Access through the previously configured win10 virtual machine to verify whether it is successful.

Enter win10 virtual machine
Insert picture description here

Insert picture description here
success

Guess you like

Origin blog.csdn.net/weixin_44324367/article/details/111224056