初始化环境
Script 1
关闭防火墙、selinux、完全关闭swap。
#!/bin/bash
# Maintainer: zhengmingyue
# Email: 348063831@qq.com
echo -e "The script is used to setting Centos Linux 7 or Centos Linux 8. \n \
e.g. Close firewalld, set selinux and so on. \n"
# Close firewall.
systemctl disable firewalld --now >> /dev/null
# Close selinux.
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
stat=`grep 'SELINUX=disabled' /etc/selinux/config`
echo -e "Selinux configuration: \n ${stat}. \nEnforcing: \n `getenforce` \n"
# Deactivate swap partion.
swapoff -a >> /dev/null
sed -ri 's/.*swap.*/#&/' /etc/fstab
echo -e "Swap partion information:"
echo "Swap: `free -m | grep Swap`"
cat /etc/fstab | grep swap
Script 2
设置本地源,需要将系统镜像挂载到光驱设备/dev/sr0。
注意下方我是直接删除/etc/yum.repos.d/下的所有repo,如有重要repo,请备份。
#!/bin/bash
# Maintainer: zhengmingyue
# Email: 348063831@qq.com
echo "The script is used to set yum local repo CentOS Linux 7 or 8."
VERSION_ID=`cat /etc/os-release | grep "VERSION_ID" | awk -F"=|\"|=\"| " '{ print $2 }'`
rm -rf /etc/yum.repos.d/*
touch /etc/yum.repos.d/Local.repo
mkdir -pv /mnt/cdrom
mount /dev/sr0 /mnt/cdrom
if [ $VERSION_ID == "7" ]
then
cat > /etc/yum.repos.d/Local.repo << EOF
[Local]
name=CentOS-Local
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0
EOF
elif [ $VERSION_ID == "8" ]
then
cat > /etc/yum.repos.d/Local.repo << EOF
[Base]
name=CentOS-Base
baseurl=file:///mnt/cdrom/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=CentOS-AppStream
baseurl=file:///mnt/cdrom/AppStream
enabled=1
gpgcheck=0
EOF
Script 3
安装一些软件的脚本,可以根据不同的系统版本安装。建议在Script 2脚本之后运行,或者自行保证源可用。
if分支下面的安装命令,请根据自己需求,自行更改。
#!/bin/bash
# Maintainer: zhengmingyue
# Email: 348063831@qq.com
echo "The script is used to install some tools for minimal installation CentOS Linux 7 or CentOS Linux 8."
VERSION_ID=`cat /etc/os-release | grep "VERSION_ID" | awk -F"=|\"|=\"| " '{ print $2 }'`
echo "Install something tools"
if [ $VERSION_ID == "7" ]
then
yum install -y bash-completion net-tools curl lsof vim chrony
elif [ $VERSION_ID == "8" ]
then
dnf install -y bash-completion net-tools curl lsof vim chrony
fi
# Installed bash-completion cloud used key tab to supplement command,
# net-tools could used ifconfig and or so.
# Curl and lsof is tool for system.
# Chrony is time synchronization service. I suggest that each cluster install this service.Can use chrony script.