在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上進行服務器搭建的基本流程,具體的安裝可能會因為硬件配置、網絡環境等因素有所不同。在進行任何配置更改后,建議重啟相關服務或系統以使更改生效。如果在配置過程中遇到問題,可以參考相關的技術文檔或尋求專業人士的幫助。