CentOS7.x system configuration record

0 x00 Initialization###

CentOS7 initialization script: [May 8, 2020 09:09:54]

#! /bin/bash
# @ Desc:Initialization script after Centos7 installation
# @ Author: WeiyiGeek
# @ Time:May 6, 2020 11:04:42
# @ Version:1.0

echo -e "\e[32m#########\n#Network card configuration\n##########\e[0m"
sed -i 's/ONBOOT=no/ONBOOT=yes/g'/etc/sysconfig/network-scripts/ifcfg-ens192
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g'/etc/sysconfig/network-scripts/ifcfg-ens192
sed -i 's/BOOTPROTO=\"dhcp\"/BOOTPROTO=\"static\"/g'/etc/sysconfig/network-scripts/ifcfg-ens192
cat >>/etc/sysconfig/network-scripts/ifcfg-ens192 <<EOF
IPADDR=10.10.107.192
NETMASK=255.255.255.0
GATEWAY=10.10.107.1
EOF
service network restart
echo nameserver 223.6.6.6>>/etc/resolv.conf
echo -e"--[End of network card configuration]--"

echo -e "\e[32m#########\n#SSH service configuration\n#########\e[0m"
echo 'PermitRootLogin yes'>>/etc/ssh/sshd_config
echo 'PasswordAuthentication yes'>>/etc/ssh/sshd_config
systemctl restart sshd
echo "--[End of SSH service configuration]--"

echo -e "\e[32m#########\n#Yum source settings\n#########\e[0m"
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum update -y && yum upgrade -y &&  yum -y install epel*
echo "--[YUM replacement and update application software completed]--"

echo -e "\e[32m#########\n#System kernel version upgrade\n#########\e[0m"
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum -y install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
yum --disablerepo="*"--enablerepo=elrepo-kernel repolist
yum --disablerepo="*"--enablerepo=elrepo-kernel list kernel*
yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64 
awk -F \' '$1=="menuentry "{print i++" : " $2}' /etc/grub2.cfg
sudo grub2-set-default0
reboot
# yum -y --enablerepo=elrepo-kernel install kernel-ml-tools.x86_64 
# sudo grub2-set-default0

echo -e "\n############################\n#Install common operation and maintenance software\n####################################\n"
# Compile dependency
yum install -y gcc gcc-c++ openssl-devel bzip2-devel
# Conventional software
yum install -y nano vim net-tools tree wget dos2unix unzip htop ncdu bash-completion 
echo "--[Installation is complete]--"

echo -e "\n############################\n#bash terminal beautification\n####################################\n"
yum install -y git
git clone --depth=1 \
https://github.com/Bash-it/bash-it.git \
~ /.bash_it
cd !$ &&./install.sh -s

0 x01 basic configuration###

0. CentOS mirror source####

Official mirror list status address:

It is recommended to use Alibaba Cloud's source other release version equivalent: http://mirrors.aliyun.com/help/centos

Aliyun downloads the latest CentOS-Base.repo to /etc/yum.repos.d/

# Backup CentOS-Base.repo
$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

# Download update source
CentOS 5:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# Clear source data and generate mirror cache
yum clean all
yum makecache
yum update

Note: It is not recommended to use yum to delete software, because it will delete redundant dependent programs, which may cause accidents (operation and maintenance must be paid attention to)


1. CentOS7.x kernel upgrade process####

System environment: CentOS Linux release 7.6.1810 (Core)
Reason for the upgrade: When using Docker, I found that the minimum requirement for the Linux kernel version is 3.10 (this also happens to be the kernel version of CentOS 7.6), but some functions cannot be realized on this version.
Note: The kernel version of the online environment needs to be carefully selected according to the actual situation. The newer version may encounter more problems in the future;

There are two types of Linux kernels:

CentOS and Fedora are common Linux branches based on Redhat.

About the definition of kernel version:
Version nature: main branch version ml (mainline), stable version (stable), long-term maintenance version lt (longterm-long term support), kernel pre-release version (kernel pre-release version)

The version naming format is: ABC

A:Is the kernel version number: The version number will only change when the code and the concept of the kernel have changed significantly. There have been two changes in history:
The first time was 1 in 1994.Version 0, the second time was 2 in 1996.Version 0, the third time is 3 in 2011.Version 0 is released, but this time there is no major change in the concept of the kernel

B:Is the kernel major version number: the major version number is based on the traditional odd-Even system version number is assigned: odd number is development version, even number is stable version

C:It is the kernel minor version number: the minor version number will change when the kernel adds security patches, fixes bugs, implements new features or drives

Linux distribution kernel
Generally speaking, only the kernel downloaded and compiled from kernel.org is the official kernel; most Linux distributions provide self-maintained kernels, which can be upgraded through package management systems such as yum or rpm (warehouse upgrade kernel);

Major Linux distributions (RedHat, Ubuntu, CentOS, etc.) integrate a series of other software on the basis of the kernel and release them according to their own version rules; use uname -r to distinguish whether you are using the official kernel or the Linux distribution kernel. Anything behind the line indicates that this is not an official kernel;
For example: 3.10.0-514.26.2.el7.x86_64, indicating that the corresponding Linux kernel version is 3.10, and 514 is the number of the release rule;

Virtual file system
Kernel space and user space can communicate through the /proc virtual file system; the /proc directory contains some directories and virtual files, which can present kernel information to users or send information from user space to the kernel.

[[ email protected]~]# cat /proc/version
Linux version 3.10.0-957.10.1.el7.x86_64([email protected])(gcc version 4.8.520150623(Red Hat 4.8.5-36)(GCC)) #1 SMP Mon Mar 1815:06:45 UTC 2019

cpuinfo: Identifies the type and speed of the processor
pci: Display devices found on the PCI bus
modules: modules currently loaded into the kernel
version: system version and kernel version
#1. View current and upgradeable versions
yum list kernel
Installed Packages
kernel.x86_64  3.10.0-957.el7         @anaconda
Available Packages
kernel.x86_64  3.10.0-957.5.1.el7     updates  

#2 upgrade
yum update kernel -y 

#3. Restart and check
reboot   
uname -r
#1. Update the warehouse first
yum -y update

#2. Enable ELRepo repository
# The ELRepo repository is a community-based enterprise-level Linux repository, providing support for RedHat Enterprise(RHEL)And other RHEL-based Linux distributions (CentOS, Scientific, Fedora, etc.) support.
# ELRepo focuses on hardware-related software packages, including file system drivers, graphics card drivers, network drivers, sound card drivers and camera drivers, etc.
##- - The enablerepo option enables the specified repository on the CentOS system,The default is elrepo, here elrepo is used-kernel replacement
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum -y install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm  #Centos 6 YUM source

#3. Load elrepo-kernel metadata
yum --disablerepo="*"--enablerepo=elrepo-kernel repolist

#4. After the repository is enabled, you can use the following command to list the available kernel-related packages
yum --disablerepo="*"--enablerepo=elrepo-kernel list kernel*
yum --disablerepo="*"--enablerepo="elrepo-kernel" list available

# Long-term maintenance version lt is 4.4. The latest mainline stable version ml is 5.0
# elrepo-kernel                       |2.9 kB     00:00
# elrepo-kernel/primary_db              |1.8 MB   00:05
# Available Packages
# kernel-lt.x86_64         4.4.179-1.el7.elrepo elrepo-kernel
# kernel-lt-devel.x86_64   4.4.179-1.el7.elrepo elrepo-kernel
# kernel-lt-doc.noarch     4.4.179-1.el7.elrepo elrepo-kernel
# kernel-lt-headers.x86_64 4.4.179-1.el7.elrepo elrepo-kernel
# kernel-lt-tools.x86_64   4.4.179-1.el7.elrepo elrepo-kernel
# kernel-lt-tools-libs.x86_64 4.4.179-1.el7.elrepo elrepo-kernel
# kernel-lt-tools-libs-devel.x86_64 4.4.179-1.el7.elrepo elrepo-kernel
# kernel-ml.x86_64         5.0.10-1.el7.elrepo  elrepo-kernel
# kernel-ml-devel.x86_64   5.0.10-1.el7.elrepo  elrepo-kernel
# kernel-ml-doc.noarch     5.0.10-1.el7.elrepo  elrepo-kernel
# kernel-ml-headers.x86_64 5.0.10-1.el7.elrepo  elrepo-kernel
# kernel-ml-tools.x86_64   5.0.10-1.el7.elrepo  elrepo-kernel
# kernel-ml-tools-libs.x86_64
#       5.0.10- 1. el7.elrepo  elrepo-kernel
# kernel-ml-tools-libs-devel.x86_64
#       5.0.10- 1. el7.elrepo  elrepo-kernel
# perf.x86_64              5.0.10-1.el7.elrepo  elrepo-kernel
# python-perf.x86_64       5.0.10-1.el7.elrepo  elrepo-kernel

#5. We need to install the latest mainline stable kernel, use the following command:(In the future, this machine can be upgraded to the latest stable version by running this sentence directly after upgrading the kernel.)
yum --disablerepo="*"--enablerepo=elrepo-kernel install  kernel-ml.x86_64  -y

#6. Remove old and install new version toolkit
yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64  -y
yum --disablerepo="*"--enablerepo=elrepo-kernel install kernel-ml-tools.x86_64  -y
# Delete the old kernel (optional) There are two ways to delete the kernel: through the yum remove command or through yum-utils tool.
# rpm -qa | grep kernel  #Delete the RPM package of the old kernel
# yum remove [The package is queried above]
# If the installed kernel is not more than 3 yum-The utils tool will not delete any of them. Only when there are more than 3 kernels installed will the old kernel be deleted automatically.
# yum install yum-utils #Installation tool
# package-cleanup --oldkernels  #Delete tool

#7. complete in one step
yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64

After the kernel is upgraded, the current kernel is still the default version, and the kernel version insertion sequence needs to be modified:

#8. We can view the default boot sequence through commands, and then modify the default kernel version in grub:
$ awk -F \' '$1=="menuentry "{print i++" : " $2}' /etc/grub2.cfg
0: CentOS Linux(4.20.12-1.el7.elrepo.x86_64)7(Core)1: CentOS Linux(3.10.0-957.5.1.el7.x86_64)7(Core)2: CentOS Linux(3.10.0-957.el7.x86_64)7(Core)3: CentOS Linux(0-rescue-ca0f6fb3c5f24478abc0a2e275281d7a)7(Core)

# Description:
# - The default new kernel is inserted from the beginning, the default startup sequence is also from 0 (the current sequence has not yet taken effect) or use
# - Which file/etc/grub2.cfg and/boot/grub2/grub.cfg content is consistent
$ grep "^menuentry"/boot/grub2/grub.cfg | cut -d "'"-f2
CentOS Linux(4.20.12-1.el7.elrepo.x86_64)7(Core)
CentOS Linux(3.10.0-957.5.1.el7.x86_64)7(Core)
CentOS Linux(3.10.0-957.el7.x86_64)7(Core)
CentOS Linux(0-rescue-ca0f6fb3c5f24478abc0a2e275281d7a)7(Core)

#9. View the current actual startup sequence
$grub2-editenv list
saved_entry=CentOS Linux(3.10.0-957.5.1.el7.x86_64)7(Core)

#10. Set default startup
sudo grub2-set-default'CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)'#Way 1
sudo grub2-set-default0  #Way 2
grub2-editenv list
saved_entry=CentOS Linux(4.20.12-1.el7.elrepo.x86_64)7(Core)

# The new kernel can be seen from the above(5.0.10)The current position is 0, the original kernel(3.10.0)The current position is 1, so if we want to take effect the latest kernel, we also need to modify the boot sequence of the kernel to 0:
# vim /etc/default/grub
# GRUB_DEFAULT =0
# Note: The changed files in Centos 6 are the same. Use the command to determine the location of the new kernel, and then change the parameter default to 0.
# Then run grub2-mkconfig command to re-create the kernel configuration, as follows:
# grub2-mkconfig -o /boot/grub2/grub.cfg

#11. Restart after modifying the default kernel version in grub
reboot

WeiyiGeek.grub

Supplementary note:

grub2-set-default0

# Traditional startup method
grub2-mkconfig -o /boot/grub2/grub.cfg
grubby --default-kernel

# UEFI boot method
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

Method 2:

# For some servers that cannot access the Internet or need to install a specific version of the kernel, we can download and install the rpm package of the kernel image. The download address is as follows:
Download the specified version of the kernel: http://rpm.pbone.net/index.php3?stat=3&limit=1&srodzaj=3&dl=40&search=kernel
Download the specified version of the kernel-devel:http://rpm.pbone.net/index.php3?stat=3&limit=1&srodzaj=3&dl=40&search=kernel-devel

Official Centos 6: http://elrepo.org/linux/kernel/el6/x86_64/RPMS/
Official Centos 7: http://elrepo.org/linux/kernel/el7/x86_64/RPMS/
historic version:http://mirror.rc.usf.edu/elrepo/kernel/el7/x86_64/RPMS/
historic version:http://ftp.osuosl.org/pub/elrepo/kernel/el7/x86_64/RPMS/

Download and upload the rpm package to the server, and install it with the following command:
# yum -y install kernel-ml-devel-4.12.4-1.el7.elrepo.x86_64.rpm 
# yum -y install kernel-ml-4.12.4-1.el7.elrepo.x86_64.rpm
# rpm -ivh kernel-ml-headers-5.2.4-1.el7.elrepo.x86_64.rpm
# rpm -ivh kernel-ml-devel-5.2.4-1.el7.elrepo.x86_64.rpm

Method 3:
You can also compile and install the source code package. This method is highly customizable but also more complicated. If you need it, you can find the information and install it yourself. Only the download address of the kernel source package of each system version is given below: https://www.kernel.org/pub/linux/kernel/

supplement:


2. CentOS7.x network card name change

System environment: CentOS Linux release 7.6.1810 (Core)

**Default network card information: **

[[ email protected] network-scripts]# ip addr | grep "enp"2: enp0s3:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:46:9b:14 brd ff:ff:ff:ff:ff:ff
3: enp0s8:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:36:63:b1 brd ff:ff:ff:ff:ff:ff
4: enp0s9:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:0b:01:7d brd ff:ff:ff:ff:ff:ff

Purpose: Change the network card name from enp0s3/8/9 above to eth0/1/2, the following is the configuration process:

# Network card configuration directory
cd /etc/sysconfig/network-scripts
#1. Change the name of the network card (ifcfg is left in the directory-File, will be deleted by default)
[[ email protected] network-scripts]# ls ifcfg-*
ifcfg-eth0  ifcfg-eth1  ifcfg-eth2  ifcfg-lo

#2. Modify the configuration file of each network card
sed -i 's/NAME=enp0s3/NAME=eth1/g' ifcfg-eth1
sed -i 's/DEVICE=enp0s3/DEVICE=eth1/g' ifcfg-eth1

sed -i 's/NAME=enp0s3/NAME=eth2/g' ifcfg-eth2
sed -i 's/DEVICE=enp0s3/DEVICE=eth2/g' ifcfg-eth2

#3. shut down"Consistent network device nomenclature&quot;
cp /etc/sysconfig/grub /etc/sysconfig/grub.bak
In GRUB_CMDLINE_LINUX add net.ifnames=0 biosdevname=0

# Update GRUB and kernel configuration after modification
$ grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image:/boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image:/boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image:/boot/vmlinuz-0-rescue-a21bd1at			810ca4597ae7f6a7c26299389
Found initrd image:/boot/initramfs-0-rescue-a21bd1a810ca4597ae7f6a7c26299389.img
done

#4. Add device rule profile
# modify/etc/udev/rules.d/70-persistent-net.rules, create a new file without the file
# Note that the MAC address matches the NAME (you can use ip addr to view)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:46:9b:14", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:36:63:b1", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:0b:01:7d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

#5. After the configuration is complete, restart the system
$reboot  #After restarting ip addr to view the modified network card information
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether 08:00:27:46:9b:14 brd ff:ff:ff:ff:ff:ff
 inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
3: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether 08:00:27:36:63:b1 brd ff:ff:ff:ff:ff:ff
4: eth2:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether 08:00:27:0b:01:7d brd ff:ff:ff:ff:ff:ff

WeiyiGeek.grub modification

  1. Script changes 1234567891011121314151617181920#!/bin/bash#function RENMAE_NIC(){ local _NICNAME=Extra open brace or missing close braceUndefined control sequence \eNICNAMEsed−is/"NAME=.∗NICNAMEsed−is/"DEVICE=.∗NICNAMEsed−i′ /IPV6/d′/etc/sysconfig/network−scripts/ifcfg−{_NICNAME} mv /etc/sysconfig/network-scripts/ifcfg-NICNAME/etc/sysconfig/network−scripts/ifcfg−eth0sed−is/′rhgbquiet"

3. Forgot to change the CentOS7.x password####

Way 1:

WeiyiGeek.

**Method 2: **

WeiyiGeek.centos7 password reset


4. The account is locked and enters the system emergency mode to clear the number of failed logins####

Process steps:

WeiyiGeek.

n. Compilation error solution collection
  1. Resolve error: the HTTP XSLT module requires the libxml2/libxslt error
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
  1. Solve error: the HTTP image filter module requires the GD library. error
yum -y install gd-devel
  1. Solve error: the GeoIP module requires the GeoIP library. error
yum -y install GeoIP GeoIP-devel GeoIP-data
  1. Solve error: the Google perftools module requires the Google perftools error
yum -y install gperftools
  1. Solve error: libatomic_ops library was not found. Error
yum -y install libuuid-devel libblkid-devel libudev-devel fuse-devel libedit-devel libatomic_ops-devel
  1. Solve the error trying to exec'cc1plus': execvp: No such file or directory error
yum -y install gcc-c++
  1. Resolve error: [pool www] cannot get uid for user'www-data' error
groupadd www-data
useradd -g www-data www-data
  1. Resolve configure: error: mbed TLS libraries not found. error. Need to install mbedtls, tutorial: https://www.24kplus.com/linux/281.html

  2. Solve error: Cannot find OpenSSL's<evp.h> error

yum install openssl openssl-devel
ln -s /usr/lib64/libssl.so /usr/lib/
  1. Solve error: Libtool library used but'LIBTOOL' is undefined error
yum install libtool
  1. Solve exec: g++: not found error
yum -y update gcc
yum -y install gcc+ gcc-c++
  1. Solve configure: error: tss lib not found: libtspi.so error
yum install trousers-devel
  1. Resolve Can't exec "autopoint": No such file or directory error
yum install gettext gettext-devel gettext-common-devel
  1. Solve configure: error: libcrypto not found. error
yum remove openssl-devel
yum -y install openssl-devel
  1. Solve configure: error: Package requirements (libffi >= 3.0.0) were not met: No package'libffi' found error
yum install libffi-devel
  1. Solve fatal error: uuid.h: No such file or directory error
yum install e2fsprogs-devel uuid-devel libuuid-devel
  1. Solve configure: error: openssl lib not found: libcrypto.so error
yum install openssl-devel
  1. Solve tar (child): lbzip2: Cannot exec: No such file or directory error
yum -y install bzip2
  1. Solve configure: error: C++ preprocessor “/lib/cpp” fails sanity check error
yum install gcc-c++
  1. Solve configure: error: Please reinstall the BZip2 distribution error
yum install bzip2 bzip2-devel
  1. Solve configure: error: cURL version 7.15.5 or later is required to compile php with cURL support error
yum install curl-devel
  1. Solve configure: error: not found. Please provide a path to MagickWand-config or Wand-config program error
yum install ImageMagick-devel
  1. Solve configure: error: no acceptable C compiler found in $PATH error
yum install gcc
  1. Solve configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met: error
yum install libicu-devel
  1. Solve configure: error: Package requirements (sqlite3> 3.7.4) were not met: No package'sqlite3' found error
yum install sqlite-devel
  1. Solve configure: error: Package requirements (oniguruma) were not met: No package'oniguruma' found error
yum install oniguruma oniguruma-devel

Recommended Posts

CentOS8.x system configuration record
CentOS7.x system configuration record
Ubuntu 14.04 configuration record
Centos backend system setup record
cobbler automatic installation system (Centos7.X)
cobbler automatic installation system (Centos7.X)
CentOS7.x system root directory partition expansion
CentOS 7 system installation and configuration graphic tutorial
Centos7.6 operating system installation and optimization record