在CentOS Stream 8上搭建服务器涉及多个步骤,包括安装操作系统、配置网络、安装必要的软件包等。以下是一个基本的指南:
ip addr show或 ifconfig命令查看当前系统的网络接口信息。/etc/sysconfig/network-scripts/目录下,每个网卡对应一个以 ifcfg-开头的配置文件。BOOTPROTO的值从 dhcp改为 static。ONBOOT的值为 yes。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" vi编辑器中,按 Esc键,然后输入 :wq并按回车保存并退出。NetworkManager服务,使更改生效:sudo systemctl restart NetworkManager 或者,如果您使用的是 NetworkManager命令行工具,可以使用:
sudo nmcli con reload eth0 sudo nmcli con up eth0 ip addr命令查看网卡的IP地址信息,确保静态IP地址已正确配置。ping命令测试网络连接,例如 ping一个外部IP地址或域名。nslookup或 dig命令检查DNS解析是否正常。sudo dnf update sudo dnf install google-chrome gedit sudo dnf install nginx 安装结束后,使用 nginx -v命令查看是否安装成功。
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; } } } sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload example.com的虚拟主机: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> sudo yum install certbot python2-certbot-apache -y sudo certbot --apache sudo systemctl enable httpd yum-cron工具进行自动更新,是保持服务器稳定运行的关键。以上步骤是在CentOS Stream 8上进行服务器搭建的基本流程,具体的安装可能会因为硬件配置、网络环境等因素有所不同。在进行任何配置更改后,建议重启相关服务或系统以使更改生效。如果在配置过程中遇到问题,可以参考相关的技术文档或寻求专业人士的帮助。