LNMP平台部署
目录
环境准备
LNMP部署
nginx服务主机
php服务主机
mysql服务主机
切换到 nginx服务主机
切换php服务主机
切换到访问页面
切换到nginx服务主机
环境准备
三台服务器:nginx php mysql
关闭防火墙
systemctl stop firewalld
关闭安全上下文
setenforce 0
修改主机host
hostnamectl set-hostname nginxhostnamectl set-hostname phphostnamectl set-hostname mysql
LNMP部署
nginx服务主机
主机ip:192.168.158.138
下载nginx服务
[root@nginx ~]# yum -y install nginx
修改配置文件
[root@nginx ~]# cd /etc/nginx/
[root@nginx nginx]# ls
conf.d koi-utf scgi_params
default.d koi-win scgi_params.default
fastcgi.conf mime.types uwsgi_params
fastcgi.conf.default mime.types.default uwsgi_params.default
fastcgi_params nginx.conf win-utf
fastcgi_params.default nginx.conf.default
[root@nginx nginx]# mv nginx.conf nginx.conf.bck
[root@nginx nginx]# cp nginx.conf.default nginx.conf
[root@nginx nginx]# vim nginx.confuser nginx; # 改为nginx
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}http {include 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 logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ { #使用正则匹配所有以.php结尾的请求root html; #访问页面路径 fastcgi_pass 192.168.158.156:9000; #表示将所有 PHP 请求转发到此 PHP 处理服务器fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; #提供:HTTP 方法、请求头、URI 等默认参数}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}
重载nginx
[root@nginx nginx]# systemctl restart nginx
下载NFS (实现目录共享)
[root@nginx nginx]# yum -y install nfs-utils
编辑
[root@nginx nginx]# vim /etc/exports
/usr/share/nginx/html 192.168.158.0/24(rw,sync,no_root_squash)
[root@nginx nginx]# exportfs -arv
exporting 192.168.158.0/24:/usr/share/nginx/html
启用NFS
[root@nginx nginx]# systemctl start nfs-server
[root@nginx nginx]# systemctl start nfs-utils
php服务主机
主机ip:192.168.158.156
下载服务和所需依赖环境
[root@php ~]# dnf install epel-release
[root@php ~]# dnf install php php-fpm php-mysqlnd php-gd php-mbstring php-xml php-json unzip
修改配置文件
[root@php ~]# vim /etc/php-fpm.d/www.confuser = nginx
group = nginx
listen = 192.168.158.156:9000
修改为php服务主机ip和端口号
此处删除
下载NFS
[root@php ~]# yum -y install nfs-utils
启动NFS
[root@php ~]# systemctl start nfs-server
[root@php ~]# systemctl start nfs-utils
创建挂载目录(有就不用创建)
共享目录挂载
[root@php ~]# cd /usr/share/nginx/html
[root@php html]# ls
[root@php html]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs tmpfs 1.8G 9.3M 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/mapper/rl-root xfs 70G 11G 60G 15% /
/dev/nvme0n1p1 xfs 1014M 273M 742M 27% /boot
/dev/mapper/rl-home xfs 126G 936M 125G 1% /home
tmpfs tmpfs 364M 0 364M 0% /run/user/0
[root@php html]# mount 192.168.158.138:/usr/share/nginx/html/ /usr/share/nginx/html
[root@php html]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs tmpfs 1.8G 9.3M 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/mapper/rl-root xfs 70G 11G 60G 15% /
/dev/nvme0n1p1 xfs 1014M 273M 742M 27% /boot
/dev/mapper/rl-home xfs 126G 936M 125G 1% /home
tmpfs tmpfs 364M 0 364M 0% /run/user/0
192.168.158.138:/usr/share/nginx/html nfs4 70G 11G 60G 15% /usr/share/nginx/html
重载NFS
[root@php html]# systemctl restart php-fpm
mysql服务主机
主机ip:192.168.158.157
下载mysql-server mysql
[root@mysql ~]# yum -y install mysql-server mysql
Rocky Linux 8 - AppStream 3.5 kB/s | 4.8 kB 00:01
Rocky Linux 8 - AppStream 1.2 MB/s | 19 MB 00:15
Rocky Linux 8 - BaseOS 3.3 kB/s | 4.3 kB 00:01
Rocky Linux 8 - BaseOS 1.2 MB/s | 28 MB 00:22
Rocky Linux 8 - Extras 2.7 kB/s | 3.1 kB 00:01
Rocky Linux 8 - Extras 12 kB/s | 15 kB 00:01
依赖关系解决。
=======================================================================================软件包 架构 版本 仓库 大小
=======================================================================================
安装:mysql x86_64 8.0.41-1.module+el8.10.0+1937+28fbbc83.0.1 appstream 14 Mmysql-server x86_64 8.0.41-1.module+el8.10.0+1937+28fbbc83.0.1 appstream 32 M
启动mysql服务
[root@mysql ~]# systemctl start mysqld
登录mysql,创建远程登录用户并授权
[root@mysql ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.41 Source distributionCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> CREATE USER 'zbloguser'@'192.168.158.%' IDENTIFIED BY '123.com';
Query OK, 0 rows affected (0.01 sec)mysql> GRANT ALL PRIVILEGES ON *.* TO 'zbloguser'@'192.168.158.%';
Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)mysql> EXIT;
Bye
切换到 nginx服务主机
删除不需要的文档
[root@nginx nginx]# cd /usr/share/nginx/html/
[root@nginx html]# ls
404.html 50x.html index.html nginx-logo.png poweredby.png
[root@nginx html]# rm -rf ./*
[root@nginx html]# ls
[root@nginx html]# rz
rz waiting to receive.**[root@nginx html]# ls
Z-BlogPHP_1_7_4_3430_Shelter.zip
解压zblog软件包
[root@nginx html]# unzip Z-BlogPHP_1_7_4_3430_Shelter.zip
[root@nginx html]# ls
feed.php readme.txt zb_install zb_system
index.php search.php Z-BlogPHP_1_7_4_3430_Shelter.zip zb_users
重载nginx服务
[root@nginx html]# systemctl restart nginx
切换php服务主机
此时主机里共享目录也有zblog解压文件
[root@php ~]# cd /usr/share/nginx/html
[root@php html]# ls
feed.php readme.txt zb_install zb_system
index.php search.php Z-BlogPHP_1_7_4_3430_Shelter.zip zb_users
重载php服务
[root@php html]# systemctl restart php-fpm
切换到访问页面
访问 192.168.158.138/index.php
进行下一步
切换到nginx服务主机
提示进入 zb_user 目录下创建一个 c_option.php 文件,并输入一下代码并保存
[root@nginx html]# ls
feed.php readme.txt zb_install zb_system
index.php search.php Z-BlogPHP_1_7_4_3430_Shelter.zip zb_users
[root@nginx html]# cd zb_users/
[root@nginx zb_users]# ls
avatar cache data emotion language logs plugin theme upload
[root@nginx zb_users]# vim c_option.php<?php
return array ('ZC_DATABASE_TYPE' => 'mysqli','ZC_SQLITE_NAME' => '','ZC_SQLITE_PRE' => 'zbp_','ZC_MYSQL_SERVER' => '192.168.158.157','ZC_MYSQL_USERNAME' => 'zbloguser','ZC_MYSQL_PASSWORD' => '123.com','ZC_MYSQL_NAME' => 'zblogdb','ZC_MYSQL_CHARSET' => 'utf8mb4','ZC_MYSQL_COLLATE' => 'utf8mb4_general_ci','ZC_MYSQL_PRE' => 'zbl_','ZC_MYSQL_ENGINE' => 'InnoDB','ZC_MYSQL_PORT' => '3306','ZC_MYSQL_PERSISTENT' => false,'ZC_PGSQL_SERVER' => 'localhost','ZC_PGSQL_USERNAME' => 'postgres','ZC_PGSQL_PASSWORD' => '','ZC_PGSQL_NAME' => '','ZC_PGSQL_CHARSET' => 'utf8','ZC_PGSQL_PRE' => 'zbp_','ZC_PGSQL_PORT' => '5432','ZC_PGSQL_PERSISTENT' => false,
);
点击登录就可以了