手动部署LNMP环境debian

更新安装依赖:

apt update && apt install -y build-essential curl gcc g++ make perl zlib1g-dev wget tar unzip libpcre2-dev vim

校准时间:

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && date -R

卸载并清除 Apache2 及其配置文件

apt purge apache2 apache2-utils apache2-bin apache2-data

下载/解压 nginx

wget -nc --no-check-certificate https://github.com/openssl/openssl/releases/download/openssl-4.1.0/openssl-4.1.0.tar.gz && tar -zxvf openssl-4.1.0.tar.gz

下载nginx

wget -nc --no-check-certificate https://nginx.org/download/nginx-1.30.6.tar.gz && tar -zxvf nginx-1.30.6.tar.gz

删除文件包:

rm -rf nginx-1.30.6.tar.gz && rm -rf openssl-4.1.0.tar.gz && cd nginx-1.30.6

添加编译插件:

./configure \
  --user=www-data \
  --group=www-data \
  --prefix=/usr/local/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --pid-path=/var/run/nginx.pid \
  --with-threads \
  --with-file-aio \
  --with-http_ssl_module \
  --with-http_v2_module \
  --with-http_v3_module \
  --with-http_realip_module \
  --with-http_gzip_static_module \
  --with-http_stub_status_module \
  --with-stream \
  --with-stream_ssl_module \
  --with-stream_realip_module \
  --with-stream_ssl_preread_module \
  --with-compat \
  --with-openssl-opt="no-tests" \
  --with-cc-opt='-march=native -O3' \
  --with-openssl=../openssl-4.1.0

编译/安装 nginx

make -j$(nproc) && make install

配置nginx服务:

cat >/usr/lib/systemd/system/nginx.service << "EOF"
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

创建日志和配置文件目录所有权

cd && mkdir -p /etc/nginx/conf.d /etc/nginx/ssl

安装wordpress

cd /usr/local/nginx/html && wget https://cn.wordpress.org/latest-zh_CN.zip && unzip latest-zh_CN.zip && mv wordpress/* /usr/local/nginx/html && rm -rf latest-zh_CN.zip wordpress && cd

添加权限和删除编译文件夹

rm -rf nginx-1.30.6  openssl-4.1.0 && chown -R www-data:www-data /usr/local/nginx/html

目录权限设为 755,文件权限设为 644

find /usr/local/nginx/html -type d -exec chmod 755 {} \;
find /usr/local/nginx/html -type f -exec chmod 644 {} \;

修改nginx.conf 中的两行配置

sed -i -e 's/#user\s\+nobody;/user www-data;/' -e 's/worker_processes\s\+1;/worker_processes auto;/' /etc/nginx/nginx.conf

添加dhparam

curl https://ssl-config.mozilla.org/ffdhe2048.txt > /etc/nginx/ssl/dhparam

申请证书

nginx配置生成地址

安装 php:

apt install -y php php-fpm php-mysql php-gd php-mbstring php-xml php-curl php-opcache php-cli && php --version

安装MariaDB:

apt install -y mariadb-server mariadb-client && mariadb --version

mysql或MariaDB安全加固:
会设置密码,界面1直接回车,剩的都选Y:

mariadb-secure-installation

root登录:

mariadb -u root -p

查看当前的数据库:

show databases;

创建数据库非root用户名密码:

create database wordpress; create user name@localhost identified by 'password';

授予权限:

grant all privileges on wordpress.* to name@localhost; flush privileges;

退出:

exit

开启BBR:

cat >>/etc/sysctl.conf << FOE
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
# 1. 全局最大缓冲区限制(平衡型:32MB)
net.core.wmem_max = 33554432
net.core.rmem_max = 33554432
# 2. 系统的整体默认缓冲区大小(小内存建议降至 256KB,节省初始开销)
net.core.wmem_default = 262144
net.core.rmem_default = 262144
# 3. TCP 自动调优窗口范围(最大限制在 32MB)
# [最小值, 默认值, 最大值]
net.ipv4.tcp_wmem = 4096 65536 33554432
net.ipv4.tcp_rmem = 4096 87380 33554432
# 4. 必须开启的 TCP 特性
net.ipv4.tcp_window_scaling = 1
FOE

刷新内核参数使配置立即生效

sysctl -p && lsmod | grep bbr

加载单元:

systemctl daemon-reload

检查最终生效的值

sysctl net.ipv4.tcp_rmem

开启nginx:

systemctl start nginx

开启状态:

systemctl status nginx

开机自动启动:

systemctl enable nginx

重新启动:

systemctl restart nginx

停止nginx:

service nginx stop

开启php:

systemctl start php8.4-fpm

开启状态:

systemctl status php8.4-fpm

开机自动启动:

systemctl enable php8.4-fpm

重新启动:

systemctl restart php8.4-fpm

开启mysql:

systemctl start mariadb.service

开启状态:

systemctl status mariadb.service

开机自动启动:

systemctl enable mariadb.service

重新启动:

systemctl restart mariadb.service

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注