LNMP架构介绍及部署实践

一.架构原理介绍

1.介绍

LNMP是指LNMP==Linux+Nginx+Mysql+PHP的结构体系

2.节点处理

处理防火墙
systemctl stop firewalld
systemctl disable firewalld
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
setenforce 0

时间同步
yum -y install ntp ntpdate
ntpdate cn.pool.ntp.org
hwclock --systohc

修改主机名
hostnamectl set-hostname + 主机名称
su -l

3.程序安装

(这里主要讲解PHP安装)
(1)下载并解压软件包

 wget  http://php.net/distributions/php-7.2.0.tar.gz
 tar xf php-7.2.0.tar.gz -C /usr/local/src/

(2)安装依赖

  [root@php-server ~]# yum install -y gcc zlib zlib-devel openssl openssl-devel
   perl perl-devel make
  [root@php-server ~]# wget
  ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
  [root@php-server ~]# yum -y install gd-devel libjpeg libjpeg-devel libpng
  libpng-devel libiconv-devel freetype freetype-devel libmcrypt libmcrypt-devel
  libxml2 libxml2-devel libxslt-devel mhash
  [root@php-server ~]# tar zxf libmcrypt-2.5.7.tar.gz
  [root@php-server ~]# cd libmcrypt-2.5.7
  [root@php-server libmcrypt-2.5.7]# ./configure
  [root@php-server libmcrypt-2.5.7]# make && make install
  [root@php-server libmcrypt-2.5.7]# echo $?
   0
  [root@php-server libmcrypt-2.5.7]# yum -y install gd-devel libjpeg libjpeg-devel
  libpng libpng-devel libiconv-devel freetype freetype-d autoconf
  [root@php-server ~]# rpm -e libcurl-7.29.0-42.el7.x86_64 --nodeps
  [root@php-server ~]# wget https://curl.haxx.se/download/curl-7.56.0.tar.gz
  [root@php-server ~]# tar -zxvf curl-7.56.0.tar.gz
  [root@php-server ~]# cd curl-7.56.0
  [root@php-server curl-7.56.0]#./configure --prefix=/usr/local/curl --with-ssl --
  with-zlib
  [root@php-server curl-7.56.0]# make && make install

(3)编译安装PHP

[root@php-server libmcrypt-2.5.7]# cd /usr/local/src/php-7.2.0/
[root@php-server php-7.2.0]# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-curl=/usr/local/curl \
--disable-ipv6 \
--with-pdo-mysql \
--with-openssl \
--with-openssl-dir \
--with-pcre-regex \
--with-kerberos \
--with-libdir=lib \
--with-libxml-dir \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-sqlite \
--with-gd \
--with-iconv \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-gettext \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-mcrypt \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-pdo \
--enable-mysqlnd \
--enable-zip \
--enable-inline-optimization \
--enable-shared \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-opcache \
--enable-fpm \
--enable-maintainer-zts \
--enable-fileinfo \
--enable-gd-jis-conv \
--with-zlib-dir                        (在这可能会遇到一些问题,按照提示下载缺少的软件包就可以了)
[root@php-server php-7.2.0]# echo $?
0
[root@php-server php-7.2.0]# make    (在这也有可能遇到问题,请按照报错进行解决)
0
 [root@php-server php-7.2.0]# echo $?
0
[root@php-server php-7.2.0]# make install
[root@php-server php-7.2.0]# echo $?

4. LNMP环境配置与测试

(1)PHP配置

[root@php-server php-7.2.0]# cp php.ini-production /usr/local/php/etc/php.ini
[root@php-server php-7.2.0]# cp php.ini-production /etc/php.ini
[root@php-server php-7.2.0]# cd /usr/local/src/php-7.2.0/sapi/fpm/
[root@php-server fpm]# cp -p init.d.php-fpm /etc/init.d/php-fpm
[root@php-server fpm]# cd /etc/init.d/
functions  netconsole network   php-fpm   README   
[root@php-server init.d]# chmod +x php-fpm
[root@php-server init.d]# chkconfig php-fpm on
[root@php-server init.d]# vim /etc/profile
export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
[root@php-server init.d]# source /etc/profile
[root@php-server init.d]# php -v
PHP 7.2.0 (cli) (built: Oct 29 2019 15:01:58) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies

配置php-fpm模块
编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
配置fpm相关选项为你所需要的值
启动

[root@php-server ~]# cd /usr/local/php
[root@php-server php]# cd etc/
[root@php-server etc]# cp php-fpm.conf.default php-fpm.conf
[root@php-server etc]# cd php-fpm.d/
[root@php-server php-fpm.d]# cp www.conf.default www.conf
[root@php-server php-7.2.8]# vim /usr/local/php7/etc/php-fpm.conf
pm.max_children = 50      //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5       //启动时启动5个进程
pm.min_spare_servers = 2  //最小空闲进程数 
pm.max_spare_servers = 8   //最大空闲进程数
[root@php-server ~]# cat /usr/local/php/etc/php-fpm.d/www.conf |grep -iv "^\;"
[www]
user = nginx
group = nginx
listen = 0.0.0.0:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

启动

[root@php-server ~]# cd /usr/local/php/sbin
[root@php-server ~]# ./php-fpm   

在这里可能会遇到问题 ps -ef |grep php
用户名为nobody
在这里提供两个办法
一 进入配置文件修改
user=nginx
group=nginx
二.自己创建nginx用户
useradd nginx
groupadd nginx
usermod -G nginx nginx
然后重新启动查看

(2)nginx配置

[root@localhost nginx]# cat /etc/nginx/nginx.conf
user nginx nginx;
pid /var/run/nginx.pid;
error_log logs/error.log;

events {
    worker_connections 1024;
}

http {
    include         mime.types;
    default_type    application/octet-stream;

    log_format    main  '$remote_addr - $remote_user [$time_local] "$request"';

server {
    listen       80;

    server_name  192.168.200.138;

    charset koi8-r;
    access_log logs/host.access.log main;

    location / {
            root            /www;
            index           index.html index.htm;
}
    location ~ \.php$ {
            root            /www;
            fastcgi_pass    192.168.200.138:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include         fastcgi_params;
    }
  }
}

修改完配置,重启服务

[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps  -ef |grep nginx

编辑测试网页
在php-server上创建测试目录

[root@php-server /]# mkdir www
[root@php-server /]# chown -R nginx:nginx www
 编辑测试网页
[root@php-server /]# vim www/index.php
<?php
phpinfo();
?>

在浏览器上测试:
(3)mysql配置
在mysql-server上创建测试账号和测试数据库
在这里插入图片描述

在你MySQL8上,创建用户时修改认证插件为mysql_native_password,并开放客户端。
在这里插入图片描述
安装PHP-mysql链接模块

[root@php-server ~]# cd /usr/local/src/php-7.2.0/ext/
[root@php-server ~]# cd mysqli/
[root@localhost mysqli]# /usr/local/php7/bin/phpize
[root@localhost mysqli]# ./configure \
--with-php-config=/usr/local/php7/bin/php-config \
--enable-embedded-mysqli=shared \
--enable-shared
[root@localhost mysqli]# echo $?
0
[root@localhost mysqli]# make
[root@localhost mysqli]# make install
[root@localhost mysqli]# echo $?
[root@localhost mysqli]# cd /usr/local/php7/lib/php/extensions/no-debug-zts-
20170718
[root@localhost no-debug-zts-20170718]# ls
mysqli.a mysqli.so opcache.a opcache.so pdo_mysql.a pdo_mysql.so
[root@localhost php]# cd /usr/local/src/php-7.2.0/ext/pdo
[root@localhost php]# cd /usr/local/src/php-7.2.0/ext/pdo_mysql/
[root@localhost pdo_mysql]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:     20170718
Zend Module Api No:   20170718
Zend Extension Api No:  320170718
[root@localhost pdo_mysql]# ./configure \
--with-php-config=/usr/local/php7/bin/php-config \
--with-pdo-mysql=mysqlnd
[root@localhost pdo_mysql]# echo $?
0
[root@localhost pdo_mysql]# make
[root@localhost pdo_mysql]# echo $?
0
[root@localhost pdo_mysql]# make install

添加模块:

[root@localhost php-7.2.0]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@localhost php-7.2.0]# cd /usr/local/php7/etc/
[root@localhost etc]# vim php.ini
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-zts-20170718"
extension = mysqli.so
extension = pdo_mysql.so
[root@localhost etc]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost etc]# ps -ef |grep php
root   94481   1 0 12:00 ?    00:00:00 php-fpm: master process
(/usr/local/php7/etc/php-fpm.conf)
nginx   94482 94481 0 12:00 ?    00:00:00 php-fpm: pool www
nginx   94483 94481 0 12:00 ?    00:00:00 php-fpm: pool www
nginx   94484 94481 0 12:00 ?    00:00:00 php-fpm: pool www
nginx   94485 94481 0 12:00 ?    00:00:00 php-fpm: pool www
nginx   94486 94481 0 12:00 ?    00:00:00 php-fpm: pool www
root   94495  1506 0 12:00 pts/0  00:00:00 grep --color=auto php

编辑mysql测试网页

[root@php-server /]# vim www/index1.php
<?php
$con = new mysqli('192.168.42.181','superadmin','Cloudbu@123','memcacher');
if(!$con)
echo "faling...";
else
echo "success connect mysql\n";
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值