CentOS裝好后基本配置指南
1. 系統(tǒng)更新與升級
執(zhí)行yum update -y
升級所有軟件包,確保系統(tǒng)處于最新狀態(tài)。建議定期運(yùn)行此命令修復(fù)安全漏洞。
2. 設(shè)置主機(jī)名與時區(qū)
使用hostnamectl set-hostname your-hostname
修改主機(jī)名,通過timedatectl set-timezone Asia/Shanghai
同步時區(qū)。
3. 網(wǎng)絡(luò)配置優(yōu)化
編輯/etc/sysconfig/network-scripts/ifcfg-eth0
文件配置靜態(tài)IP,重啟網(wǎng)絡(luò)服務(wù)使用systemctl restart network
生效。
4. 安裝基礎(chǔ)工具包
yum install -y epel-release
yum install -y wget curl vim net-tools lsof htop
5. 防火墻規(guī)則配置
啟用firewalld服務(wù):systemctl enable --now firewalld
,開放SSH端口:firewall-cmd --permanent --add-port=22/tcp
。
6. 創(chuàng)建標(biāo)準(zhǔn)用戶賬戶
useradd username
passwd username
usermod -aG wheel username
7. SSH安全強(qiáng)化
編輯/etc/ssh/sshd_config
文件,禁用root登錄(PermitRootLogin no
)并限制密碼認(rèn)證(PasswordAuthentication no
)。
8. 配置自動更新機(jī)制
安裝yum-cron
并啟用服務(wù):systemctl enable --now yum-cron
,設(shè)置每日自動安裝安全更新。
9. SELinux策略調(diào)整
臨時切換模式:setenforce 0
,永久修改需編輯/etc/selinux/config
,建議保持enforcing
模式提升安全性。
10. 部署基礎(chǔ)服務(wù)環(huán)境
# 安裝Web服務(wù)器與數(shù)據(jù)庫
yum install -y httpd mariadb-server
systemctl enable --now httpd mariadb