最简单的
- 适合用于跟着别人的教程学东西
- 去除开机免密码登录
- 调整开机等待时间
- 关闭 SELINUX
- 调整时区 ```bash
__set_boot(){ sed -i ‘s,^ExecStart=.$,ExecStart=-/sbin/agetty —autologin root —noclear %I,’ /etc/systemd/system/getty.target.wants/getty@tty1.service sed -i ‘s,^ExecStart=.$,ExecStart=-/sbin/agetty —autologin root —noclear %I,’ /lib/systemd/system/autovt@.service
修改CentOS 选择内核界面的选择时间, 减少系统启动等待时间
sed -i ‘s,timeout=5$,timeout=1,’ /boot/grub2/grub.cfg 2>/dev/null sed -i ‘s,timeout=5$,timeout=1,’ /boot/efi/EFI/centos/grub.cfg 2>/dev/null } __set_boot
__set_config() { firewall-cmd —state systemctl stop firewalld.service systemctl disable firewalld.service
chkconfig NetworkManager off
service NetworkManager stop
setenforce 0
sed -i 's,^SELINUX=.*$,SELINUX=disabled,' /etc/selinux/config
} __set_config
__set_time() {
# 设置时区
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
} __set_time
<a name="PXVrj"></a>
# 升级内核
```bash
__kernel_update() {
#导入公钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#添加YUM源
yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
#安装更新长期支持版内核
yum install -y --enablerepo=elrepo-kernel kernel-lt kernel-lt-devel
#更新GRUB配置使用新内核启动
#查看配置中的所有内核版本
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
_modify=$(awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg | head -1 | grep "$(uname -r)" -c)
if ((_modify != 1)); then
#设置新内核为默认启动项,默认情况下新内核序号为0
grub2-set-default 0
#更新配置
grub2-mkconfig -o /boot/grub2/grub.cfg
# 设置开机免输入密码
sed -i 's,^ExecStart=.*$,ExecStart=-/sbin/agetty --autologin root --noclear %I,' /etc/systemd/system/getty.target.wants/getty@tty1.service
sed -i 's,^ExecStart=.*$,ExecStart=-/sbin/agetty --autologin root --noclear %I,' /lib/systemd/system/autovt@.service
# 修改系统启动等待时间
sed -i 's,timeout=5$,timeout=2,' /boot/grub2/grub.cfg
sed -i 's,timeout=5$,timeout=2,' /boot/efi/EFI/centos/grub.cfg
sync
# reboot
fi
}
__kernel_update
安装基础软件包
__install_app() {
yum clean all
yum makecache fast
yum -y update
yum groups install -y base
yum -y install \
vim git jq bc tree unzip zip dos2unix sysstat psmisc lsof sshpass expect \
vnstat htop perf dstat glances \
hdparm libaio-devel log4cplus log4cplus-devel lshw ntp xfsprogs-devel \
net-tools bridge-utils nfs-utils telnet lrzsz \
bash-completion bash-completion-extras
}
__install_app
二维码生成工具
qrencode