下面按**“从零在 CentOS Stream 8 上搭建一台可用服务器”的思路给你讲,覆盖系统初始化 → 网络 → 常用服务(Web / SSH / 防火墙)→ 基础安全**。你可以按需取用。
dnf makecache
dnf update -y
dnf install -y vim wget curl net-tools bash-completion
hostnamectl set-hostname server01
编辑:
vim /etc/sysconfig/network-scripts/ifcfg-ens192
示例:
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
ONBOOT=yes
重启网络:
nmcli c reload
nmcli c up ens192
dnf install -y openssh-server
systemctl enable --now sshd
编辑 /etc/ssh/sshd_config:
PermitRootLogin no
PasswordAuthentication no
使用密钥登录:
ssh-keygen
ssh-copy-id user@server
CentOS Stream 8 默认使用 firewalld
systemctl enable --now firewalld
firewall-cmd --state
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
dnf install -y nginx
systemctl enable --now nginx
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
浏览器访问:
http://服务器IP
dnf install -y mariadb-server
systemctl enable --now mariadb
mysql_secure_installation
查看状态:
getenforce
如需排错:
setenforce 0 # 临时关闭
生产环境不建议永久关闭
dnf install -y dnf-automatic
systemctl enable --now dnf-automatic.timer
| 用途 | 推荐方案 |
|---|---|
| 网站 | Nginx + PHP + MariaDB |
| API | Nginx + Node.js / Python |
| 内网服务 | SSH + Firewalld |
| 生产服务器 | SELinux + 防火墙 + 非 root |
我可以继续帮你:
你这台服务器准备 干啥用的?