首页 > 其他分享 >lnmp架构的部署

lnmp架构的部署

时间:2022-10-11 19:00:21浏览次数:54  
标签:fpm 架构 部署 lnmp nginx mysql -- php root

目录

LNMP架构的部署

实验环境

系统 主机 IP
centos8 nginx 192.168.169.139
centos8 mysql 192.168.169.142
centos8 php-fpm 192.168.169.145

前置环境准备

//配置网络仓库
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
dnf clean all
dnf list all

//关闭防火墙和selinux
systemctl disable --now firewalld.service 
sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
reboot

1. 安装nginx

在nginx主机上完成

//下载nginx源码包
[root@nginx ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz

//创建nginx用户
[root@nginx ~]# useradd -rMs /sbin/nologin nginx

//下载编译环境和依赖包
[root@nginx ~]# dnf -y install gcc gcc-c++ make pcre-devel openssl openssl-devel gd-devel

//解压nginx源码包
[root@nginx ~]# tar xf nginx-1.22.0.tar.gz 
[root@nginx ~]# 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 

[root@nginx nginx-1.22.0]# make && make install

//配置全局环境变量
[root@nginx ~]# echo 'export PATH=$PATH:/usr/local/nginx/sbin' > /etc/profile.d/nginx.sh
[root@nginx ~]# source /etc/profile.d/nginx.sh 

//使用systemd风格管理nginx
[root@nginx nginx]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx server daemon
After=network.target 
 
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/bin/kill -HUP $MAINPID
 
[Install]
WantedBy=multi-user.target

[root@nginx nginx]# systemctl daemon-reload 
[root@nginx nginx]# systemctl start nginx.service 
[root@nginx nginx]# systemctl enable nginx.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@nginx nginx]# ss -antl
State          Recv-Q         Send-Q                   Local Address:Port                   Peer Address:Port         Process         
LISTEN         0              128                            0.0.0.0:80                          0.0.0.0:*                            
LISTEN         0              128                            0.0.0.0:22                          0.0.0.0:*                            
LISTEN         0              128                               [::]:22                             [::]:*

2. 安装mysql

在mysql主机上完成

//下载mysql安装包
[root@mysql ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

//安装ncurses-compat-libs
[root@mysql ~]# dnf -y install ncurses-compat-libs

//创建mysql用户
[root@mysql ~]# useradd -rMs /sbin/nologin mysql

//创建mysql数据存放目录
[root@mysql ~]# mkdir -p /opt/data
[root@mysql ~]# chown -R mysql.mysql /opt/data/

//解压mysql
[root@mysql ~]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql local]# ln -s mysql-5.7.38-linux-glibc2.12-x86_64 mysql
[root@mysql local]# chown -R mysql.mysql mysql-5.7.38-linux-glibc2.12-x86_64
[root@mysql local]# chown -R mysql.mysql mysql
[root@mysql local]# cd mysql
[root@mysql mysql]# ls
LICENSE  README  bin  docs  include  lib  man  share  support-files

//配置环境变量
[root@mysql mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@mysql mysql]# source /etc/profile.d/mysql.sh

//配置头文件
[root@mysql mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@mysql mysql]# ll /usr/include/mysql
lrwxrwxrwx. 1 root root 24 Sep  7 15:21 /usr/include/mysql -> /usr/local/mysql/include

//配置库文件
[root@mysql mysql]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@mysql mysql]# ldconfig

//配置mysql帮助文档
[root@mysql mysql]# sed -i '22a MANDATORY_MANPATH     /usr/local/mysql/man' /etc/man_db.conf 

//初始化mysql并将密码保存至/tmp/mysql.pass文件下
[root@mysql mysql]# /usr/local/mysql/bin/mysqld --initialize --user mysql --datadir /opt/data/ | grep 'password' | awk -F' '  '{print $NF}' > /tmp/pass

//生成mysql配置文件
[root@mysql mysql]# cat > /etc/my.cnf <<EOF
[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
EOF

[root@mysql mysql]# cat /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

//使用systemd风格管理mysql
[root@mysql ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL server daemon
After=network.target 
 
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID
 
[Install]
WantedBy=multi-user.target

[root@mysql ~]# systemctl daemon-reload 
[root@mysql ~]# systemctl start mysqld.service 
[root@mysql ~]# systemctl enable mysqld.service 
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@mysql ~]# ss -antl
State          Recv-Q         Send-Q                   Local Address:Port                   Peer Address:Port         Process         
LISTEN         0              128                            0.0.0.0:22                          0.0.0.0:*                            
LISTEN         0              80                                   *:3306                              *:*                            
LISTEN         0              128                               [::]:22                             [::]:* 

//登录数据库
[root@mysql ~]# mysql -uroot -p'hid/qgUxj6B)'  //hid/qgUxj6B)是我的数据库初始密码
//初始化数据库密码
mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@mysql ~]# 

//使用更改后的密码进行登录
[root@mysql ~]# mysql -uroot -p'123456'

3. 安装php

在php-fpm主机上完成

//下载php源码包
[root@php-fpm ~]# wget https://www.php.net/distributions/php-8.1.11.tar.gz

//安装epel源
[root@php-fpm ~]# dnf -y install epel-release
//安装依赖包
[root@php-fpm ~]# dnf -y install gcc gcc-c++ make 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 libsqlite3x-devel http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm libzip-devel

//解压php
[root@php-fpm ~]# tar xf php-8.1.11.tar.gz 
[root@php-fpm ~]# cd php-8.1.11/
[root@php-fpm php-8.1.11]# ./configure --prefix=/usr/local/php8 \
--with-config-file-path=/etc \
--enable-fpm \
--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-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 \
--enable-posix

…………
+--------------------------------------------------------------------+
| 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-fpm php-8.1.11]# make && make install

[root@php-fpm php-8.1.11]# cd /usr/local/php8/
[root@php-fpm php8]# ls
bin  etc  include  lib  php  sbin  var

//配置环境变量
[root@php-fpm php8]# echo 'export PATH=$PATH:/usr/local/php8/bin' > /etc/profile.d/php8.sh
[root@php-fpm php8]# source /etc/profile.d/php-fpm.sh

//配置头文件
[root@php-fpm php8]# ln -s /usr/local/php8/include /usr/include/php8
[root@php-fpm php8]# ll /usr/include/php8
lrwxrwxrwx 1 root root 23 Oct 11 05:34 /usr/include/php8 -> /usr/local/php8/include

//配置库文件
[root@php-fpm php8]# echo "/usr/local/php8/lib" > /etc/ld.so.conf.d/php8.conf
[root@php-fpm php8]# ldconfig 

//配置php-fpm
[root@php-fpm php8]# cd ~/php-8.1.11/
[root@php-fpm php-8.1.11]# cp php.ini-production /etc/php.ini 
cp: overwrite '/etc/php.ini'? y
[root@php-fpm php-8.1.11]# cp ~/php-8.1.11/sapi/fpm/init.d.php-fpm /usr/local/php8/bin/php-fpm
[root@php-fpm php-8.1.11]# chmod +x /usr/local/php8/bin/php-fpm
[root@php-fpm php-8.1.11]# cd /usr/local/php8/etc/
[root@php-fpm etc]# cp php-fpm.conf.default php-fpm.conf
[root@php-fpm etc]# cd php-fpm.d/
[root@php-fpm php-fpm.d]# cp www.conf.default www.conf

//使用systemd风格管理php-fpm
[root@php-fpm ~]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm server daemon
After=network.target 
 
[Service]
Type=forking
ExecStart=/usr/local/php8/bin/php-fpm start
ExecStop=/usr/local/php8/bin/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID
 
[Install]
WantedBy=multi-user.target

[root@php-fpm ~]# systemctl daemon-reload 
[root@php-fpm ~]# systemctl start php-fpm.service 
[root@php-fpm ~]# systemctl enable php-fpm.service 
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@php-fpm ~]# ss -antl
State          Recv-Q         Send-Q                   Local Address:Port                   Peer Address:Port         Process         
LISTEN         0              128                            0.0.0.0:22                          0.0.0.0:*                            
LISTEN         0              128                          127.0.0.1:9000                        0.0.0.0:*                            
LISTEN         0              128                               [::]:22                             [::]:* 

4. 配置nginx

在nginx主机上完成

[root@nginx ~]# cd /usr/local/nginx/
[root@nginx nginx]# cp conf/nginx.conf conf/nginx.conf.bak
[root@nginx nginx]# vim conf/nginx.conf
location / {
            root   html;
            index  index.html index.htm index.php;  //加上index.php
        }
//取消如下内容的注释
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
//进行修改
        location ~ \.php$ {
            root           html;
            fastcgi_pass   192.168.169.145:9000;		//监听php端的9000端口
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;
            
//编写php测试页面
[root@nginx nginx]# cat > /usr/local/nginx/html/index.php <<EOF
> <?php
>     phpinfo();
> ?>
> EOF

//重启nginx
[root@nginx nginx]# systemctl restart nginx.service

在php-fpm主机上完成

[root@php-fpm ~]# cd /usr/local/php8/etc/php-fpm.d/
[root@php-fpm php-fpm.d]# vim www.conf
listen = 192.168.169.145:9000
listen.allowed_clients = 192.168.169.139

//编写php测试页面
[root@php-fpm php-fpm.d]# cat > /usr/local/nginx/html/index.php <<EOF
> <?php
>     phpinfo();
> ?>
> EOF

//重启php-fpm
[root@php-fpm php-fpm.d]# systemctl restart php-fpm.service

在浏览器访问nginx端的80端口下的index.php

标签:fpm,架构,部署,lnmp,nginx,mysql,--,php,root
From: https://www.cnblogs.com/zicnotes/p/16780260.html

相关文章

  • HBase架构的优缺点
    HBase是目前非常热门的一款分布式KV键值数据库系统,无论是互联网行业还是其他传统IT行业都在大量使用。HBase具有高可用、易扩展的特性,目前社区成熟度高,HBase可以作为底层......
  • 系统架构师:软件架构设计
    (理解)软件架构的概念★★★  架构的本质软件架构为软件系统提供了一个结构、行为和属性的高级抽象软件架构风格是特定应用领域的惯用模式,架构定义一个词汇和一组约束......
  • 【博学谷学习记录】超强总结,用心分享|狂野架构师redis淘汰机制
    目录redis淘汰机制淘汰策略LRU算法LFU算法如何获取及设置内存淘汰策略redis淘汰机制淘汰策略1.noeviction(默认策略):默认情况下,Redis在使用的内存空间超过maxmemory......
  • 商业智能深入浅出 第2版——大数据时代下的架构规划与案例
    再版畅销书,既讲商业智能概念、数据仓库理论、数据挖掘分析,又讲Cognos、informatica这两个工具开发的书,配以丰富案例,是市面上唯一的一本。【出版信息】书名:商业智能深入浅出......
  • Linux下redis集群部署(免安装版本)
    一、redis三台集群服务器上传压缩包链接:​https://pan.baidu.com/s/1EXDEVhaNzMxZmN12GiyKHg​​提取码:bmov二、redis-master部署运行下述命令部署:unzipredis4.0.14.zipus......
  • 系统架构与设计(5)- 2017 年 GitLab 宕机事件回顾
     今天(2021年12月前后)大家都在热议AWSdown掉的事情,突然想起来了2017年gitlab.com的宕机事件,所以又去回顾了一下当时究竟发生了什么,顺便也根据当时事件的记录整理一......
  • SpringBoot学习-(十五)SpringBoot热部署
    热部署最重要的功能就是自动应用代码更改到最新的App上面去。原理是在发现代码有更改之后,重新启动应用,但是比速度比手动停止后再启动还要更快,更快指的不是节省出来的手工操......
  • 分离部署LNMP架构
    分离部署LNMP目录分离部署LNMP部署nginx部署mysql部署php安装后配置nginx服务器端php端配置环境说明:系统主机名IP服务centos8nginx192.168.111.141nginx......
  • 软件项目部署时注意事项及关键点总结
    一、部署之前1.确认目标服务器1.1确认服务器操作系统及版本:Windows、Linux等;1.2确认服务器环境及地址:生产环境、开发环境、测试环境、演示环境等;1.3确认服务器部署......
  • ogg21c部署在centos6因glibc版本过低无法使用问题
    环境OS:Centos6.9ogg版本:21C问题[oracle@localhostgoldengate21c]$./ggsci./ggsci:/lib64/libc.so.6:version`GLIBC_2.14'notfound(requiredby/goldengate......