当前位置: 首页 > news >正文

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,
);

 

         点击登录就可以了

http://www.xdnf.cn/news/1170361.html

相关文章:

  • 设计模式——责任链模式
  • 欧式装修颜色要怎么搭配?
  • Linux研学-MySQL安装
  • C# 类 封装 属性 练习题
  • 暑假算法训练.6
  • [LLM]Synthetic Visual Genome
  • pluto example, heat-1d优化分析
  • ClearML库详解:从实验跟踪到模型部署的全流程管理
  • KafkaMQ 日志采集最佳实践
  • Hadoop调度器深度解析:FairScheduler与CapacityScheduler的优化策略
  • Navicat 远程连接SQLlite数据库
  • 【锁】MySQL中有哪几种锁?
  • 标记语言---XML
  • 《Webpack热更新瓶颈突破:全链路优化指南》
  • Java函数指南:从Function到BiFunction的深度解析
  • 从ZooKeeper到KRaft:Kafka架构演进与无ZooKeeper部署指南
  • React 面试题库
  • Redis 5.0中的 Stream是什么?
  • Vue开发常用库(含npm安装命令)
  • Linux中信号认识及处理和硬件中断与软中断的讲解
  • 设计模式七:抽象工厂模式(Abstract Factory Pattern)
  • el-input 动态获焦
  • An error occurred at line: 1 in the generated java file问题处理及tomcat指定对应的jdk运行
  • 对随机生成的html文件做标签简析
  • Python趣味算法:折半查找(二分查找)算法终极指南——原理、实现与优化
  • Spring 核心知识点梳理 1
  • Jmeter使用 - 2
  • 第十一章 用Java实现JVM之异常处理
  • 使用 Ansys Fluent 软件参数化工作流程对搅拌罐中的稳态涡流进行仿真
  • 质量即服务:从测试策略到平台运营的全链路作战手册