1. 主机名设置
| |
| hostnamectl set-hostname testsrv-1 |
| |
| |
| cat <<EOF >>/etc/hosts |
| 192.168.166.8 testrv-1 |
| EOF |
2. SELinux 配置
| |
| sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config |
| |
| |
| setenforce 0 |
3. 防火墙配置
systemctl enable firewalld && systemctl restart firewalld
4. SSH 服务优化
加速SSH连接速度。
| |
| sed -i 's/^GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config |
| |
| |
| systemctl restart sshd |
| |
| |
| sed -i '/^#UseDNS yes/a\UseDNS no' /etc/ssh/sshd_config |
| |
| |
| systemctl restart sshd |
5. YUM 源配置
更新为阿里提供的软件源,加速软件下载及安装。
5.1 备份 YUM 源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
5.2 更新阿里云 YUM 源
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
5.3 生成缓存
yum makecache
6. 时间同步设置
这里我们以 NTP 配置为例。
6.1 NTP 安装
yum install -y ntp
6.2 系统时区设置
timedatectl set-timezone Asia/Shanghai
6.3 开启 NTP 同步
timedatectl set-ntp yes
6.4 配置文件修改
| |
| vim /etc/ntpd.conf |
| |
| server 192.168.166.23 iburst prefer |
| server ntp.aliyun.com iburst |
6.5 注册并启动 NTP 服务
systemctl enable ntpd && systemctl start ntpd
6.6 时间校准
[root@localhost ~]
6.7 时间服务状态查看
| [root@localhost ~] |
| Local time: Wed 2021-03-24 19:44:30 CST |
| Universal time: Wed 2021-03-24 11:44:30 UTC |
| RTC time: Wed 2021-03-24 11:44:29 |
| Time zone: Asia/Shanghai (CST, +0800) |
| NTP enabled: yes |
| NTP synchronized: yes |
| RTC in local TZ: no |
| DST active: n/a |
7. 系统服务优化
默认系统安装完成后有一些没有必要的服务,进行禁用或卸载操作,以最小化的原则,减少无必要服务的运行,可以提高系统的安全性。
8. 常用软件安装
根据自己使用的习惯,可以把一些常用的软件工具安装,便于后期的操作。
yum install -y wget lrzsz zip unzip tree vim net-tools telnet rsync
9. 内核版本升级
默认CentOS7.9的内核还是3.10版本,基于安全和场景的要求可以进行升级到当前最新的长期支持版。
9.1 RPM KEY 导入
rpm import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
9.2 YUM 安装
yum install -y https://www.elrepo.org/elrepo-release-7.0-6.el7.elrepo.noarch.rpm
9.3 安装内核
yum --disablerepo='*' --eanblerepo='elrepo-kernel' install -y kernel-lt
9.4 卸载旧版工具包
[root@localhost ~]
9.5 安装新版本工具包
[root@localhost ~]
9.6 内核引导顺序修改
| [root@localhost ~] |
| [root@localhost ~] |
9.7 默认引导内核确认
| [root@localhost ~] |
| /boot/vmlinuz-3.10.0-1160.95.1.el7.x86_64 |
9.8 重启系统
[root@localhost ~]
9.9 确认引导内核
| [root@localhost ~] |
| Linux 5.4.251-1.el7.elrepo.x86_64 |
查看返回信息,当前系统内核已经正确引导升级后的版本。
10. 操作系统更新
评论