Linux Centos7 - - NFS shared storage space

Keywords: CentOS vim Linux Anaconda

The purpose of this chapter is to use NFS shared storage space and build HTTPD services to use this space.

This chapter environment: VM virtual machine, a server Centos7 as a server to provide NFS services, a server Centos7-1 as a client

1. Add a hard disk to the server (restart the server disk is valid)

2. Check whether the disk is in effect

[root@localhost ~]# ls /dev/
agpgart          lp0                 sda5      tty22  tty48    usbmon0
autofs           lp1                 sdb  //This is our new tty23 tty49 usbmon1
block            lp2                 sg0       tty24  tty5     usbmon2
bsg              lp3                 sg1       tty25  tty50    vcs
btrfs-control    mapper              sg2       tty26  tty51    vcs1
bus              mcelog              shm       tty27  tty52    vcs2
cdrom            mem                 snapshot  tty28  tty53    vcs3
char             mqueue              snd       tty29  tty54    vcs4
console          net                 sr0       tty3   tty55    vcs5
core             network_latency     stderr    tty30  tty56    vcs6
cpu              network_throughput  stdin     tty31  tty57    vcsa
cpu_dma_latency  null                stdout    tty32  tty58    vcsa1

3. Configure the disk and format it

[root@localhost ~]# fdisk /dev/sdb
 Welcome to fdisk (util-linux 2.23.2).

Changes will stay in memory until you decide to write them to disk.
Think twice before using write commands.

Device does not contain a recognized partition table
 Create a new DOS disk label using the disk identifier 0xe5bb6879.

Command (Enter m for help):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
 Partition number (1-4, default 1):
Start sector (2048-41943039, default 2048):
The default value 2048 will be used
 Last sector, +sector or+size {K, M, G} (2048-41943039, default 41943039):
The default value 41943039 will be used
 Partition 1 has been set to Linux type with size of 20 GiB

Command (Enter m for help):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Synchronizing disks.
[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5242624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

4. Auto-mount and view mount status

[root@client html]# vim /etc/fstab

/etc/fstab
 Created by anaconda on Sat Aug 10 00:09:52 2019

 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=6885a615-3022-4e62-8685-1dc9aaa0b657 /                       xfs     defaults        0 0
UUID=91d30663-7fe2-4989-9ad9-9f9c7086a493 /boot                   xfs     defaults        0 0
UUID=121c8f14-d41e-4da5-a3eb-f973cde89040 /home                   xfs     defaults        0 0
UUID=89bc11a2-b2cc-4816-9638-8f061beae396 swap                    swap    defaults        0 0
/dev/sdb1       /mnt    xfs     defaults        0 0
//Device directory mountpoint file type   
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
:wq  //Save exit
[root@localhost ~]# mount -a
[root@localhost ~]# df -hT
//File System Type Capacity Used Available% Mount Points
/dev/sda2      xfs        10G  3.9G  6.2G   39% /
devtmpfs       devtmpfs  898M     0  898M    0% /dev
tmpfs          tmpfs     912M     0  912M    0% /dev/shm
tmpfs          tmpfs     912M  9.0M  903M    1% /run
tmpfs          tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda5      xfs        10G   37M   10G    1% /home
/dev/sda1      xfs       6.0G  174M  5.9G    3% /boot
tmpfs          tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs          tmpfs     183M   16K  183M    1% /run/user/0
/dev/sdb1      xfs        20G   33M   20G    1% /mnt

5. Install NFS Sharing and Remote Call Toolkit

[root@localhost~]# Yum install nfs-utils rpcbind-y//NFS Sharing and Remote Call Toolkit
 Loaded plug-ins: fastest mirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: centos.ustc.edu.cn
 * updates: mirrors.163.com
 Resolving dependencies
 --> Inspecting business
 The package nfs-utils.x86_64.1.1.3.0-0.48.el7 will be upgraded
 The package nfs-utils.x86_64.1.1.3.0-0.61.el7 will be updated
 The package rpcbind.x86_64.0.0.2.0-42.el7 will be upgraded
 The package rpcbind.x86_64.0.0.2.0-47.el7 will be updated

6. Editing Shared Profile

[root@localhost~]# vim/etc/exports// Go to the shared configuration file and start configuring

/ MNT 192.168.17.0/24 (rw, sync, no_root_squash)// Readable, Writable, Synchronized, No Degradation Processing
 The mount point directory you share                                                      

7. Open all functions and close the firewall to see if it has been shared.

[root@localhost ~]# System CTL start NFS // Open Sharing Function
[root@localhost ~]# System CTL start rpcbind // Open remote calls
[root@localhost ~]# Netstat-ntap | grep RPC View TCP Port
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      3035/rpc.mountd     
tcp        0      0 0.0.0.0:45274           0.0.0.0:*               LISTEN      3033/rpc.statd      
tcp6       0      0 :::38508                :::*                    LISTEN      3033/rpc.statd      
tcp6       0      0 :::20048                :::*                    LISTEN      3035/rpc.mountd     
[root@localhost ~]# System CTL stop firewalld. service // / close firewall
[root@localhost ~]# setenforce 0//Turn off Enhancement
[root@localhost ~]# showmount -e // / See if we share it
Export list for localhost.localdomain:
/mnt 192.168.17.0/24

8. To the client segment, close all functions and install HTTPD services

[root@client ~]# systemctl stop firewalld.service 
[root@client ~]# setenforce 0
[root@client ~]# yum insatll httpd -y
//Loaded plug-ins: fastest mirror, langpacks

9. Mount the server's mount point under our HTTPD site

[root@client ~]# Mount 192.168.17.128:/mnt/var/www/html/site
[root@client ~]# df -hT
//File System Type Capacity Used Available% Mount Points
/dev/sda2           xfs        20G  4.5G   16G   23% /
devtmpfs            devtmpfs  898M     0  898M    0% /dev
tmpfs               tmpfs     912M     0  912M    0% /dev/shm
tmpfs               tmpfs     912M  9.0M  903M    1% /run
tmpfs               tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda3           xfs       9.4G   37M  9.3G    1% /home
/dev/sda1           xfs       5.6G  174M  5.5G    4% /boot
tmpfs               tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs               tmpfs     183M   24K  183M    1% /run/user/0
/dev/sr0            iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
192.168.17.128:/mnt nfs4       20G   32M   20G    1% /var/www/html

10. Use another method: automount, configure

[root@client ~]# Umount/var/www/html/// Unhook the previous
[root@client ~]# df -hT
//File System Type Capacity Used Available% Mount Points
/dev/sda2      xfs        20G  4.5G   16G   23% /
devtmpfs       devtmpfs  898M     0  898M    0% /dev
tmpfs          tmpfs     912M     0  912M    0% /dev/shm
tmpfs          tmpfs     912M  9.0M  903M    1% /run
tmpfs          tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda3      xfs       9.4G   37M  9.3G    1% /home
/dev/sda1      xfs       5.6G  174M  5.5G    4% /boot
tmpfs          tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs          tmpfs     183M   24K  183M    1% /run/user/0
/dev/sr0       iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64

[root@client ~]# vim /etc/fstab
 /etc/fstab
Created by anaconda on Fri Aug  9 19:16:53 2019

 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=0857ae22-72c1-4ad4-bd8d-333df1d5c1a4 /                       xfs     defaults        0 0
UUID=2d335fb0-e4af-4a90-8777-1ce16ac58065 /boot                   xfs     defaults        0 0
UUID=d28abede-d7a4-439a-b830-64f95069ec17 /home                   xfs     defaults        0 0
UUID=1bc36e2d-3ba8-4980-9bf8-7b56280bb434 swap                    swap    defaults        0 0
192.168.17.128:/mnt     /var/www/html   nfs     defaults,_netdev        0 0     
[root@client ~]# mount -a
[root@client ~]# df -hT
//File System Type Capacity Used Available% Mount Points
/dev/sda2           xfs        20G  4.5G   16G   23% /
devtmpfs            devtmpfs  898M     0  898M    0% /dev
tmpfs               tmpfs     912M     0  912M    0% /dev/shm
tmpfs               tmpfs     912M  9.0M  903M    1% /run
tmpfs               tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda3           xfs       9.4G   37M  9.3G    1% /home
/dev/sda1           xfs       5.6G  174M  5.5G    4% /boot
tmpfs               tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs               tmpfs     183M   24K  183M    1% /run/user/0
/dev/sr0            iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
192.168.17.128:/mnt nfs4       20G   32M   20G    1% /var/www/html

11. Write a web page on the site and open HTTPD services

[root@client ~]# cd /var/www/html/
[root@client html]# ls
[root@client html]# vim index.html
h1>this is nfs</h1>
~                                                                                      
~                          
[root@client html]# cat index.html 
<h1>this is nfs</h1>
[root@client html]# systemctl start httpd

12. Let's try the website (the IP address of the client)

That's all we share in NFS storage.

Posted by j0se on Sun, 15 Sep 2019 21:13:23 -0700