温馨提示×

centos stream8怎么搭服务器

小樊
44
2026-10-26 10:34:01
栏目: 云计算

下面按**“从零在 CentOS Stream 8 上搭建一台可用服务器”的思路给你讲,覆盖系统初始化 → 网络 → 常用服务(Web / SSH / 防火墙)→ 基础安全**。你可以按需取用。


一、系统准备

1. 安装 CentOS Stream 8

  • 官方镜像:https://mirror.stream.centos.org
  • 安装时建议:
    • 最小安装(Minimal)
    • 设置静态 IP(生产推荐)
    • 创建普通用户 + 开启 sudo

2. 基础更新

dnf makecache
dnf update -y

3. 安装常用工具

dnf install -y vim wget curl net-tools bash-completion

二、网络与主机名

设置主机名

hostnamectl set-hostname server01

静态 IP(示例)

编辑:

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

三、远程管理(SSH)

1. 安装并启动

dnf install -y openssh-server
systemctl enable --now sshd

2. 安全建议

编辑 /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no

使用密钥登录:

ssh-keygen
ssh-copy-id user@server

四、防火墙(firewalld)

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

五、搭建 Web 服务器(Nginx 示例)

1. 安装

dnf install -y nginx
systemctl enable --now nginx

2. 防火墙放行

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

3. 测试

浏览器访问:

http://服务器IP

六、搭建数据库(MariaDB 示例)

dnf install -y mariadb-server
systemctl enable --now mariadb
mysql_secure_installation

七、基础安全加固

1. SELinux(默认开启)

查看状态:

getenforce

如需排错:

setenforce 0   # 临时关闭

生产环境不建议永久关闭

2. 自动更新(可选)

dnf install -y dnf-automatic
systemctl enable --now dnf-automatic.timer

八、常见服务器组合推荐

用途 推荐方案
网站 Nginx + PHP + MariaDB
API Nginx + Node.js / Python
内网服务 SSH + Firewalld
生产服务器 SELinux + 防火墙 + 非 root

九、你接下来可以告诉我

我可以继续帮你:

  • ✅ 搭建 LNMP
  • ✅ 配置 HTTPS(Let’s Encrypt)
  • ✅ 做 内网 / 公网服务器
  • ✅ 写 一键脚本
  • ✅ 针对 生产环境 hardening

你这台服务器准备 干啥用的?

0 踩