一、前言

新买的阿里云/腾讯云/华为云服务器默认环境杂乱、安全漏洞多、性能参数保守。所有服务器上线前必须做一次初始化,统一环境、提升性能、加固安全、方便后续运维。


二、新机初始化完整流程

更新系统 → 安装基础工具 → 关闭SELinux → 关闭防火墙/放行策略 → 优化文件句柄 → 优化swap → 设置主机名 → 时间同步


三、1. 更新系统并安装常用工具

yum update -y
yum install wget curl net-tools vim tree lrzsz telnet -y

四、2. 关闭SELinux(永久)

SELinux容易拦截服务权限,生产环境默认关闭

setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

五、3. 防火墙策略配置

云服务器优先使用云端安全组,本地防火墙可关闭

systemctl stop firewalld
systemctl disable firewalld

六、4. 设置主机名

hostnamectl set-hostname server01

七、5. 时间同步(必须配置)

服务器时间不一致会导致日志错乱、定时任务异常、数据库报错

yum install chrony -y
systemctl start chronyd
systemctl enable chronyd

八、6. 基础性能优化

文件句柄优化

echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf

优化swap内存交换

echo "vm.swappiness=10" >> /etc/sysctl.conf
sysctl -p

九、初始化总结

新机初始化四件套:装工具、关SELinux、时间同步、性能基础优化,所有云服务器必须执行,保证环境统一、稳定、安全。

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐