首页 > 其他分享 >LNMP分离部署

LNMP分离部署

时间:2022-10-12 09:37:04浏览次数:44  
标签:部署 分离 LNMP nginx usr mysql -- php root

LNMP分离部署

image-20221012090503173

环境准备:

主机名 系统版本 IP地址
nginx Red Hat Enterprise Linux release 8.2 192.168.100.110/24
php Red Hat Enterprise Linux release 8.2 192.168.100.123/24
mysql Red Hat Enterprise Linux release 8.2 192.168.100.124/24

三台服务器全部关闭防火墙

[root@nginx ]# systemctl stop firewalld.service 
[root@nginx ]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@nginx ]# setenforce 0

[root@php ~]# systemctl stop firewalld.service 
[root@php ~]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@php ~]# setenforce 0

[root@mysql ~]# systemctl stop firewalld.service 
[root@mysql ~]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@mysql ~]# setenforce 0

部署nginx

//创建nginx用户
[root@nginx ~]# id nginx
id: “nginx”:无此用户
[root@nginx ~]# useradd -M -r -s /sbin/nologin nginx
[root@nginx ~]# id nginx
uid=975(nginx) gid=973(nginx) 组=973(nginx)
//安装依赖包
[root@nginx ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
//安装开发工具包
[root@nginx ~]# yum -y groups mark install 'Development Tools'
//创建日志存放目录
[root@nginx ~]# mkdir /var/log/nginx
[root@nginx ~]# chown -R nginx.nginx /var/log/nginx
[root@nginx ~]# cd /usr/src/
//下载nginx包
[root@nginx src]# wget https://nginx.org/download/nginx-1.22.0.tar.gz
[root@nginx src]# tar xf nginx-1.22.0.tar.gz 
[root@nginx src]# ls
debug  kernels  nginx-1.22.0  nginx-1.22.0.tar.gz
[root@nginx src]# cd nginx-1.22.0
[root@nginx nginx-1.22.0]# ./configure  \
--prefix=/usr/local/nginx  \
--user=nginx  \
--group=nginx  \
--with-debug  \
--with-http_ssl_module  \
--with-http_realip_module  \
--with-http_image_filter_module  \
--with-http_gunzip_module  \
--with-http_gzip_static_module  \
--with-http_stub_status_module  \
--http-log-path=/var/log/nginx/access.log  \
--error-log-path=/var/log/nginx/error.log
[root@nginx nginx-1.22.0]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
//配置环境变量
[root@nginx ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@nginx ~]# source /etc/profile.d/nginx.sh
//查看nginx版本
[root@nginx ~]# nginx -v
nginx version: nginx/1.22.0
//创建网页测试文件
[root@nginx ~]# cat > /usr/local/nginx/html/index.php << EOF
<?php
phpinfo();
?>
EOF
//启动nginx
[root@nginx ~]# nginx 
[root@nginx ~]# ss -tanl
State                Recv-Q                Send-Q                               Local Address:Port                               Peer Address:Port               
LISTEN               0                     128                                        0.0.0.0:111                                     0.0.0.0:*                  
LISTEN               0                     128                                        0.0.0.0:80                                      0.0.0.0:*                  
LISTEN               0                     32                                   192.168.122.1:53                                      0.0.0.0:*                  
LISTEN               0                     128                                        0.0.0.0:22                                      0.0.0.0:*                

部署mysql

//安装依赖包
[root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs
//创建mysql用户
[root@mysql ~]# useradd -M -r -s /sbin/nologin mysql
[root@mysql ~]# id mysql 
uid=988(mysql) gid=984(mysql) groups=984(mysql)
//下载mysql软件包
[root@mysql ~]# cd /usr/src/
[root@mysql src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@mysql src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64/'
//解决权限问题
[root@mysql local]# chown -R mysql.mysql mysql
[root@mysql local]# ll
lrwxrwxrwx. 1 root root  36 Oct 11 22:41 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Oct 11 22:41 mysql-5.7.38-linux-glibc2.12-x86_64
//配置环境变量
[root@mysql local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@mysql local]# source /etc/profile.d/mysql.sh
//创建数据库数据存放目录
[root@mysql local]# chown -R mysql.mysql /opt/data/
[root@mysql local]# ll /opt
total 0
drwxr-xr-x. 2 mysql mysql 6 Oct 11 22:52 data
//设置头文件软链接
[root@mysql ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
//配置lib库
[root@mysql ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
//初始化数据库
[root@mysql ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data
//添加配置文件
[root@mysql ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data 
socket = /tmp/mysql.sock 
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql		
skip-name-resolve
//修改启动配置文件
[root@mysql ~]# sed -ri "s#^(basedir=).*#\1/usr/local/mysql#g" /usr/local/mysql/support-files/mysql.server
[root@mysql ~]# sed -ri "s#^(datadir=).*#\1/opt/data#g" /usr/local/mysql/support-files/mysql.server
//配置systemd管理mysqld
[root@mysql ~]# cat > /usr/lib/systemd/system/mysqld.service << EOF
> [Unit]
> Description=mysql server daemon
> After=network.targe
> 
> [Install]
> WantedBy=multi-user.target
> 
> [Service]
> Type=forking
> ExecStart=/usr/local/mysql/support-files/mysql.server start
> ExecStop=/usr/local/mysql/support-files/mysql.server stop
> ExexReload=/bin/kill/ -HUP \$MAINPID
> EOF
[root@mysql ~]# systemctl daemon-reload 
[root@mysql ~]# systemctl enable --now mysqld.service 
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
//设置数据库密码
[root@mysql ~]# /usr/local/mysql/bin/mysql -uroot -e "set password = password('redhat')"
[root@mysql ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> 

部署PHP

[root@php ~]# cd /usr/src
//下载php包
[root@php src]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
//下载依赖包
[root@php src]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd sqlite-devel libzip-devel gcc gcc-c++ make
[root@php src]# yum -y install  http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@php src]# tar xf php-7.4.30.tar.xz php-7.4.30/
[root@php src]# ls
debug  kernels  php-7.4.30  php-7.4.30.tar.xz
[root@php src]# cd php-7.4.30/
[root@php php-7.4.30]# ./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl

......过程省略......
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.
[root@php php-7.4.30]# make -j $(cat /proc/cpuinfo |grep processor|wc -l) && make install
//配置环境变量
[root@php php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@php php-7.4.30]# source /etc/profile.d/php7.sh
[root@php php-7.4.30]# which php
/usr/local/php7/bin/php
[root@php php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@php php-7.4.30]# chmod +x /etc/init.d/php-fpm
[root@php php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
//进入php主目录
[root@php php-7.4.30]# cd /usr/local/php7/
[root@php php7]# ls
bin  etc  include  lib  php  sbin  var
//删除相关文件后缀
[root@php php7]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@php php7]# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
//配置systemd启动
[root@php php7]# cat > /usr/lib/systemd/system/php-fpm.service << EOF
> [Unit]
> Description=OpenSSH server daemon
> After=network.target sshd-keygen.target
> 
> [Service]
> Type=forking
> ExecStart=/etc/init.d/php-fpm start
> ExecStop=/etc/init.d/php-fpm stop
> ExecReload=/bin/kill -HUP $MAINPID
> 
> [Install]
> WantedBy=multi-user.target
> EOF
//重新加载systemd配置文件
[root@php php7]# systemctl daemon-reload 
//设置php-fpm开机自启
[root@php php7]# systemctl enable --now php-fpm.service 
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@php php7]# vim etc/php-fpm.d/www.conf
//搜索相关项取消注释进行修改
listen = 0.0.0.0:9000	//php服务器ip
listen.allowed_clients = 192.168.100.110 //nginx服务器ip
//创建网页测试目录
[root@php ~]# mkdir -p /var/www/html/
//生成测试网页
[root@php ~]# cat >  /var/www/html/index.php << EOF
> <?php
> phpinfo();
> ?>
> EOF
[root@php ~]# systemctl restart php-fpm.service

关联nginx和php

//关联nginx和php
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
http {
 server {
        listen       80;
        server_name  localhost;    
 location / {
            root   html;    //存放index.php目录
            index  index.php index.html index.htm;     //此处添加index.php
        }
location ~ \.php$ {          //取消注释,修改配置文件
            root           /var/www/html;
            fastcgi_pass   192.168.100.123:9000;      //反向代理,php服务器的ip
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /var/www//html/$fastcgi_script_name;  
            include        fastcgi_params;
        }

访问nginx

image-20221011232027356

标签:部署,分离,LNMP,nginx,usr,mysql,--,php,root
From: https://www.cnblogs.com/Archer-x/p/16783354.html

相关文章

  • 在信息安全系统实验箱中部署、运行代码
    目录在信息安全系统实验箱中部署、运行代码交叉编译环境的搭建准备实验箱编写代码配置NetworkFileSystem(NFS)——网络文件系统win7虚拟机连接实验箱传输并运行代码过程......
  • Lnmp环境搭建
    Lnmp环境搭建目录Lnmp环境搭建lnmp介绍lnmp的优势lnmp搭建下载安装Nginx下载安装MySQL下载安装PHP配置网站页面lnmp介绍LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这......
  • 若依框架代码生成(前后端分离版本)
    1、修改代码生成配置编辑resources目录下的application.yml最下面,代码生成这一块。author:#开发者姓名,生成到类注释上packageName:#默认生成包路径autoRemo......
  • Python 远程部署利器 Fabric2 模块
    fabric 官网英文文档:​​http://www.fabfile.org/​​《Python自动化运维技术与最佳实践》如何用Fabric实现无密码输入提示的远程自动部署:fabric实现远程操作和部署:简介F......
  • 防火墙基础之多分支无线网络综合部署与区域与区域之间安全防护
    防火墙基础之多分支无线网络综合部署与区域与区域之间安全防护​原理概述:​防火墙(英语:Firewall)技术是通过有机结合各类用于安全管理与筛选的软件和硬件设备,帮助计算机网络于......
  • Python爬虫-scrapyd框架部署
    爬虫项目部署1脚本文件部署linux内置的cron进程能帮我们实现这些需求,cron搭配shell脚本,非常复杂的指令也没有问题。1.1crontab的使用crontab[-uusername]/......
  • IDEA 使用 Docker 插件,实现一键自动化部署
    一、docker开启远程连接访问​首先我们要开启docker的远程连接访问。保证不是docker所在的服务器,也能够远程访问docker。Linux版的docker:修改docker.service文件,添加监听......
  • lnmp架构的部署
    目录LNMP架构的部署1.安装nginx2.安装mysql3.安装php4.配置nginxLNMP架构的部署实验环境系统主机IPcentos8nginx192.168.169.139centos8mysql192.......
  • Linux下redis集群部署(免安装版本)
    一、redis三台集群服务器上传压缩包链接:​https://pan.baidu.com/s/1EXDEVhaNzMxZmN12GiyKHg​​提取码:bmov二、redis-master部署运行下述命令部署:unzipredis4.0.14.zipus......
  • SpringBoot学习-(十五)SpringBoot热部署
    热部署最重要的功能就是自动应用代码更改到最新的App上面去。原理是在发现代码有更改之后,重新启动应用,但是比速度比手动停止后再启动还要更快,更快指的不是节省出来的手工操......