Do it!!! Linux Network Service -- Remote YUM warehouse and NFS (build remote YUM warehouse and NFS shared storage service)

1, Build remote YUM warehouse

1. YUM warehouse overview

(1) Introduction to yum warehouse

YUM(Yellow dog Updater, Modified)

Software update mechanism based on RPM package

Can resolve dependencies automatically

All software packages are provided by several YUM software warehouses

(2) Three ways to provide yum warehouse

FTP service: ftp://
HTTP service: http://
Local directory: file://

(3) yum profile

Specify the YUM warehouse location for the client
yum's profile

Warehouse settings: /etc/yum Repos D/ Repo
Log file: /var/log/yum Log
Configuration file: /etc/yum Repo D/ Repo

[CentOS7-base]   #Source name, required
name=CentOS-$releasever-base     #Source description can be left blank, but there will be a prompt
baseurl=file:///misc/cd/ \\local CD files can have multiple addresses. Required
        https://mirrors.aliyun.com/centos/7.3.1611/os/x86_64/
gpgcheck=1                    #Whether to enable verification is displayed in yum It has been defined in conf, and its default value is 1
enabled=1                     #Whether to disable this yum source. The default is
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#If the yum source package verification is enabled, the RPM public key needs to be imported. Here, the installation is only performed when the system does not import the RPM public key
#This is equivalent to rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Today, Xiaobian will take you to play ftp. Don't talk too much. Let's start!

(4) Configure remote ftp YUM source

Step 1: the server attaches the centos7 CD image to the server (the CD image should be connected)

[root@server ~]# mount /dev/sr0 /mnt 	' Mount image locally '
mount: /dev/sr0 is write-protected, mounting read-only
[root@server ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs        20G  3.1G   17G  16% /
...Omit some contents
/dev/sr0       iso9660   4.3G  4.3G     0 100% /mnt
[root@server ~]# ls /mnt 		' Mounted successfully '
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

Step 2: enter the server site and copy the image to a folder

[root@server var]# yum install vsftpd -y 	' Install vsftpd'
...Omit some contents

[root@server var]# cd ftp
[root@server ftp]# ls
pub
[root@server ftp]# pwd 'enter the ftp main configuration file'
/var/ftp
[root@server ftp]# mkdir centos7 	' Create a folder under the site to store the image '
[root@server ftp]# ls
centos7  pub
[root@server ftp]# ls centos7
[root@server ftp]# CP -rf /mnt/* centos7/& 	' Forcibly copy the image to centos7 and run it in the background '
[1] 9301
[root@server ftp]# jobs 			' View background running programs'
[1]+  Running                 cp -i -rf /mnt/* centos7/ &
[root@server ftp]# mkdir other 		' Create index directory of yum source for creating repodata data file '
[root@server ftp]# ls
centos7  other  pub
'If other rpm security 
Packaging documents are stored in/var/ftp/other Directory, you can perform the following operations to create repodata data'
[root@server ftp]# createrepo -g /mnt/repodata/repomd.xml  other
		'With existing repodata Catalog as template '

[root@server ftp]# ls centos7
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@server ftp]# ls other/repodata

Step 3: the server starts the vsftpd service
Port 21 is responsible for connecting to the server
Port 20 is responsible for uploading and downloading

[root@server ~]# systemctl start vsftpd 'start vsftp file sharing service'
[root@server ~]# netstat -ntap | grep 21
tcp6       0      0 :::21                   :::*                    LISTEN      12216/vsftpd        
[root@server ~]# netstat -ntap | grep 20

vsftpd in

21 The port is responsible for connecting to the server

20 The port is responsible for uploading and downloading

[root@server ~]# Systemctl stop firewalld Service 	' Turn off firewall '
[root@server ~]# Setenforce0 'turn off core protection'

Step 4: enter the client configuration: install the ftp service and check whether the site can be seen
Feel the magic of ftp

[root@client ~]# yum install ftp -y
[root@client ~]# ftp 192.168.197.172 	' Use ftp to log in to the server anonymously '
Connected to 192.168.197.172 (192.168.197.172).
220 (vsFTPd 3.0.2)
Name (192.168.197.172:root): ftp	'Enter name'
331 Please specify the password.
Password:	'input root User login password'
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls	'Discover files that can be viewed in the site'
227 Entering Passive Mode (192,168,197,172,88,1).
150 Here comes the directory listing.
drwxr-xr-x    8 0        0             220 Nov 25 03:15 centos7
drwxr-xr-x    3 0        0              22 Nov 25 03:16 other
drwxr-xr-x    2 0        0               6 Oct 30  2018 pub
226 Directory send OK.
ftp> bye
221 Goodbye.

Step 5: before building the yum source, package the original configuration file and take it with you. Next, manually write a
Move all repo files to a folder

[root@client ~]# CD /etc/yum Repos D/'yum profile directory '
[root@client yum.repos.d]# ls' first is the master profile '
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@client yum.repos.d]# mkdir bak
[root@client yum.repos.d]#MV * Repo bak 'move all files ending in repo to bak's folder'
[root@client yum.repos.d]#ls bak    
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo

Step 6: clear the cache, write a repo file and copy the secret key to it
When the protagonist comes, the front ones are all matting. This must be remembered,

[root@client yum.repos.d]# vim centos7.repo 
[base]		'//Warehouse category '
name=centos7.packages		'//Warehouse name (description) '
baseurl=ftp://192.168.110.133/centos7 		'// URL access path '
enabled=1		'//Enable this software warehouse '
gpgcheck=1		'//Verify the signature of the software package. Unlike local yum, it is a remote Yum warehouse, so you should verify it to prevent it from being tampered with by others. '
gpgkey=ftp://192.168.110.133/centos7/RPM-GPG-KEY-CentOS-7		
'Paste the secret key copied by the server into this,//Location of GPG public key file '

[other]
name=other.packages
baseurl=ftp://192.168.110.133/other  
enabled=1
gpgcheck=0		'//Do not verify the signature of the package '
'View and copy the secret key on the server'
[root@server ftp]# ls centos7 	' Server view '
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

Step 7: at this time, the yum list has taken effect (you can install the software package and update related operations)

Update the package using yum update, including the kernel

yum upgrade updates packages only, not the kernel

(5) Package query

Query package
yum list [software name]
yum info [software name]
Yum search < keyword >
Querying package groups
yum grouplist [package group name]
Yum groupinfo < package group name >

(6) Installing and upgrading software

yum install [software name]
Yum groupinstall < package group name >

Upgrade software

yum update

yum groupdate

Update the package using yum update, including the kernel

yum upgrade updates packages only, not the kernel

Uninstall software

Yum remove < software name >
Yum groupremove < package group name >

2, NFS shared storage service

1. NFS Network File System

Server for NFS allows PC to mount the directory shared by server for NFS in the network to the file system at the local end. From the perspective of the local end system, the directory of the remote host is like its own disk partition, which is very convenient to use;

2. NFS mount principle


As shown above:

After we set up A shared directory /home/public in server for NFS, other NFS clients that have access to server for NFS can mount this directory to A mount point of their file system, which can be defined by themselves. As shown in the above figure, the directories mounted by client A and client B are different. After mounting, we can see all the data of the server /home/public locally. If the client configured on the server side is read-only, the client can only be read-only. If read / write is configured, the client can read / write. After mounting, NFS client views disk information command: \df – h.

Since NFS transmits data between the server and the client through the network, the corresponding network port is required for data transmission between the two. Which port does the NFS server use for data transmission? Basically, the port of NFS server is set at 2049, but the file system is very complex. Therefore, NFS has other programs to start additional ports. These additional ports used to transmit data are randomly selected, which are ports smaller than 1024; Since it is random, how does the client know which port is used by the NFS server? At this time, it needs to be implemented through the remote procedure call (RPC) protocol!

3. Configure services for NFS

NFS software is very simple. The main configuration file: /etc/exports is empty by default. If there is no such file, you can use vim to actively create it. As for the setup of NFS server, it is also very simple. As long as you edit the main configuration file /etc/exports, start rpcbind (if it has been started, do not restart), and then start NFS, NFS will succeed

(1) Step 1: format and mount the newly added hard disk

The steps to format the disk are omitted. If you have any questions, please check my previous blog

[root@server ~]# vim /etc/fstab
[root@server ~]# mount -a
[root@server ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs        20G  4.1G   16G  21% /
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   52M   10G   1% /home
/dev/sda1      xfs       6.0G  174M  5.9G   3% /boot
tmpfs          tmpfs     183M  8.0K  183M   1% /run/user/42
tmpfs          tmpfs     183M     0  183M   0% /run/user/0
/dev/sdb1      xfs        20G   33M   20G   1% /mnt

(2) Step 2: install NFS utils rpcbind and set it to start automatically

[root@server ~]# yum install nfs-utils rpcbind -y
[root@server ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@server ~]# systemctl enable rpcbind.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/rpcbind.service to /usr/lib/systemd/system/rpcbind.service.

(3) Step 3: set the shared directory, start the service and close the protective wall

[root@server ~]# vim /etc/exports
/mnt    192.168.133.0/24(rw,sync,no_root_squash)
[root@server ~]# systemctl start nfs
[root@server ~]# systemctl start rpcbind
[root@server ~]# netstat -ntap | grep rpc
tcp        0      0 0.0.0.0:35312           0.0.0.0:*               LISTEN      14124/rpc.statd     
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      14125/rpc.mountd    
tcp6       0      0 :::20048                :::*                    LISTEN      14125/rpc.mountd    
tcp6       0      0 :::58102                :::*                    LISTEN      14124/rpc.statd  
[root@server ~]# systemctl stop firewalld.service 
[root@server ~]# setenforce 0

NFS configuration permission settings, that is, the parameter set in brackets () in the configuration format of /etc/exports file;

(4) Step 4: view the NFS shared directory published locally

[root@server ~]# showmount -e
Export list for server:
/mnt 192.168.110.0/24

(5) Step No: enter the client, close the firewall, and install the httpd service

[root@client ~]# systemctl stop firewalld.service 
[root@client ~]# setenforce 0
[root@client ~]# yum install httpd -y

(6) Step 6: manually mount NFS shared directory or use automatic mount

Here, the widget is attached to the apache Web page configuration file >_<

[root@client ~]# mount 192.168.110.133:/mnt /var/www/html 'temporary mount'
[root@client ~]# df -hT
Filesystem           Type      Size  Used Avail Use% Mounted on
/dev/sda2            xfs        20G  4.1G   16G  21% /
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   12K  183M   1% /run/user/42
tmpfs                tmpfs     183M     0  183M   0% /run/user/0
192.168.110.133:/mnt nfs4       20G   32M   20G   1% /var/www/html

[root@client ~]# umount /var/www/html 'UN mount'
[root@client ~]# vim /etc/fstab 'change to permanent mount'
192.168.110.133:/mnt    /var/www/html   nfs     defausts,_netdev        0 0
[root@client ~]# mount -a 'check the mounting status and do not remind that the mounting is successful by default'
[root@client ~]# df -hT
Filesystem           Type      Size  Used Avail Use% Mounted on
/dev/sda2            xfs        20G  4.1G   16G  21% /
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   12K  183M   1% /run/user/42
tmpfs                tmpfs     183M     0  183M   0% /run/user/0
192.168.110.133:/mnt nfs4       20G   32M   20G   1% /var/www/html

(7) Step 7: configure the httpd web page and start the service

[root@client ~]# cd /var/www/html 'enter apache Web page configuration file'
[root@client html]# ls
[root@client html]# VIM index HTML 'edit profile'
<h1>this is nfs web </h1>
[root@client html]# systemctl start httpd.service 
Log in with the web address of the client





Tags: Linux Operation & Maintenance CentOS

Posted by Aleirita on Tue, 31 May 2022 09:25:31 +0530