LNMP的平台搭建及源码编译

lnmp简介:

LNMP指的是一个基于CentOS/Debian编写的Nginx、PHP、MySQL、phpMyAdmin、eAccelerator一键安装包。
可以在VPS、独立主机上轻松的安装LNMP生产环境。

lnmp的组成:

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

lnmp的特点:

Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 
Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。
Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。
优点
编辑
作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。
作为负载均衡服务器:Nginx 既可以在内部直接支持Rails和PHP,也可以支持作为 HTTP代理服务器
对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。
作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一
也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。
Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,
还能够在不间断服务的情况下进行软件版本的升级。

准备一个新的虚拟机分配一个可给予的最大内存方便后来的编译不然会很卡:

这里写图片描述

mysql的源码编译:

[root@server6 ~]# ls 准备安装包
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.17.tar.gz
[root@server6 ~]# tar zxf mysql-boost-5.7.17.tar.gz  解压安装包
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz
[root@server6 ~]# cd mysql-5.7.17/ 进入解压路径
[root@server6 mysql-5.7.17]# ls
boost            dbug                 libmysql     rapid          testclients
BUILD            Docs                 libmysqld    README         unittest
client           Doxyfile-perfschema  libservices  regex          VERSION
cmake            extra                man          scripts        vio
CMakeLists.txt   include              mysql-test   sql            win
cmd-line-utils   INSTALL              mysys        sql-common     zlib
config.h.cmake   libbinlogevents      mysys_ssl    storage
configure.cmake  libbinlogstandalone  packaging    strings
COPYING          libevent             plugin       support-files
[root@server6 mysql-5.7.17]# cd ..
[root@server6 ~]# yum install cmake-  2.8.12.2-4.el6.x86_64.rpm  安装cmake编译工具

这里写图片描述

[root@server6 ~]# cd ..
[root@server6 /]# cd
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.17  mysql-boost-5.7.17.tar.gz
[root@server6 ~]# cd mysql-5.7.17/
[root@server6 mysql-5.7.17]# ls
boost            dbug                 libmysql     rapid          testclients
BUILD            Docs                 libmysqld    README         unittest
client           Doxyfile-perfschema  libservices  regex          VERSION
cmake            extra                man          scripts        vio
CMakeLists.txt   include              mysql-test   sql            win
cmd-line-utils   INSTALL              mysys        sql-common     zlib
config.h.cmake   libbinlogevents      mysys_ssl    storage
configure.cmake  libbinlogstandalone  packaging    strings
COPYING          libevent             plugin       support-files

这里写图片描述

[root@server6 mysql-5.7.17]# yum install gcc gcc-c++ -y 安装所需解决依赖性

这里写图片描述

[root@server6 mysql-5.7.17]# cmake 编译-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all 
-- Running cmake version 2.8.12.2
-- Could NOT find Git (missing:  GIT_EXECUTABLE) 
-- Configuring with MAX_INDEXES = 64U
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for SHM_HUGETLB
-- Looking for SHM_HUGETLB - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void *
-- Check size of void * - done
-- SIZEOF_VOIDP 8
-- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG
-- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG - Failed
-- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG
-- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG - Failed
-- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD
-- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD - Failed
-- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD
-- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD - Failed
-- Performing Test HAVE_C_FP_CONTRACT_FLAG
-- Performing Test HAVE_C_FP_CONTRACT_FLAG - Failed
-- Performing Test HAVE_CXX_FP_CONTRACT_FLAG
-- Performing Test HAVE_CXX_FP_CONTRACT_FLAG - Failed
-- MySQL 5.7.17
-- Packaging as: mysql-5.7.17-Linux-x86_64
-- Looked for boost/version.hpp in  and 
-- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND
-- LOCAL_BOOST_DIR 
-- LOCAL_BOOST_ZIP 
-- Could not find (the correct version of) boost.
-- MySQL currently requires boost_1_59_0

CMake Error at cmake/boost.cmake:81 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 
 -DWITH_BOOST=<directory>
 提示的报错信息,加在编译后面即可

  This CMake script will look for boost in <directory>.  If it is not there,
  it will download and unpack it (in that directory) for you.

  If you are inside a firewall, you may need to use an http proxy:

  export http_proxy=http://example.com:80

Call Stack (most recent call first):
  cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
  CMakeLists.txt:455 (INCLUDE)


-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.17/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.17/CMakeFiles/CMakeError.log".
[root@server6 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \-DWITH_BOOST=    两下Tab键可以补齐
boost/               include/             regex/
BUILD/               INSTALL              scripts/
client/              libbinlogevents/     sql/
cmake/               libbinlogstandalone/ sql-common/
CMakeCache.txt       libevent/            storage/
CMakeFiles/          libmysql/            strings/
CMakeLists.txt       libmysqld/           support-files/
cmd-line-utils/      libservices/         testclients/
config.h.cmake       man/                 unittest/
configure.cmake      mysql-test/          VERSION
COPYING              mysys/               VERSION.dep
dbug/                mysys_ssl/           vio/
Docs/                packaging/           win/
Doxyfile-perfschema  plugin/              zlib/
extra/               rapid/               
.gitignore           README               
[root@server6 mysql-5.7.17]# cmake 保留两层路径即可-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \-DWITH_BOOST=boost/boost_1_59_0/

这里写图片描述

系统提示必须删除CMakeCache.txt,不然解决的依赖性不会被读取
     remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:107 (FIND_CURSES)
  cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.17/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.17/CMakeFiles/CMakeError.log".
[root@server6 mysql-5.7.17]# yum install ncurses-devel -y
安装提示的服务

这里写图片描述

编译时会占用大量的系统资源,建议使用多个核心同时进行编译,否则可能会编译失败,耐心等待即可:

[root@server6 mysql-5.7.17]# rm -fr CMakeCache.txt  删除缓存[root@server6 mysql-5.7.17]# yum install bison -y 安装依赖性
[root@server6 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all \-DWITH_BOOST=boost/boost_1_59_0/

这里写图片描述

[root@server6 mysql-5.7.17]# make 进行读取配置文件

这里写图片描述

[root@server6 mysql-5.7.17]# make install 进行安装

这里写图片描述

[root@server6 mysql-5.7.17]# cd /usr/local/lnmp/mysql/
[root@server6 mysql]# ls
bin  COPYING  docs  include  lib  man  mysql-test  README  share  support-files
[root@server6 mysql]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@server6 mysql]# ll /etc/my.cnf 
-rw-r--r--. 1 root root 251 Aug  9  2013 /etc/my.cnf
[root@server6 mysql]# cat /etc/my.cnf  查看配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@server6 mysql]# cd support-files/
[root@server6 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server

这里写图片描述

[root@server6 support-files]# cp my-default.cnf /etc/my.cnf  直接覆盖文件
cp: overwrite `/etc/my.cnf'? y
[root@server6 support-files]# vim /etc/my.cnf  编辑填写提示即可

这里写图片描述

[root@server6 support-files]# file mysql.server  查看文件类型
mysql.server: POSIX shell script text executable
[root@server6 support-files]# cp mysql.server /etc/init.d/mysqld  复制过去即可
[root@server6 support-files]# ll /etc/init.d/mysqld 
-rwxr-xr-x 1 root root 10916 Aug  5 11:02 /etc/init.d/mysqld
[root@server6 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@server6 support-files]# cd ..
[root@server6 mysql]# ls
bin  COPYING  docs  include  lib  man  mysql-test  README  share  support-files
[root@server6 mysql]# ll
total 56
drwxr-xr-x  2 root root  4096 Aug  5 10:25 bin
-rw-r--r--  1 root root 17987 Nov 28  2016 COPYING
drwxr-xr-x  2 root root  4096 Aug  5 10:25 docs
drwxr-xr-x  3 root root  4096 Aug  5 10:25 include
drwxr-xr-x  4 root root  4096 Aug  5 10:25 lib
drwxr-xr-x  4 root root  4096 Aug  5 10:25 man
drwxr-xr-x 10 root root  4096 Aug  5 10:26 mysql-test
-rw-r--r--  1 root root  2478 Nov 28  2016 README

这里写图片描述

[root@server6 mysql]# groupadd -g 27 mysql  建立用户指定组
[root@server6 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s /sbin/nologin mysql
[root@server6 mysql]# cd bin/
[root@server6 bin]# ls
innochecksum                mysql_config               mysqlshow
lz4_decompress              mysql_config_editor        mysqlslap
myisamchk                   mysqld                     mysql_ssl_rsa_setup
myisam_ftdump               mysqld_multi               mysqltest
myisamlog                   mysqld_safe                mysqltest_embedded
myisampack                  mysqldump                  mysql_tzinfo_to_sql
my_print_defaults           mysqldumpslow              mysql_upgrade
mysql                       mysql_embedded             mysqlxtest
mysqladmin                  mysqlimport                perror
mysqlbinlog                 mysql_install_db           replace
mysqlcheck                  mysql_plugin               resolveip
mysql_client_test           mysqlpump                  resolve_stack_dump
mysql_client_test_embedded  mysql_secure_installation  zlib_decompress
[root@server6 bin]# cd

这里写图片描述

[root@server6 ~]# vim .bash_profile  生成服务启动脚本
[root@server6 ~]# source .bash_
.bash_history  .bash_logout   .bash_profile  
[root@server6 ~]# source .bash_profile  检测语法

这里写图片描述

[root@server6 mysql]# mysqld --initialize --user=mysql 初始化,这个是初始化密码
root@localhost: 2=G7f5.ddIZ=
[root@server6 mysql]# ls
bin      data  include  man         README  support-files
COPYING  docs  lib      mysql-test  share
[root@server6 mysql]# cd data/
[root@server6 data]# ls
auto.cnf        ibdata1      ib_logfile1  performance_schema
ib_buffer_pool  ib_logfile0  mysql        sys
[root@server6 data]# /etc/init.d/mysqld start 可以开启服务
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server6.err'.
. SUCCESS! 
[root@server6 data]# /etc/init.d/mysqld stop  可以停止服务
Shutting down MySQL.. SUCCESS! 
[root@server6 data]# chkconfig --list mysqld
service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld')

这里写图片描述

[root@server6 mysql]# chown mysql data/ -R  仅仅更改data目录的用户为mysql
[root@server6 mysql]# ll
total 60
drwxr-xr-x  2 root  mysql  4096 Aug  5 10:25 bin
-rw-r--r--  1 root  mysql 17987 Nov 28  2016 COPYING
drwxr-x---  5 mysql root   4096 Aug  5 11:19 data
drwxr-xr-x  2 root  mysql  4096 Aug  5 10:25 docs
drwxr-xr-x  3 root  mysql  4096 Aug  5 10:25 include
drwxr-xr-x  4 root  mysql  4096 Aug  5 10:25 lib
drwxr-xr-x  4 root  mysql  4096 Aug  5 10:25 man
drwxr-xr-x 10 root  mysql  4096 Aug  5 10:26 mysql-test
-rw-r--r--  1 root  mysql  2478 Nov 28  2016 README
drwxr-xr-x 28 root  mysql  4096 Aug  5 10:26 share
drwxr-xr-x  2 root  mysql  4096 Aug  5 10:26 support-files
[root@server6 mysql]# chgrp root . -R 重新将组更改为root
[root@server6 mysql]# ll
total 60
drwxr-xr-x  2 root  root  4096 Aug  5 10:25 bin
-rw-r--r--  1 root  root 17987 Nov 28  2016 COPYING
drwxr-x---  5 mysql root  4096 Aug  5 11:19 data
drwxr-xr-x  2 root  root  4096 Aug  5 10:25 docs
drwxr-xr-x  3 root  root  4096 Aug  5 10:25 include
drwxr-xr-x  4 root  root  4096 Aug  5 10:25 lib
drwxr-xr-x  4 root  root  4096 Aug  5 10:25 man
drwxr-xr-x 10 root  root  4096 Aug  5 10:26 mysql-test
-rw-r--r--  1 root  root  2478 Nov 28  2016 README
drwxr-xr-x 28 root  root  4096 Aug  5 10:26 share
drwxr-xr-x  2 root  root  4096 Aug  5 10:26 support-files
[root@server6 mysql]# /etc/init.d/mysqld start 可以开启服务
Starting MySQL.. SUCCESS! 

这里写图片描述

[root@server6 mysql]# mysql_secure_installation  初始化安装使用初始化数据库的密码登陆进去修改密码即可:


Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Using existing password for root.
之后的回车即可

这里写图片描述

[root@server6 mysql]# mysql -p  直接使用自己设置的数据库密码进行登陆
Enter password: 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit
Bye

这里写图片描述

PHP源码编译:

[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.17.tar.gz
mysql-5.7.17                     php-5.6.35.tar.bz2
[root@server6 ~]# tar jxf php-5.6.35.tar.bz2  解压php源码包
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.17.tar.gz  php-5.6.35.tar.bz2
mysql-5.7.17                     php-5.6.35
[root@server6 ~]# cd php-5.6.35  进入源码包

这里写图片描述

参数复制粘贴容易出现错误:
[root@server6 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqyi=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash

这里写图片描述

出来报错信息,依次安装依赖性
configure: error: xml2-config not found. Please check your libxml2 installation.
[root@server6 php-5.6.35]# yum install libxml2-devel openssl-devel curl-devel -y

这里写图片描述

[root@server6 php-5.6.35]# yum list gd  查看gd的包的版本
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Available Packages
gd.i686                         2.0.35-11.el6                        rhel-source
gd.x86_64                       2.0.35-11.el6                        rhel-source
[root@server6 php-5.6.35]# cd
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm    php-5.6.35
gd-devel-2.0.35-11.el6.x86_64.rpm  php-5.6.35.tar.bz2
mysql-5.7.17                       re2c-0.13.5-1.el6.x86_64.rpm
mysql-boost-5.7.17.tar.gz
[root@server6 ~]# yum install -y gd-devel-2.0.35-11.el6.x86_64.rpm 

这里写图片描述
这里写图片描述
这里写图片描述

[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm         mysql-boost-5.7.17.tar.gz
gd-devel-2.0.35-11.el6.x86_64.rpm       php-5.6.35
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm  php-5.6.35.tar.bz2
mysql-5.7.17                            re2c-0.13.5-1.el6.x86_64.rpm
[root@server6 ~]# yum install libmcrypt-devel-2.5.8-9.el6.x86_64.rpm -y

这里写图片描述
这里写图片描述

[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm
gd-devel-2.0.35-11.el6.x86_64.rpm
libevent-devel-1.4.13-4.el6.x86_64.rpm
libevent-doc-1.4.13-4.el6.noarch.rpm
libevent-headers-1.4.13-4.el6.noarch.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
mysql-5.7.17
mysql-boost-5.7.17.tar.gz
php-5.6.35
php-5.6.35.tar.bz2
re2c-0.13.5-1.el6.x86_64.rpm
[root@server6 ~]# yum install lib* -y

这里写图片描述

[root@server6 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqyi=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash

这里写图片描述

[root@server6 php-5.6.35]# make && make insatll

这里写图片描述

PHP的简单配置:

[root@server6 php-5.6.35]# cd /usr/local/lnmp/php/
[root@server6 php]# ls
bin  etc  include  lib  php  sbin  var
[root@server6 php]# cd etc/
[root@server6 etc]# ls
pear.conf  php-fpm.conf.default
[root@server6 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server6 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default
[root@server6 etc]# cd 
[root@server6 ~]# cd php-5.6.35
[root@server6 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server6 php-5.6.35]# cd /usr/local/lnmp/php/
[root@server6 php]# ls
bin  etc  include  lib  php  sbin  var
[root@server6 php]# cd etc/
[root@server6 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini

这里写图片描述

[root@server6 etc]# vim php.ini  添加时区

这里写图片描述

[root@server6 etc]# vim php-fpm.conf  打开PID即可

这里写图片描述

[root@server6 etc]# id nginx  查看用户不存在
id: nginx: No such user
[root@server6 etc]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx  建立用户
[root@server6 etc]# cd 
[root@server6 ~]# cd php-5.6.35
[root@server6 php-5.6.35]# cd sapi/
[root@server6 sapi]# ls
aolserver       apache_hooks  continuity  litespeed  phttpd  thttpd
apache          caudium       embed       milter     pi3web  tux
apache2filter   cgi           fpm         nsapi      roxen   webjames
apache2handler  cli           isapi       phpdbg     tests
[root@server6 sapi]# cd fpm/
[root@server6 fpm]# ls
config.m4          LICENSE        php-fpm.conf        status.html.in
CREDITS            Makefile.frag  php-fpm.conf.in     tests
fpm                php-fpm        php-fpm.service     www.conf.in
init.d.php-fpm     php-fpm.8      php-fpm.service.in
init.d.php-fpm.in  php-fpm.8.in   status.html
[root@server6 fpm]# file init.d.php-fpm  查看文件类型为脚本
init.d.php-fpm: POSIX shell script text executable
[root@server6 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server6 fpm]# chmod +x /etc/init.d/php-fpm  赋予执行权限

这里写图片描述

[root@server6 fpm]# /etc/init.d/php-fpm start  启动脚本
Starting php-fpm  done
[root@server6 fpm]# netstat -antlp  开启端口
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      908/sshd            
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      984/master          
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      11804/php-fpm       
tcp        0      0 172.25.38.7:22              172.25.38.250:54092         ESTABLISHED 1368/sshd           
tcp        0      0 :::22                       :::*                        LISTEN      908/sshd            
tcp        0      0 ::1:25                      :::*                        LISTEN      984/master          
tcp        0      0 :::3306                     :::*                        LISTEN      25819/mysqld        

这里写图片描述

nginx源码编译:

[root@server6 ~]# tar zxf nginx-1.10.1.tar.gz  解压源码包
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm           mysql-boost-5.7.17.tar.gz
gd-devel-2.0.35-11.el6.x86_64.rpm         nginx-1.10.1
libevent-devel-1.4.13-4.el6.x86_64.rpm    nginx-1.10.1.tar.gz
libevent-doc-1.4.13-4.el6.noarch.rpm      nginx-sticky-module-ng.tar.gz
libevent-headers-1.4.13-4.el6.noarch.rpm  php-5.6.35
libmcrypt-2.5.8-9.el6.x86_64.rpm          php-5.6.35.tar.bz2
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm    re2c-0.13.5-1.el6.x86_64.rpm
mysql-5.7.17
[root@server6 ~]# tar zxf nginx-sticky-module-ng.tar.gz 解压模块包
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm           mysql-boost-5.7.17.tar.gz
gd-devel-2.0.35-11.el6.x86_64.rpm         nginx-1.10.1
libevent-devel-1.4.13-4.el6.x86_64.rpm    nginx-1.10.1.tar.gz
libevent-doc-1.4.13-4.el6.noarch.rpm      nginx-sticky-module-ng
libevent-headers-1.4.13-4.el6.noarch.rpm  nginx-sticky-module-ng.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm          php-5.6.35
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm    php-5.6.35.tar.bz2
mysql-5.7.17                              re2c-0.13.5-1.el6.x86_64.rpm

这里写图片描述

[root@server6 ~]# cd  nginx-1.10.1
[root@server6 nginx-1.10.1]# cd src/core/nginx.h 
-bash: cd: src/core/nginx.h: Not a directory

这里写图片描述

[root@server6 nginx-1.10.1]# vim src/core/nginx.h 

这里写图片描述

[root@server6 nginx-1.10.1]# vim auto/cc/gcc 

这里写图片描述

开始源码编译三部曲:

[root@server6 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio

这里写图片描述
解决报错:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

[root@server6 nginx-1.10.1]# yum install pcre-devel -y

这里写图片描述

[root@server6 nginx-1.10.1]# make && make install

这里写图片描述

nginx的简单配置:

[root@server6 nginx-1.10.1]# cd /usr/local/lnmp/nginx/ 进入nginx的默认目录
[root@server6 nginx]# ls
conf  html  logs  sbin
[root@server6 nginx]# cd conf/
[root@server6 conf]# ls
fastcgi.conf            koi-win             scgi_params
fastcgi.conf.default    mime.types          scgi_params.default
fastcgi_params          mime.types.default  uwsgi_params
fastcgi_params.default  nginx.conf          uwsgi_params.default
koi-utf                 nginx.conf.default  win-utf
[root@server6 conf]# vim nginx.conf  更改最大连接

这里写图片描述

[root@server6 conf]# vim /etc/security/limits.conf  写入最大文件数

这里写图片描述

[root@server6 conf]# sysctl -a|grep file  查看最大文件个数
fs.file-nr = 576    0   291270
fs.file-max = 291270
[root@server6 conf]# vim nginx.conf  打开与PHP的连接

这里写图片描述

[root@server6 conf]# cd
[root@server6 ~]# vim .bash_profile 写入nginx的默认路径方便调用

这里写图片描述

[root@server6 ~]# source .bash_profile  刷新检测语法
[root@server6 ~]# nginx -t  检测nginx语法
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server6 ~]# nginx   开启nginx
[root@server6 ~]# nginx -s reload  重启nginx

这里写图片描述

在网页测试nginx的访问:

这里写图片描述

[root@server6 ~]# cd /usr/local/lnmp/nginx/html/
[root@server6 html]# ls
50x.html  index.html
[root@server6 html]# vim index.php
[root@server6 html]# cat index.php   写入php访问界面
<?php
phpinfo()
?>

这里写图片描述

在网页查看php的测试:

这里写图片描述

若想要直接访问php的界面,在配置文件更改访问顺序即可:

[root@server6 html]# vim /usr/local/lnmp/nginx /conf/nginx.conf 编辑nginx配置文件
[root@server6 html]# nginx -s reload 重启nginx服务

这里写图片描述

在网页测试访问顺序:

这里写图片描述

论坛的搭建:

[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm           mysql-boost-5.7.17.tar.gz
Discuz_X3.2_SC_UTF8.zip                   nginx-1.10.1
gd-devel-2.0.35-11.el6.x86_64.rpm         nginx-1.10.1.tar.gz
libevent-devel-1.4.13-4.el6.x86_64.rpm    nginx-sticky-module-ng
libevent-doc-1.4.13-4.el6.noarch.rpm      nginx-sticky-module-ng.tar.gz
libevent-headers-1.4.13-4.el6.noarch.rpm  php-5.6.35
libmcrypt-2.5.8-9.el6.x86_64.rpm          php-5.6.35.tar.bz2
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm    re2c-0.13.5-1.el6.x86_64.rpm
mysql-5.7.17
[root@server6 ~]# yum install unzip -y

这里写图片描述

[root@server6 ~]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/

这里写图片描述

[root@server6 ~]# cd /usr/local/lnmp/
[root@server6 lnmp]# ls
mysql  nginx  php
[root@server6 lnmp]# cd nginx/html/
[root@server6 html]# ls
50x.html  index.html  index.php  readme  upload  utility
[root@server6 html]# mv upload/ bbs
[root@server6 html]# ls
50x.html  bbs  index.html  index.php  readme  utility

这里写图片描述

在网页测试会出来错误:

这里写图片描述
这里写图片描述

[root@server6 html]# cd bbs/
[root@server6 bbs]# ls
admin.php  connect.php      forum.php  member.php  search.php  uc_server
api        cp.php           group.php  misc.php    source      userapp.php
api.php    crossdomain.xml  home.php   plugin.php  static
archiver   data             index.php  portal.php  template
config     favicon.ico      install    robots.txt  uc_client
[root@server6 bbs]# chmod 777 config/ data/ uc_server/ uc_client/ -R
[root@server6 bbs]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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> quit
Bye

这里写图片描述

在网页测试:

已经可写:
这里写图片描述
全新安装:
这里写图片描述
填写用户密码:
这里写图片描述
无法读取socket:
这里写图片描述

配置访问目录让可以查看socket文件:

[root@server6 bbs]# cd /usr/local/lnmp/php/etc/
[root@server6 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini
[root@server6 etc]# vim php-fpm.conf
[root@server6 etc]# vim php.ini 

这里写图片描述
这里写图片描述
这里写图片描述

[root@server6 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done

这里写图片描述

在网页查看错误已经变成权限不允许:

这里写图片描述
配置增加权限:

[root@server6 etc]# ll /usr/local/lnmp/mysql/data/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Aug  5 11:22 /usr/local/lnmp/mysql/data/mysql.sock
[root@server6 etc]# cd /usr/local/
[root@server6 local]# ls
bin  etc  games  include  lib  lib64  libexec  lnmp  sbin  share  src
[root@server6 local]# cd lnmp/
[root@server6 lnmp]# ls
mysql  nginx  php
[root@server6 lnmp]# ll
total 12
drwxr-xr-x 11 root root 4096 Aug  5 11:17 mysql
drwxr-xr-x 11 root root 4096 Aug  5 14:30 nginx
drwxr-xr-x  9 root root 4096 Aug  5 13:41 php
[root@server6 lnmp]# cd mysql/
[root@server6 mysql]# ll
total 60
drwxr-xr-x  2 root  root  4096 Aug  5 10:25 bin
-rw-r--r--  1 root  root 17987 Nov 28  2016 COPYING
drwxr-x---  5 mysql root  4096 Aug  5 11:22 data
drwxr-xr-x  2 root  root  4096 Aug  5 10:25 docs
drwxr-xr-x  3 root  root  4096 Aug  5 10:25 include
drwxr-xr-x  4 root  root  4096 Aug  5 10:25 lib
drwxr-xr-x  4 root  root  4096 Aug  5 10:25 man
drwxr-xr-x 10 root  root  4096 Aug  5 10:26 mysql-test
-rw-r--r--  1 root  root  2478 Nov 28  2016 README
drwxr-xr-x 28 root  root  4096 Aug  5 10:26 share
drwxr-xr-x  2 root  root  4096 Aug  5 10:26 support-files

这里写图片描述

[root@server6 mysql]# chmod 755 data/
[root@server6 mysql]# ll
total 60
drwxr-xr-x  2 root  root  4096 Aug  5 10:25 bin
-rw-r--r--  1 root  root 17987 Nov 28  2016 COPYING
drwxr-xr-x  5 mysql root  4096 Aug  5 11:22 data
drwxr-xr-x  2 root  root  4096 Aug  5 10:25 docs
drwxr-xr-x  3 root  root  4096 Aug  5 10:25 include
drwxr-xr-x  4 root  root  4096 Aug  5 10:25 lib
drwxr-xr-x  4 root  root  4096 Aug  5 10:25 man
drwxr-xr-x 10 root  root  4096 Aug  5 10:26 mysql-test
-rw-r--r--  1 root  root  2478 Nov 28  2016 README
drwxr-xr-x 28 root  root  4096 Aug  5 10:26 share
drwxr-xr-x  2 root  root  4096 Aug  5 10:26 support-files
[root@server6 mysql]# cd data/
[root@server6 data]# ls
auto.cnf        ib_logfile0  mysql            mysql.sock.lock     server6.pid
ib_buffer_pool  ib_logfile1  mysqld_safe.pid  performance_schema  sys
ibdata1         ibtmp1       mysql.sock       server6.err

这里写图片描述

在网页继续搭建论坛:

这里写图片描述
就可以登陆自己的论坛:
这里写图片描述
进去管理中心提示删除安装路径中的index.php:
这里写图片描述

删除index.php防止下次登陆论坛时候还得重新安装:

[root@server6 ~]# cd /usr/local/lnmp/nginx/html/
[root@server6 html]# ls
50x.html  bbs  index.html  index.php  readme  utility
[root@server6 html]# cd bbs/
[root@server6 bbs]# cd install/
[root@server6 install]# ls
data  images  include  index.php
[root@server6 install]# rm -f index.php 

这里写图片描述

在网页测试论坛搭建成功:

这里写图片描述

[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm           mysql-5.7.17
Discuz_X3.2_SC_UTF8.zip                   mysql-boost-5.7.17.tar.gz
gd-devel-2.0.35-11.el6.x86_64.rpm         nginx-1.10.1
libevent-devel-1.4.13-4.el6.x86_64.rpm    nginx-1.10.1.tar.gz
libevent-doc-1.4.13-4.el6.noarch.rpm      nginx-sticky-module-ng
libevent-headers-1.4.13-4.el6.noarch.rpm  nginx-sticky-module-ng.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm          php-5.6.35
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm    php-5.6.35.tar.bz2
memcache-2.2.5.tgz                        re2c-0.13.5-1.el6.x86_64.rpm
[root@server6 ~]# tar zxf memcache-2.2.5.tgz 
[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm           mysql-5.7.17
Discuz_X3.2_SC_UTF8.zip                   mysql-boost-5.7.17.tar.gz
gd-devel-2.0.35-11.el6.x86_64.rpm         nginx-1.10.1
libevent-devel-1.4.13-4.el6.x86_64.rpm    nginx-1.10.1.tar.gz
libevent-doc-1.4.13-4.el6.noarch.rpm      nginx-sticky-module-ng
libevent-headers-1.4.13-4.el6.noarch.rpm  nginx-sticky-module-ng.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm          package.xml
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm    php-5.6.35
memcache-2.2.5                            php-5.6.35.tar.bz2
memcache-2.2.5.tgz                        re2c-0.13.5-1.el6.x86_64.rpm

这里写图片描述

Memcache是什么?

Memcache是一个自由和开放源代码、高性能、分配的内存对象缓存系统。用于加速动态web应用程序,
减轻数据库负载。它可以应对任意多个连接,使用非阻塞的网络IO。由于它的工作机制是在内存中开辟
一块空间,然后建立一个Hash表,Memcached自管理这些Hash表。

Memcached是简单而强大的。它简单的设计促进迅速部署,易于发展所面临的问题,解决了很多大型
数据缓存。它的API可供最流行的语言。

Memcached又是什么?

Memcache是该系统的项目名称,Memcached是该系统的主程序文件(字母d可以理解为daemon),
以守护程序方式运行于一个或多个服务器中,随时接受客户端的连接操作,使用共享内存存取数据。

实验配置:

[root@server6 ~]# cd memcache-2.2.5
[root@server6 memcache-2.2.5]# ls
config9.m4   memcache.c                  memcache_queue.h
config.m4    memcache_consistent_hash.c  memcache_session.c
config.w32   memcache.dsp                memcache_standard_hash.c
CREDITS      memcache.php                php_memcache.h
example.php  memcache_queue.c            README
[root@server6 memcache-2.2.5]# phpize   phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块
-bash: phpize: command not found
[root@server6 memcache-2.2.5]# cd /usr/local/lnmp/php/bin/
[root@server6 bin]# ls
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize
[root@server6 bin]# cd ..
[root@server6 php]# cd bin/
[root@server6 bin]# ls
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize
[root@server6 bin]# cd ..
[root@server6 php]# cd sbin/
[root@server6 sbin]# ls
php-fpm
[root@server6 sbin]# cd ..
[root@server6 php]# ls
bin  etc  include  lib  php  sbin  var
[root@server6 php]# cd bin/
[root@server6 bin]# pwd
/usr/local/lnmp/php/bin
[root@server6 bin]# cd
[root@server6 ~]# vim .bash_profile  添加到环境变量

这里写图片描述

[root@server6 ~]# source .bash_profile  激活生效
[root@server6 ~]# cd memcache-2.2.5
[root@server6 memcache-2.2.5]# ls
config9.m4   memcache.c                  memcache_queue.h
config.m4    memcache_consistent_hash.c  memcache_session.c
config.w32   memcache.dsp                memcache_standard_hash.c
CREDITS      memcache.php                php_memcache.h
example.php  memcache_queue.c            README
[root@server6 memcache-2.2.5]# phpize  已经有了扩展模块
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

这里写图片描述

[root@server6 memcache-2.2.5]# ./configure && make && make install  进行源码编译

这里写图片描述

Installing shared extensions:     /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
[root@server6 memcache-2.2.5]# cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
[root@server6 no-debug-non-zts-20131226]# ls
memcache.so  opcache.a  opcache.so
[root@server6 no-debug-non-zts-20131226]# pwd
/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226
[root@server6 no-debug-non-zts-20131226]# ls
memcache.so  opcache.a  opcache.so
[root@server6 no-debug-non-zts-20131226]# php -m   查看php 在cli下面加载了哪些模块,使用 php -i 查看php在cli下面的详细信息
[PHP Modules]
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
json
libxml
mbstring
mcrypt
mhash
mysql
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
snmp
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

这里写图片描述

[root@server6 no-debug-non-zts-20131226]# php -m | grep memcache 检测memcache是否存在
[root@server6 no-debug-non-zts-20131226]# cd ..
[root@server6 extensions]# cd /usr/local/lnmp/nginx/html/
[root@server6 html]# cd /usr/local/lnmp/php/etc/
[root@server6 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini
[root@server6 etc]# vim php.ini 
[root@server6 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@server6 etc]# vim php.ini 
[root@server6 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@server6 etc]# yum install memcached -y  安装memcached

这里写图片描述

[root@server6 etc]# /etc/init.d/memcached start  开启服务
Starting memcached:                                        [  OK  ]
[root@server6 etc]# php -m | grep memcache   已经加载了memcached模块
memcache
[root@server6 etc]# netstat -antlp  查看端口9000是memcached的默认端口
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN      18312/memcached     
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      15455/nginx         
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      908/sshd            
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      984/master          
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      18286/php-fpm       
tcp        0      0 172.25.38.7:45697           172.25.38.250:80            TIME_WAIT   -                   
tcp        0      0 172.25.38.7:22              172.25.38.250:54092         ESTABLISHED 1368/sshd           
tcp        0      0 :::11211                    :::*                        LISTEN      18312/memcached     
tcp        0      0 :::22                       :::*                        LISTEN      908/sshd            
tcp        0      0 ::1:25                      :::*                        LISTEN      984/master          
tcp        0      0 :::3306                     :::*                        LISTEN      25819/mysqld        
[root@server6 etc]# cd
[root@server6 ~]# cd memcache-2.2.5

这里写图片描述
这里写图片描述

[root@server6 memcache-2.2.5]# cp memcache.php example.php /usr/local/lnmp/nginx/html/
[root@server6 memcache-2.2.5]# rpm -q memcached
memcached-1.4.4-3.el6.x86_64
[root@server6 memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/
[root@server6 html]# ls
50x.html  example.php  index.php     readme
bbs       index.html   memcache.php  utility

这里写图片描述

在网页测试:

这里写图片描述

[root@server6 html]# vim memcache.php 

这里写图片描述

在网页测试会有相应的登陆界面:

这里写图片描述
可以看到memcache的界面
这里写图片描述
每刷新一次在memcache.php会有相应的动态数据变化:
这里写图片描述
这里写图片描述

在真机测试memcache的加速功能:

[root@foundation38 Desktop]# ab -c 10 -n 1000 http://172.25.38.7/example.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.38.7 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/
Server Hostname:        172.25.38.7
Server Port:            80

Document Path:          /example.php
Document Length:        123 bytes

Concurrency Level:      10
Time taken for tests:   1.073 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      280000 bytes
HTML transferred:       123000 bytes
Requests per second:    932.37 [#/sec] (mean)
Time per request:       10.725 [ms] (mean)
Time per request:       1.073 [ms] (mean, across all concurrent requests)
Transfer rate:          254.95 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     2   11   1.3     10      20
Waiting:        2   11   1.3     10      20
Total:          2   11   1.3     10      20

Percentage of the requests served within a certain time (ms)
  50%     10
  66%     11
  75%     11
  80%     11
  90%     12
  95%     13
  98%     14
  99%     14
 100%     20 (longest request)

通过图片可以看到速度的对比关系:
这里写图片描述
这里写图片描述

OpenResty运行原理:

Nginx 采用的是 master-worker 模型,一个 master 进程管理多个 worker 进程,基本的事件处理都是放在
woker 中,master 负责一些全局初始化,以及对 worker 的管理。在OpenResty中,每个 woker 使用一个
LuaVM,当请求被分配到 woker 时,将在这个 LuaVM 里创建一个 coroutine(协程)。协程之间数据隔离,
每个协程具有独立的全局变量_G。
ps. 协程和多线程下的线程类似:有自己的堆栈,自己的局部变量,有自己的指令指针,但是和其他协程程序共享
全局变量等信息。线程和协程的主要不同在于:多处理器的情况下,概念上来说多线程是同时运行多个线程,而协
程是通过代码来完成协程的切换,任何时刻只有一个协程程序在运行。并且这个在运行的协程只有明确被要求挂起
时才会被挂起。

lua:

(1) Lua 是一个小巧的脚本语言。作者是巴西人。该语言的设计目的是为了嵌入应用程序中,从而为应
用程序提供灵活的扩展和定制功能
(2) Lua的特点:
Lua脚本可以很容易的被C/C++代码调用,也可以反过来调用C/C++的函数,这使得Lua在应用程序中可
以被广泛应用。不仅仅作为扩展脚本,也可以作为普通的配置文件,代替XML,Ini等文件格式,并且更容易理解和维护。
Lua由标准C编写而成,代码简洁优美,几乎在所有操作系统和平台上都可以编译,运行。一个完整的
Lua解释器不过200k,在目前所有脚本引擎中,Lua的速度是最快的。这一切都决定了Lua是作为嵌入式脚本的最佳选择。

OpenResty实验配置:

[root@server6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm           mysql-boost-5.7.17.tar.gz
Discuz_X3.2_SC_UTF8.zip                   nginx-1.10.1
gd-devel-2.0.35-11.el6.x86_64.rpm         nginx-1.10.1.tar.gz
libevent-devel-1.4.13-4.el6.x86_64.rpm    nginx-sticky-module-ng
libevent-doc-1.4.13-4.el6.noarch.rpm      nginx-sticky-module-ng.tar.gz
libevent-headers-1.4.13-4.el6.noarch.rpm  openresty-1.13.6.1.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm          package.xml
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm    php-5.6.35
memcache-2.2.5                            php-5.6.35.tar.bz2
memcache-2.2.5.tgz                        re2c-0.13.5-1.el6.x86_64.rpm
mysql-5.7.17
[root@server6 ~]# tar zxf openresty-1.13.6.1.tar.gz  解压包
[root@server6 ~]# cd openresty-1.13.6.1  进入源码编译包
[root@server6 openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio && gmake && gmake install

这里写图片描述

关闭nginx:

[root@server6 ~]#nginx -s stop

这里写图片描述

[root@server6 etc]# cd /usr/local/lnmp/openresty/nginx/conf/
[root@server6 conf]# ls
fastcgi.conf            koi-win             scgi_params
fastcgi.conf.default    mime.types          scgi_params.default
fastcgi_params          mime.types.default  uwsgi_params
fastcgi_params.default  nginx.conf          uwsgi_params.default
koi-utf                 nginx.conf.default  win-utf
[root@server6 conf]# vim nginx.conf  编辑主配置文件
#user  nobody;
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 {

        upstream memcache {
        server localhost:11211;
        keepalive 512;
        }

    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;
 location / {
            root   html;
            index  index.php 在真机测试速度对比,加入了memcache明显加速了:

[root@foundation38 Desktop]# ab -c 10 -n 1000 http://172.25.38.7/example.php
This is ApacheBench, Version 2.3 < R e v i s i o n : 1430300 >
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.38.7 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: openresty/1.13.6.1
Server Hostname: 172.25.38.7
Server Port: 80

Document Path: /example.php
Document Length: 16 bytes

Concurrency Level: 10
Time taken for tests: 0.461 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 192000 bytes
HTML transferred: 16000 bytes
Requests per second: 2170.07 [#/sec] (mean)
Time per request: 4.608 [ms] (mean)
Time per request: 0.461 [ms] (mean, across all concurrent requests)
Transfer rate: 406.89 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 4
Processing: 1 4 0.8 4 8
Waiting: 1 4 0.8 4 8
Total: 2 5 0.8 4 9
WARNING: The median and mean for the total time are not within a normal deviation
These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
50% 4
66% 5
75% 5
80% 5
90% 6
95% 6
98% 7
99% 7
100% 9 (longest request)
[root@foundation38 Desktop]# ab -c 10 -n 1000 http://172.25.38.7/index.php
This is ApacheBench, Version 2.3 < R e v i s i o n : 1430300 >
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.38.7 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: openresty/1.13.6.1
Server Hostname: 172.25.38.7
Server Port: 80

Document Path: /index.php
Document Length: 16 bytes

Concurrency Level: 10
Time taken for tests: 0.472 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 192000 bytes
HTML transferred: 16000 bytes
Requests per second: 2120.46 [#/sec] (mean)
Time per request: 4.716 [ms] (mean)
Time per request: 0.472 [ms] (mean, across all concurrent requests)
Transfer rate: 397.59 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 5
Processing: 1 5 1.1 4 9
Waiting: 1 5 1.1 4 9
Total: 2 5 1.2 4 9

Percentage of the requests served within a certain time (ms)
50% 4
66% 5
75% 5
80% 5
90% 6
95% 7
98% 8
99% 9
100% 9 (longest request)

![这里写图片描述](https://img-blog.csdn.net/2018080518165169?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2FhYWFhYWJf/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
![这里写图片描述](https://img-blog.csdn.net/20180805181659134?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2FhYWFhYWJf/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
index.html index.htm;
        }

        location /memc {
        internal;
        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        set $memc_key $query_string;
        set $memc_exptime 300;
        memc_pass memcache;
        }


        #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$ {
            set $key $uri$args;
            srcache_fetch GET /memc $key;
            srcache_store PUT /memc $key;
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
 #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

   # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #
    }
[root@server6 conf]# /usr/local/lnmp/openresty/nginx/sbin/nginx -t  检测语法
nginx: the configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf test is successful

在网页访问可以看到openresty的访问界面,由于默认访问的是PHP,所以是以下实验效果:

这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/aaaaaab_/article/details/81428133