centos

centos stream8如何搭建服务器

小樊
41
2025-06-22 09:58:24
栏目: 云计算

在CentOS Stream 8上搭建服务器涉及多个步骤,包括安装操作系统、配置网络、安装必要的软件包等。以下是一个基本的指南:

安装CentOS Stream 8

  1. 下载ISO镜像
  1. 准备安装介质
  1. 创建虚拟机(可选)
  1. 启动安装程序
  1. 配置安装选项
  1. 完成安装

配置网络

  1. 查看网络接口信息
  1. 编辑网络配置文件
  1. 配置静态IP地址
IPADDR="192.168.1.100"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
DNS1="8.8.8.8"
DNS2="8.8.4.4"
  1. 保存并退出编辑器
  1. 重启网络服务
sudo systemctl restart NetworkManager

或者,如果您使用的是 NetworkManager命令行工具,可以使用:

sudo nmcli con reload eth0
sudo nmcli con up eth0
  1. 验证配置

安装必要的软件包

  1. 更新系统
sudo dnf update
  1. 安装常用软件
sudo dnf install google-chrome gedit
  1. 安装Web服务器(如Nginx)
sudo dnf install nginx

安装结束后,使用 nginx -v命令查看是否安装成功。

  1. 配置Web服务器
sudo nano /etc/nginx/nginx.conf

在文件中添加以下内容:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
notice;
pid /var/run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log main;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 65;
    gzip on;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen 80;
        server_name localhost;
        location / {
            root /usr/share/nginx/html;
            index index.html index.htm;
        }
    }
}
  1. 配置防火墙
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
  1. 配置虚拟主机(可选)
sudo nano /etc/nginx/conf.d/example.com.conf

在文件中添加以下内容:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html/example.com
    ServerName example.com
    ServerAlias www.example.com
    ErrorLog /var/log/nginx/example.com-error.log
    CustomLog /var/log/nginx/example.com-access.log combined
</VirtualHost>
  1. 配置SSL/TLS(可选)
sudo yum install certbot python2-certbot-apache -y
sudo certbot --apache
  1. 设置开机自启动
sudo systemctl enable httpd
  1. 服务器监控与维护

以上步骤是在CentOS Stream 8上进行服务器搭建的基本流程,具体的安装可能会因为硬件配置、网络环境等因素有所不同。在进行任何配置更改后,建议重启相关服务或系统以使更改生效。如果在配置过程中遇到问题,可以参考相关的技术文档或寻求专业人士的帮助。

0
看了该问题的人还看了