架构与前置准备
单节点LNMP部署步骤
sudo apt install nginx -y && sudo systemctl enable --now nginxsudo apt install mariadb-server -y && sudo systemctl enable --now mariadb && sudo mysql_secure_installationsudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-gd php8.2-curl php8.2-mbstring php8.2-xml php8.2-zip php8.2-opcache -yserver {
listen 80 default_server;
root /var/www/html;
index index.php index.html;
location / { try_files $uri $uri/ =404; }
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht { deny all; }
}
sudo nginx -t && sudo systemctl reload nginxsudo systemctl restart php8.2-fpm<?php phpinfo(); ?>),访问 http://服务器IP/info.php 应看到 PHP 信息页。构建高可用集群
http {
upstream backend {
server 10.0.0.11:80;
server 10.0.0.12:80;
}
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
重载 Nginx 生效。也可使用 HAProxy 实现四层/七层负载均衡。server-id=1、log_bin,创建复制用户并授权;记录 SHOW MASTER STATUS 的 File/Position。server-id=2、relay_log,执行 CHANGE MASTER TO ... 指向主库,启动复制 START SLAVE;。安全与稳定性加固
部署与验证清单