CentOS 6.7 源码搭建LNMP架构部署动态网站环境

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: lnmp

源码搭建LNMP架构部署动态网站环境
Nginx 简介
Nginx是一款相当优秀的用于部署动态网站的服务程序,Nginx具有不错的稳定性、丰富的功能以及占用较少的系统资源等独特特性。
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器。Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度BWS、新浪、网易、腾讯等。
通过部署Linux+Nginx+MYSQL+PHP这四种开源软件,便拥有了一个免费、高效、扩展性强、资源消耗低的LNMP动态网站架构了
源码安装程序
很多软件产品只会以源码包的方式发布,如果只会用RPM命令就只能去互联网大海洋中慢慢寻找到由第三方组织或黑客们编写的RPM软件包后才能安装程序了,并且源码程序的可移植性非常好,可以针对不同的系统架构而正确运行,但RPM软件包则必需严格符合限制使用的平台和架构后才能顺利安装,所以建议即便在工作中可以很舒服的用Yum仓库来安装服务程序,源码安装的流程也一定要记清:
第一步 解压文件
源码包通常会使用tar工具归档然后用gunzip或bzip2进行压缩,后缀格式会分别为.tar.gz与tar.bz2 ,解压方法:
[root@vdevops package]# tar zxvf filename.tar.gz
[root@vdevops package]# tar jvvf filename.tar.bz2

tar zxvf filename.tar.gz -C FileDirectory

第2步,切换到解压后的目录:

[root@vdevops ~]# cd FileDirectory
第3步:准备编译工作:

在开始安装服务程序之前,先阅读readme文件,然后需要执行configure脚本,他会自动的对当前系统进行一系列的评估,如源文件、软件依赖性库、编译器、汇编器、连接器检查等等,如果有需求,还可以使用--prefix参数来指定程序的安装路径(很实用),而当脚本检查系统环境符合要求后,则会在当前目录下生成一个Makefile文件。

[root@vdevops ~]# ./configure --prefix=/usr/local/program

configure之前可以先configure –help查看都有哪些参数,可以自定义编译之后的文件目录,通过--prefix=/opt/servername

第4步:生成安装程序:

刚刚生成的Makefile文件会保存有系统环境依赖关系和安装规则,接下来需要使用make命令来根据MakeFile文件提供的规则使用合适的SHELL来编译所有依赖的源码,然后make命令会生成一个最终可执行的安装程序。

[root@vdevops ~]# make
第5步:安装服务程序:

如果在configure脚本阶段中没有使用--prefix参数,那么程序一般会被默认安装到/usr/local/bin目录中。

[root@vdevops ~]# make install
第6步:清理临时文件(可选):

[root@vdevops ~]# make clean
卸载服务程序的命令(请不要随便执行!!!):

[root@vdevops ~]# make uninstall

部署LNMP架构
LNMP(即Linux+Nginx+MYSQL+PHP)是目前非常热门的动态网站部署架构,一般是指:

Linux:如RHEL、Centos、Debian、Fedora、Ubuntu等系统。
Nginx:高性能、低消耗的HTTP与反向代理服务程序。
MYSQL:热门常用的数据库管理软件。
PHP:一种能够在服务器端执行的嵌入HTML文档的脚本语言。
Tengine:
Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。(可以这样理解:淘宝拿到了Nginx源代码之后,进行了功能的填充,优化等等,然后提交给Nginx官方,但是由于Nginx官方相应慢或者不响应,加上语言沟通的不顺畅,于是淘宝公司就自己打包,在遵循GPL的原则上进行二次开发,于是就出了现在的Tengine这个版本)。
官网网站:http://tengine.taobao.org/

Nginx工作原理:
对比apache的工作原理,对php文件处理过程的区别
1:nginx是通过php-fpm这个服务来处理php文件
2:apache是通过libphp5.so这个模块来处理php文件
Nginx:

Apache

Apache的libphp5.so随着apache服务器一起运行,而Nginx和php-fpm是各自独立运行,所以在运行过程中,Nginx和php-fpm都需要分别启动!
修改Nginx配置文件,启动nginx服务,修改php配置文件,启动php-fpm服务
nginx相对于apache的优点: 
轻量级,同样起web 服务,比apache 占用更少的内存及资源 ;高并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能保持低资源低消耗高性能;高度模块化的设计,编写模块相对简单;社区活跃,各种高性能模块出品迅速。
apache 相对于nginx 的优点: 
rewrite ,比nginx 的rewrite强大;模块超多,基本想到的都可以找到;少bug ,nginx 的bug 相对较多;超稳定 
存在就是理由,一般来说,需要性能的web 服务,用nginx 。如果不需要性能只求稳定,那就apache 。nginx处理动态请求是鸡肋,一般动态请求要apache去做,nginx只适合静态和反向。 

部署LNMP架构需要安装依赖包
yum -y install make gcc gcc-c++ flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel gd freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel unzip libcap lsof

系统初始配置:
yum update –y && yum -y install vim wget unzip lrzsz
关闭防火墙:

[root@vdevops nginx-1.9.15]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@vdevops nginx-1.9.15]# chkconfig iptables off
禁用selinux
[root@vdevops ~]# getenforce #查看selinux状态
Enforcing
[root@vdevops nginx-1.9.15]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux #永久关闭
临时关闭(不用重启机器): setenforce 0
安装nginx
http://nginx.org/
wget http://nginx.org/download/nginx-1.9.15.tar.gz -P /usr/local/src/

Mainline version 主线版本

Stable version    稳定版本
Legacy versions     老版本,遗产版本

所需依赖包:
[root@vdevops ~]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel
zlib:Nginx提供gzip模块,需要zlib的支持

      openssl:Nginx提供SSL的功能

wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.zip -P /usr/local/src/

 nginx rewrite依赖于PCRE库

[root@vdevops src]# unzip pcre-8.38.zip -d /usr/local/

创建Nginx运行用户:
[root@vdevops ~]# groupadd nginx
[root@vdevops ~]# useradd nginx -g nginx -M -s /sbin/nologin
cd /usr/local/src
[root@vdevops src]# tar xvf nginx-1.9.15.tar.gz
cd nginx-1.9.15
[root@vdevops nginx-1.9.15]# ./configure --prefix=/opt/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/pcre-8.38 --user=nginx --group=nginx

注:
--with-http_dav_module #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)

                                默认关闭,需要编译开启

--with-http_stub_status_module #启用支持(获取Nginx上次启动以来的工作状态)
--with-http_addition_module #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module #启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module #启用支持(提供支持flv视频文件支持)
--with-http_mp4_module #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)
--with-pcre=/usr/local/pcre-8.37 #需要注意,这里指的是源码,用#./configure --help |grep pcre查看帮助
[root@vdevops nginx-1.9.15]# make -j 4 && make install
-j 4 使用4个cpu进行编译,加快编译速度
[root@vdevops nginx-1.9.15]# ll /opt/nginx/
total 16
drwxr-xr-x. 2 root root 4096 Apr 25 14:12 conf #Nginx相关配置文件
drwxr-xr-x. 2 root root 4096 Apr 25 14:12 html #网站根目录
drwxr-xr-x. 2 root root 4096 Apr 25 14:12 logs #日志文件
drwxr-xr-x. 2 root root 4096 Apr 25 14:12 sbin #Nginx启动脚本

配置Nginx支持php文件
[root@vdevops nginx-1.9.15]# vim /opt/nginx/conf/nginx.conf

启动Nginx服务
[root@vdevops nginx-1.9.15]# /opt/nginx/sbin/nginx
优化nginx启动命令执行路径
[root@vdevops init.d]# ln -s /opt/nginx/sbin/nginx /usr/local/sbin/
[root@vdevops init.d]# vim /etc/init.d/nginx
编辑nginx启动脚本

! /bin/sh

chkconfig: 2345 55 25

Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and

run 'update-rc.d -f nginx defaults', or use the appropriate command on your

distro. For CentOS/Redhat run: 'chkconfig --add nginx'

BEGIN INIT INFO

Provides: nginx

Required-Start: $all

Required-Stop: $all

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: starts the nginx web server

Description: starts nginx using start-stop-daemon

END INIT INFO

Author: licess

website: http://lnmp.org

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/opt/nginx/sbin/$NAME
CONFIGFILE=/opt/nginx/conf/$NAME.conf
PIDFILE=/opt/nginx/logs/$NAME.pid

case "$1" in

start)
    echo -n "Starting $NAME... "

    if netstat -tnpl | grep -q nginx;then
        echo "$NAME (pid `pidof $NAME`) already running."
        exit 1
    fi

    $NGINX_BIN -c $CONFIGFILE

    if [ "$?" != 0 ] ; then
        echo " failed"
        exit 1
    else
        echo " done"
    fi
    ;;

stop)
    echo -n "Stoping $NAME... "

    if ! netstat -tnpl | grep -q nginx; then
        echo "$NAME is not running."
        exit 1
    fi

    $NGINX_BIN -s stop

    if [ "$?" != 0 ] ; then
        echo " failed. Use force-quit"
        exit 1
    else
        echo " done"
    fi
    ;;

status)
    if netstat -tnpl | grep -q nginx; then
        PID=`pidof nginx`
        echo "$NAME (pid $PID) is running..."
    else
        echo "$NAME is stopped"
        exit 0
    fi
    ;;

force-quit)
    echo -n "Terminating $NAME... "

    if ! netstat -tnpl | grep -q nginx; then
        echo "$NAME is not running."
        exit 1
    fi

    kill `pidof $NAME`

    if [ "$?" != 0 ] ; then
        echo " failed"
        exit 1
    else
        echo " done"
    fi
    ;;

restart)
    $0 stop
    sleep 1
    $0 start
    ;;

reload)
    echo -n "Reload service $NAME... "

    if netstat -tnpl | grep -q nginx; then
        $NGINX_BIN -s reload
        echo " done"
    else
        echo "$NAME is not running, can't reload."
        exit 1
    fi
    ;;

configtest)
    echo -n "Test $NAME configure files... "

    $NGINX_BIN -t
    ;;

*)
    echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
    exit 1
    ;;

esac
设置nginx开机自启动
[root@vdevops init.d]# chmod +x /etc/init.d/nginx
[root@vdevops init.d]# chkconfig --add nginx
[root@vdevops init.d]# chkconfig nginx on
浏览器访问验证:

扩展:nginx维护命令
[root@vdevops init.d]# nginx –t #检查配置文件是否有语法错误
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

[root@vdevops init.d]# nginx –V #查看nginx配置参数
nginx version: nginx/1.9.15
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
configure arguments: --prefix=/opt/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/pcre-8.38 --user=nginx --group=nginx

注意:重新编译时,一定要查看以前的编译配置,只需要在原有的配置参数后添加新的参数即可。
[root@vdevops init.d]# nginx -s reload #平滑重载nginx配置文件,不需要重启nginx服务
测试nginx启动脚本

安装mysql
http://www.mysql.com/
查看系统中是否已自带mysql相关
[root@vdevops ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-5.el6_6.x86_64
删除自带的mysql相关
[root@vdevops ~]# yum remove mysql –y
下载最新的mysql源码包
[root@vdevops init.d]# wget -c http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12.tar.gz -P /usr/local/src/
新建mysql用户和mysql组
[root@vdevops init.d]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
[root@vdevops ~]# cd /usr/local/src/
[root@vdevops src]# md5sum mysql-5.7.12.tar.gz #[md5校验]
af17ba16f1b21538c9de092651529f7c mysql-5.7.12.tar.gz
[root@vdevops src]# tar zxvf mysql-5.7.12.tar.gz && cd mysql-5.7.12
创建mysql安装目录和数据存放目录,虚拟机添加一块新的硬盘,创建分区/dev/sdb1,并分配所有空间
[root@vdevops src]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@vdevops src]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_vdevops 1 2 0 wz--n- 19.80g 0
[root@vdevops src]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@vdevops src]# vgextend vg_vdevops /dev/sdb1
Volume group "vg_vdevops" successfully extended
[root@vdevops src]# lvcreate -n data -L 19G vg_vdevops
Logical volume "data" created.
[root@vdevops src]# mkfs.ext4 /dev/vg_vdevops/data
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5236736 blocks
261836 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@vdevops src]# lvextend -L +1000M /dev/vg_vdevops/data
Size of logical volume vg_vdevops/data changed from 19.00 GiB (4864 extents) to 19.98 GiB (5114 extents).
Logical volume data successfully resized
[root@vdevops src]# resize2fs /dev/vg_vdevops/data
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_vdevops/data to 5240832 (4k) blocks.
The filesystem on /dev/vg_vdevops/data is now 5240832 blocks long.
[root@vdevops src]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_vdevops 2 3 0 wz--n- 39.79g 0
[root@vdevops src]# mkdir /data
[root@vdevops src]# mount /dev/vg_vdevops/data /data/
[root@vdevops src]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_vdevops-LogVol01

                   18G  1.5G   16G   9% /

tmpfs 935M 0 935M 0% /dev/shm
/dev/sda1 190M 37M 143M 21% /boot
/dev/mapper/vg_vdevops-data

                   20G   44M   19G   1% /data

开机自动挂载data目录
[root@vdevops src]# echo "/dev/sdb1 /data ext4 defaults 0 0" >> /etc/fstab
注意:mysql-5.7.12安装时占用空间比较大,虚拟机环境下建议新添加一块硬盘,并加到同一个lvm组中,真是服务器不需要,按照下面步骤扩展lvm
安装必须软件包
建议使用网络yum源,mysql-5.7.12.tar.gz的编译对软件包的版本要求比较高,其中cmake的版本要不低于2.8

[root@vdevops src]# yum -y install gcc gcc-c++ autoconf automake zlib libxml ncurses-devel libtool-ltdl-devel* make

编译Cmake编译工具

[root@vdevops src]# rpm -qa | grep cmake
[root@vdevops src]# wget -c http://git.typecodes.com/libs/ccpp/cmake-3.2.1.tar.gz
[root@vdevops src]# tar zxvf cmake-3.2.1.tar.gz && cd cmake-3.2.1 && ./configure
[root@vdevops cmake-3.2.1]# make && make install
[root@vdevops cmake-3.2.1]# ln -s /usr/local/bin/cmake /usr/bin/cmake
[root@vdevops cmake-3.2.1]# cmake --version
cmake version 3.2.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Boost库,一个开源可移植的C++库,是C++标准化进程的开发引擎之一。

[root@vdevops src]# wget -c http://liquidtelecom.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz -P /usr/local/src/
注:从mysql-5.7.5之后源码编译,必须编译boost库
[root@vdevops src]# mkdir -p /data/mysql/data
[root@vdevops src]# tar zxvf boost_1_59_0.tar.gz

[root@vdevops src]# tar zxvf mysql-5.7.12.tar.gz
[root@vdevops src]# mv boost_1_59_0 /data/boost

bison:GUN分析生成器

[root@vdevops src]# tar zxvf bison-3.0.tar.gz && cd bison-3.0 && ./configure
[root@vdevops src]# make && make install

Mysql编译配置相关参数:
[root@vdevops src]# cd mysql-5.7.12
[root@vdevops mysql-5.7.12]# cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data/boost
[root@vdevops mysql-5.7.12]# grep processor /proc/cpuinfo | wc -l
2
[root@vdevops mysql-5.7.12]# make -j 2 && make install

CMAKE_INSTALL_PREFIX:指定MySQL程序的安装目录,默认/usr/local/mysql
DEFAULT_CHARSET:指定服务器默认字符集,默认latin1
DEFAULT_COLLATION:指定服务器默认的校对规则,默认latin1_general_ci
ENABLED_LOCAL_INFILE:指定是否允许本地执行LOAD DATA INFILE,默认OFF
WITH_COMMENT:指定编译备注信息
WITH_xxx_STORAGE_ENGINE:指定静态编译到mysql的存储引擎,MyISAM,MERGE,MEMBER以及CSV四种引擎默认即被编译至服务器,不需要特别指定。
WITHOUT_xxx_STORAGE_ENGINE:指定不编译的存储引擎
SYSCONFDIR:初始化参数文件目录
MYSQL_DATADIR:数据文件目录
MYSQL_TCP_PORT:服务端口号,默认3306
MYSQL_UNIX_ADDR:socket文件路径,默认/tmp/mysql.sock
看到下图代表已经编译安装好了mysql-5.7.12

编译完成后,建议到/data/mysql/support-files/下面查看相关配置文件。
[root@vdevops ~]# cd /data/mysql/support-files/
[root@vdevops support-files]# ll
total 28
-rw-r--r--. 1 mysql mysql 773 Mar 29 02:06 magic
-rw-r--r--. 1 mysql mysql 1126 Apr 25 17:58 my-default.cnf
-rwxr-xr-x. 1 mysql mysql 1061 Apr 25 17:58 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql 869 Apr 25 17:58 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10945 Apr 25 17:58 mysql.server
查看编译成功之后的MySQL安装
使用如下两条命令,查看MySQL的安装目录 /usr/local/mysql/ 下面是否生成了相关目录文件(最重要的当然是bin、sbin和lib目录)。如果lib目录下面没有生成如图所示的.so动态库文件和.a静态库文件,那么说明安装不成功(即使成功了也可能会导致php进程无法找到mysql的相关库文件)

开始设置MySQL的配置文件my.cnf
先把编译生成的my.cnf文件备份,然后把自己之前整理过的mysql配置文件,上传到当前服务器的/etc目录下即可。

如果默认my.cnf不存在,需要手动新建
[root@vdevops etc]# vim /etc/my.cnf
添加以下配置内容,相关参数可根据实际情况情绪调整。

For advice on how to change settings please see

http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

* DO NOT EDIT THIS FILE. It's a template which will be copied to the

* default location during install, and will be replaced if you

* upgrade to a newer version of MySQL.

[client]
port=3306
socket=/data/mysql/mysql.sock

[mysqld]

Remove leading # and set to the amount of RAM for the most important data

cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

innodb_buffer_pool_size = 128M

Remove leading # to turn on a very important data integrity option: logging

changes to the binary log between backups.

log_bin

These are commonly set, remove the # and set as required.

user = mysql
basedir = /data/mysql
datadir = /data/mysql/data
port=3306
server-id = 1
socket=/data/mysql/mysql.sock

character-set-server = utf8
log-error = /data/mysql/error.log
pid-file = /data/mysql/mysql.pid
general_log = 1
skip-name-resolve

skip-networking

back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30

performance_schema = 0
explicit_defaults_for_timestamp

lower_case_table_names = 1

myisam_sort_buffer_size = 8M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800

Remove leading # to set options mainly useful for reporting servers.

The server defaults are faster for transactions and fast SELECTs.

Adjust sizes as needed, experiment to find the optimal values.

join_buffer_size = 128M

sort_buffer_size = 2M

read_rnd_buffer_size = 2M

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

Recommended in standard MySQL setup

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

添加mysql的环境变量
将MySQL生成的bin目录添加到当前Linux系统的环境变量中
[root@vdevops etc]# echo -e 'nnexport PATH=/data/mysql/bin:$PATHn' >> /etc/profile && source /etc/profile
[root@vdevops etc]# cat /etc/profile
能看到添加MySQL环境变量已经成功

修改MySQL数据库文件存放路径权限以及相关安全配置
文中前面已经创建过/data/mysql/data,用于存放MySQL的数据库文件,同时设置其用户和用户组为之前创建的mysq,权限700,这样其他用户无法进行读写,尽量保证数据库的安全。
[root@vdevops ~]# chown -R mysql:mysql /data/mysql
[root@vdevops ~]# chmod -R go-rwx /data/mysql/data
查看相关目录权限已经设置OK

初始化MySQL自身的数据库
在MySQL安装目录的 bin 路径下,执行mysqld命令,初始化MySQL自身的数据库。

参数user表示用户,basedir表示mysql的安装路径,datadir表示数据库文件存放路径

[root@vdevops ~]# /data/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --basedir=/data/mysql/data

注:查看error.log,ll -rt /data/mysql/data/ 确保MySQL数据库初始化成功,否侧后面启动MySQL服务会报错。
设置MySQL日志文件存放目录以及设置开机自动
默认配置文件中都已经设置OK,如需更改建议放到/var/log下面

[root@vdevops ~]# mkdir -p /var/run/mysql && mkdir -p /var/log/mysql

[root@vdevops ~]# chown -R mysql:mysql /var/log/mysql && chown -R mysql:mysql /var/run/mysql

本文中默认全部放到mysql目录下面,便于管理。

设置开机自启动

[root@vdevops ~]# cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@vdevops ~]# chmod +x /etc/init.d/mysqld
[root@vdevops ~]# chkconfig mysqld on
启动MySQL服务
完成上面的操作之后,就可以正式启动MySQL服务,启动MySQL进程服务的命令如下:
[root@vdevops ~]# mysqld_safe --user=mysql --datadir=/data/mysql/data/ --log-error=/data/mysql/error.log &

启动报错,查看error.log,分析相关原因,此次报错问题在于mysql目录权限赋予的不正确,导致MySQL数据库初始化失败。
[root@vdevops ~]# ntpdate time.nist.gov
5 May 11:02:31 ntpdate[16405]: step time server 216.229.0.179 offset 791817.941700 sec
[root@vdevops ~]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!
然后使用下面这2个命令查看MySQL服务进程和端口监听情况:
[root@vdevops ~]# ps -ef | grep mysql
[root@vdevops ~]# netstat -nlpt | grep 3306

初始化MySQL数据库的root用户密码
和Oracle数据库一样,MySQL数据库也默认自带了一个 root 用户(这个和当前Linux主机上的root用户是完全不搭边的),我们在设置好MySQL数据库的安全配置后初始化root用户的密码。配制过程中,一路输入 y 就行了。这里只说明下MySQL5.7.7rc版本中,用户密码策略分成低级 LOW 、中等 MEDIUM 和超强 STRONG三种,推荐使用中等 MEDIUM 级别!

LOW:【只需要长度大于或等于8】

MEDIUM:【还需要包含数字、大小写和类似于@#%等特殊字符】

STRONG:【还需要包含字典文件】

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

删除匿名用户

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

禁止root用户登录

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

  • Dropping test database...
    Success.

删除测试库

  • Removing privileges on test database...
    Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

刷新权限

All done!
登录测试

将ySQL数据库的动态链接库共享至系统链接库
通常MySQL数据库还会被类似于PHP等服务调用,因此我们需要将MySQL编译后的lib库文件添加到当前Linux主机链接库/etc/ld.so.conf.d/下,这样MySQL服务就可以被其他服务调用了。
[root@vdevops ~]# echo "/data/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@vdevops ~]# ldconfig #使生效
[root@vdevops ~]# ldconfig -v | grep mysql #查看效果
ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-573.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg
/data/mysql/lib:

libmysqlclient.so.20 -> libmysqlclient.so.20.2.1

创建其他MySQL数据库用户
使用MySQL数据库root管理员用户登录MySQL数据库后,可以管理数据库和其他用户。这里创建一个名为vdevops的MySQL用户(密码为:@Vdevops1217.com)和名为vdevops的数据库。
[root@vdevops ~]# mysql -u root -p (初始化数据库用户时设置的密码)
mysql> CREATE DATABASE vdevops DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on vdevops.* to vdevops@localhost identified by '@Vdevops1217.com';
Query OK, 0 rows affected, 2 warnings (0.06 sec)

mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
query
User: 'mysql.sys'@'localhost';
User: 'root'@'localhost';
User: 'vdevops'@'localhost';

3 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

MySQL编译安装时常见错误分析
1 没有安装MySQL所需要的boost库

测试发现编译MySQL5.7以及更高的版本时,都需要下载并引用或者直接安装boost库,否则在执行cmake命令时会报如下错误:

-- Running cmake version 3.2.1
-- Configuring with MAX_INDEXES = 64U
-- SIZEOF_VOIDP 8
-- MySQL 5.7.6-m16 [MySQL版本]
-- Packaging as: mysql-5.7.6-m16-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_57_0 [解决办法]

CMake Error at cmake/boost.cmake:76 (MESSAGE): [具体错误和解决方法]
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=

This CMake script will look for boost in . 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:228 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:452 (INCLUDE)

-- Configuring incomplete, errors occurred!
See also "/mydata/mysql-5.7.6-m16/CMakeFiles/CMakeOutput.log".
解决方法:直接按照前文《2015博客升级记(四):CentOS 7.1编译安装MySQL5.7.7rc》小节2中的方法安装Boost库即可。或者先下载Boost库,然后通过在cmake命令后面添加参数-DDOWNLOAD_BOOST=1 -DWITH_BOOST=Boost库路径即可。

2 执行cmake时缺少Ncurses库的支持

Ncurses提供功能键定义(快捷键),屏幕绘制以及基于文本终端的图形互动功能的动态库。

[root@typecodes ~]# yum -y install ncurses-devel

-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,

  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:181 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:480 (MYSQL_CHECK_EDITLINE)

-- Configuring incomplete, errors occurred!
See also "/mydata/mysql-5.7.6-m16/CMakeFiles/CMakeOutput.log".
See also "/mydata/mysql-5.7.6-m16/CMakeFiles/CMakeError.log".
解决方法:直接执行命令yum -y install ncurses-devel安装Ncurses即可。

3 安装MySQL完后,无法正常启动服务

在安装完MySQL后,执行命令service mysqld start失败,也即无法正常启动MySQL服务。

无法正常启动MySQL服务

解决方法:主要通过命令systemctl status mysqld.service和MySQL的日志来分析。如上图所示,在日志文件/var/log/mysql/error.log中可以看到具体的ERROR信息:Could not create unix socket lock file /var/run/mysql/mysql.sock.lock。这种错误一般都是目录不存在或者权限不足,所以我们直接使用命令mkdir -p /var/log/mysql/创建该目录即可,然后可以设置目录权限chown -R mysql:mysql /var/log/mysql/。

4 操作MySQL时,报错You must SET PASSWORD before executing this statement

用MySQL的root用户登录数据库后,如果之前没有设置密码,那么执行任何操作命令时,会提示如下错误信息。

mysql> CREATE DATABASE testmysqldatabase DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
常规的使用MySQL安全模式的解决方法如下,但是在MySQL5.7以及更高版本下是行不通的。

[root@typecodes ~]# service mysqld stop
Shutting down MySQL..[ OK ]
[root@typecodes ~]# /mydata/mysql/bin/mysqld_safe --user=mysql --skip-networking --skip-grant-tables &
[1] 3688
[root@typecodes ~]# 150409 23:02:02 mysqld_safe Logging to '/var/log/mysql/error.log'.
150409 23:02:02 mysqld_safe Starting mysqld daemon with databases from /mydata/mysql/data

重新登录mysql后,设置root密码

mysql> set password='this is a password sample';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
有效的解决方法:

[root@typecodes ~]# mysql -u root -p [使用root用户登录]
Enter password: [无密码,直接回车]
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.6-m16

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

Oracle is a registered trademark of Oracle Corporation and/or its

  1. Other names may be trademarks of their respective
    owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> select * from mysql.user;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> set password='this is a password sample';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

设置当前root用户密码

mysql> set password='your password';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
需要说明的是,修改用户密码的SQL语句在不同的MySQL版本中是不同的。下面这3种是MySQL5.5以下的版本的修改方法,但是不适用于MySQL5.7以及更高版本。

mysql> update mysql.user set PASSWORD='your password' where User='root';

mysql> SET PASSWORD for root@'localhost' = PASSWORD('your password');

mysql> SET PASSWORD = PASSWORD('your password');
到此MySQL-5.7.12编译安装全部完成。
安装PHP
在Nginx中,我们使用的是php-fpm来对php页面解析,PHP-FPM其实是PHP源代码的一个补丁,指在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,再编译安装PHP后才可以使用

从PHP5.3.3开始,PHP中直接整合了PHP-FPM,所以从PHP5.3.3版本以后,不需要下载PHP-FPM补丁包了,下面是PHP-FPM官方发出来的通知:
http://php-fpm.org/download

http://php.net/downloads.php

php-7.0.6.tar.gz (sig) [17,781Kb]
md5:c9e2ff2d6f843a584179ce96e63e38f9
sha256:f6b47cb3e02530d96787ae5c7888aefbd1db6ae4164d68b88808ee6f4da94277
可自行校验wget的安装包是否完整
http://cn2.php.net/distributions/php-7.0.6.tar.gz
安装依赖关系
依赖包下载地址
https://curl.haxx.se/download/curl-7.48.0.tar.gz
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
http://iweb.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
[root@vdevops ~]# wget -c http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz -P /usr/local/src/
[root@vdevops ~]# wget -c http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz -P /usr/local/src/
[root@vdevops ~]# wget -c http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz -P /usr/local/src/
[root@vdevops ~]# wget -c http://iweb.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz -P /usr/local/src/

libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。 错误提示:configure: error: Please reinstall the iconv library.
[root@vdevops ~]# cd /usr/local/src/
[root@vdevops src]# tar zxvf libiconv-1.14.tar.gz && cd libiconv-1.14
[root@vdevops libiconv-1.14]# ./configure --prefix=/usr/local/libiconv
[root@vdevops libiconv-1.14]# make -j 2 && make install
libmcrypt是加密算法扩展库。 错误提示:configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.
[root@vdevops ~]# cd /usr/local/src/
[root@vdevops src]# tar zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8
[root@vdevops libmcrypt-2.5.8]# ./configure && make -j 2 && make install
Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。 mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存 错误提示:configure: error: “You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/
[root@vdevops src]# tar zxvf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9
[root@vdevops mhash-0.9.9.9]# ./configure && make -j 2 && make install
mcrypt 是 php 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。
[root@vdevops src]# tar zxvf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8
[root@vdevops mcrypt-2.6.8]# ./configure && make -j 2 && make install
checking for libmcrypt-config... no
checking for libmcrypt - version >= 2.5.0... no
* Could not run libmcrypt test program, checking why...
* The test program failed to compile or link. See the file config.log for the
* exact error that occured. This usually means LIBMCRYPT was incorrectly installed
* or that you have moved LIBMCRYPT since it was installed. In the latter case, you
* may want to edit the libmcrypt-config script: no
configure: error: * libmcrypt was not found
解决办法:
gcc编译的时候根据自身定义的变量寻找相关函数库等文件,libmcrypt也是刚安装的,在变量中没有定义出来,所以手动添加:
export LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH
[root@vdevops etc]# echo -e 'nnexport LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATHn' >> /etc/profile && source /etc/profile
[root@vdevops ~]# yum -y install php-pear
pear按照一定的分类来管理pear应用代码库,你的pear代码可以组织到其中适当的目录中,其他人可以方便的检索并分享到你的成果;pear不仅仅是一个代码仓库,它同时也是一个标准,使用这个标准来书写你的php代码,将会增强你的程序的可读性,复用性,减少出错的几率;Pear通过两个类为你搭建了一个框架,实现了诸如析构函数,错误捕获功能,你通过继承就可以使用这些功能.
编译安装php
[root@vdevops ~]# cd /usr/local/src/
[root@vdevops php-7.0.6]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php/ --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
报错:

[root@vdevops php-7.0.6]# rpm -qa | grep curl
curl-7.19.7-46.el6.x86_64
python-pycurl-7.19.0-8.el6.x86_64
libcurl-7.19.7-46.el6.x86_64
[root@vdevops php-7.0.6]# rpm -e --nodeps curl-7.19.7-46.el6.x86_64
[root@vdevops libmcrypt-2.5.8]# wget -c https://curl.haxx.se/download/curl-7.48.0.tar.gz -P /usr/local/src/
[root@vdevops ~]# cd /usr/local/src/
[root@vdevops src]# tar zxvf curl-7.48.0.tar.gz && cd curl-7.48.0
[root@vdevops curl-7.48.0]# ./configure && make -j 2 && make install

继续编译php,报下面错误
解决:[root@vdevops php-7.0.6]# yum install libjpeg-devel –y

解决:[root@vdevops php-7.0.6]# yum install libpng-devel –y

解决:[root@vdevops php-7.0.6]# yum install freetype-devel –y
出现上图界面,编译php中./configure完成,然后
[root@vdevops php-7.0.6]# make -j 2 && make install

注:
--with-config-file-path #设置 php.ini 的搜索路径。默认为 PREFIX/lib
--with-mysql #mysql安装目录,对mysql的支持
--with-mysqli #mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。是一个数据库驱动
--with-iconv-dir #种字符集间的转换
--with-freetype-dir #打开对freetype字体库的支持
--with-jpeg-dir #打开对jpeg图片的支持
--with-png-dir #打开对png图片的支持
--with-zlib #打开zlib库的支持,实现GZIP压缩输出
--with-libxml-dir=/usr #打开libxml2库的支持,libxml是一个用来解析XML文档的函数库
--enable-xml #支持xml文档
--disable-rpath #关闭额外的运行库文件
--enable-bcmath #打开图片大小调整,用到zabbix监控的时候用到了这个模块
--enable-shmop #shmop共享内存操作函数,可以与c/c++通讯
--enable-sysvsem #加上上面shmop,这样就使得你的PHP系统可以处理相关的IPC函数(活动在内核级别)。
--enable-inline-optimization #优化线程
--with-curl #打开curl浏览工具的支持
--with-curlwrappers #运用curl工具打开url流 ,新版PHP5.6已弃用
--enable-mbregex #支持多字节正则表达式
--enable-fpm #CGI方式安装的启动程序,PHP-FPM服务
--enable-mbstring #多字节,字符串的支持
--with-gd #打开gd库的支持,是php处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。
--enable-gd-native-ttf #支持TrueType字符串函数库
--with-openssl #打开ssl支持
--with-mhash #支持mhash算法扩展
--enable-pcntl #freeTDS需要用到的,pcntl扩展可以支持php的多线程操作
--enable-sockets #打开 sockets 支持
--with-xmlrpc #打开xml-rpc的c语言
--enable-zip #打开对zip的支持
--enable-soap #扩展库通过soap协议实现了客服端与服务器端的数据交互操作
--with-mcrypt #mcrypt算法扩展

mysqldnd即mysql native driver简写,即是由PHP源码提供的mysql驱动连接代码.它的目的是代替旧的libmysql驱动.
PDO是一个应用层抽象类,底层和mysql server连接交互需要mysql驱动的支持. 也就是说无论你使用了何种驱动,都可以使用PDO. PDO是提供了PHP应用程序层API接口,而mysqlnd, libmysql则负责与mysql server进行网络协议交互(它并不提供php应用程序层API功能)
3. 为何要使用mysqlnd驱动?
PHP官方手册描述:
A.libmysql驱动是由mysql AB公司(现在是oracle公司)编写, 并按mysql license许可协议发布,所以在PHP中默认是被禁用的.
而mysqlnd是由php官方开发的驱动,以php license许可协议发布,故就规避了许可协议和版权的问题
B.因为mysqlnd内置于PHP源代码,故你在编译安装php时就不需要预先安装mysql server也可以提供mysql client API (mysql_connect, pdo , mysqli), 这将减化一些工作量.
C. mysqlnd是专门为php优化编写的驱动,它使用了PHP本身的特性,在内存管理,性能上比libmysql更有优势. php官方的测试是:libmysql将每条记录在内存中保存了两份,而mysqlnd只保存了一份
D. 一些新的或增强的功能
增强的持久连接
引入特有的函数mysqli_fetch_all()
引入一些性能统计函数mysqli_get_cache_stats(), mysqli_get_client_stats(), 
mysqli_get_connection_stats(),
使用上述函数,可很容易分析mysql查询的性能瓶颈!
SSL支持(从php 5.3.3开始有效)
压缩协议支持
命名管道支持(php 5.4.0开始有效)

修改fpm配置php-fpm.conf.default文件名称

[root@vdevops php-7.0.6]# cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf

复制php.ini配置文件

[root@vdevops php-7.0.6]# cp /usr/local/src/php-7.0.6/php.ini-production /opt/php/php.ini

复制php-fpm启动脚本到init.d

[root@vdevops php-7.0.6]# cp /usr/local/src/php-7.0.6/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

设置php-fpm开机自启动

[root@vdevops php-7.0.6]# chmod +x /etc/init.d/php-fpm
[root@vdevops php-7.0.6]# chkconfig --add php-fpm
[root@vdevops php-7.0.6]# chkconfig php-fpm on
[root@vdevops php-7.0.6]# /etc/init.d/php-fpm start
Starting php-fpm [05-May-2016 15:54:35] WARNING: Nothing matches the include pattern '/opt/php/etc/php-fpm.d/*.conf' from /opt/php/etc/php-fpm.conf at line 125.
[05-May-2016 15:54:35] ERROR: No pool defined. at least one pool section must be specified in config file
[05-May-2016 15:54:35] ERROR: failed to post process the configuration
[05-May-2016 15:54:35] ERROR: FPM initialization failed
解决:[root@vdevops php-7.0.6]# cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/www.conf

查看端口监听状态:
[root@vdevops php-7.0.6]# netstat -nlpt | grep php-fpm

验证php测试页:
[root@vdevops ~]# cd /opt/nginx/html/
[root@vdevops html]# vim phpinfo.php
[root@vdevops html]# cat phpinfo.php
<?php
phpinfo();
?>
浏览器输入:http://10.1.1.92/phpinfo.php

到此源码安装LNMP架构完成。

目录
相关文章
|
16天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
15 0
|
4月前
|
关系型数据库 应用服务中间件 nginx
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
|
5月前
|
存储 Linux Docker
跨cpu架构部署容器技术点:怎样修改Linux 的内核版本
在使用Docker 进行跨平台部署之后,我们还可以尝试进行跨架构部署。 从X86 架构上移植到 aarch64 上。
199 0
|
1月前
|
Kubernetes 测试技术 持续交付
探索微服务架构下的持续集成与部署最佳实践
本文将深入探讨在微服务架构下实施持续集成与部署的最佳实践,介绍如何利用现代化工具和流程来实现自动化测试、持续集成、灰度发布等关键环节,帮助开发团队提升交付效率和质量。
|
2月前
|
KVM 虚拟化 Android开发
DP读书:鲲鹏处理器 架构与编程(十二)鲲鹏软件实战案例Docker+KVM的部署
DP读书:鲲鹏处理器 架构与编程(十二)鲲鹏软件实战案例Docker+KVM的部署
54 1
|
2月前
|
云计算 开发者 Docker
深入浅出:使用Docker部署微服务架构
在当今快速迭代的软件开发环境中,微服务架构凭借其灵活性和可扩展性成为了热门趋势。本文将探讨如何利用Docker这一强大的容器化技术,简化和加速微服务应用的部署与管理过程。我们将从微服务的基本概念出发,逐步深入到Docker的核心功能,最后通过一个实际案例演示整个部署流程。文章旨在为开发者提供一个清晰、实用的指南,帮助他们有效地利用Docker在微服务架构下的应用部署。
27 0
|
3月前
|
API PHP 数据库
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
33 0
|
4月前
|
消息中间件 持续交付 Docker
Docker与微服务:构建和部署微服务架构的完整指南
微服务架构已经成为现代应用开发的主要范式之一,而Docker容器技术则为微服务的构建、部署和管理提供了理想的解决方案。本文将深入探讨如何使用Docker构建和部署微服务架构,提供更多示例代码和细致的指南,以帮助大家更全面地理解和运用这些关键概念。
|
4月前
|
关系型数据库 MySQL 应用服务中间件
小白带你部署LNMP分布式部署
小白带你部署LNMP分布式部署
69 0
|
4月前
|
JSON 运维 监控
云端部署:使用AWS Lambda与公司流量监控软件实现无服务器架构
在当今数字化时代,跨平台移动应用的开发已经成为企业推广业务的一项关键工作。为了更好地监控和分析应用程序的性能,公司流量监控软件的整合变得至关重要。本文将介绍如何使用AWS Lambda和公司流量监控软件,构建一个高效的无服务器架构,实现对跨平台移动应用的流量监控。
236 0