最简单的

  • 适合用于跟着别人的教程学东西
  • 去除开机免密码登录
  • 调整开机等待时间
  • 关闭 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

  1. chkconfig NetworkManager off
  2. service NetworkManager stop
  3. setenforce 0
  4. sed -i 's,^SELINUX=.*$,SELINUX=disabled,' /etc/selinux/config

} __set_config

__set_time() {

  1. # 设置时区
  2. rm -rf /etc/localtime
  3. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

} __set_time

  1. <a name="PXVrj"></a>
  2. # 升级内核
  3. ```bash
  4. __kernel_update() {
  5. #导入公钥
  6. rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
  7. #添加YUM源
  8. yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
  9. #安装更新长期支持版内核
  10. yum install -y --enablerepo=elrepo-kernel kernel-lt kernel-lt-devel
  11. #更新GRUB配置使用新内核启动
  12. #查看配置中的所有内核版本
  13. awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
  14. _modify=$(awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg | head -1 | grep "$(uname -r)" -c)
  15. if ((_modify != 1)); then
  16. #设置新内核为默认启动项,默认情况下新内核序号为0
  17. grub2-set-default 0
  18. #更新配置
  19. grub2-mkconfig -o /boot/grub2/grub.cfg
  20. # 设置开机免输入密码
  21. sed -i 's,^ExecStart=.*$,ExecStart=-/sbin/agetty --autologin root --noclear %I,' /etc/systemd/system/getty.target.wants/getty@tty1.service
  22. sed -i 's,^ExecStart=.*$,ExecStart=-/sbin/agetty --autologin root --noclear %I,' /lib/systemd/system/autovt@.service
  23. # 修改系统启动等待时间
  24. sed -i 's,timeout=5$,timeout=2,' /boot/grub2/grub.cfg
  25. sed -i 's,timeout=5$,timeout=2,' /boot/efi/EFI/centos/grub.cfg
  26. sync
  27. # reboot
  28. fi
  29. }
  30. __kernel_update

安装基础软件包

  1. __install_app() {
  2. yum clean all
  3. yum makecache fast
  4. yum -y update
  5. yum groups install -y base
  6. yum -y install \
  7. vim git jq bc tree unzip zip dos2unix sysstat psmisc lsof sshpass expect \
  8. vnstat htop perf dstat glances \
  9. hdparm libaio-devel log4cplus log4cplus-devel lshw ntp xfsprogs-devel \
  10. net-tools bridge-utils nfs-utils telnet lrzsz \
  11. bash-completion bash-completion-extras
  12. }
  13. __install_app

二维码生成工具

  1. qrencode