【2018.06.06學習筆記】【linux高級知識 12.1-12.5】

12.1 LNMP架構介紹

LNMP架構是指:Linux、Nginx、Mysql、PHP。與LAMP架構相似,只不過Apache服務器由Nginx代替。php

與LAMP不一樣的是,LNMP的Web服務是由Nginx提供的。其中php是做爲獨立的服務進程存在的:即php-fpm,而不是像LAMP同樣php只是Apache的一個模塊形式。css

LNMP處理請求過程:html

一、用戶瀏覽器發起訪問請求。java

二、服務器收到請求後,Nginx服務處理靜態請求,如圖片、css等。mysql

三、Nginx把動態請求發給php-fpm服務,由他進行處理。linux

四、php-fpm與mysql進行數據庫交互。nginx

五、Nginx把靜態動態請求處理結果返回給用戶。web

Nginx比Apache在靜態處理性能方面強不少,特別是圖片多的網站用戶併發能夠上幾萬。Apache作不到這點性能。sql

12.2 MySQL安裝

一、進入src目錄,下載mysql二進制包數據庫

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
--2018-06-06 22:48:38--  http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
正在解析主機 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140
正在鏈接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已鏈接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:316320366 (302M) [application/octet-stream]
正在保存至: 「mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz」

100%[===========================================================================================================================>] 316,320,366 1.11MB/s 用時 4m 29s 

2018-06-06 22:53:07 (1.12 MB/s) - 已保存 「mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz」 [316320366/316320366])

[root@localhost src]# ls
mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz  mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz

二、解壓二進制安裝包:

[root@localhost src]# tar xzvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
//省略過程
mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/graph-compare-results
mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-connect
mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/bench-init.pl
mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/innotest1b
mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-insert
mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-select

[root@localhost src]# ls
mysql-5.6.36-linux-glibc2.5-x86_64  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz  mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@localhost src]# du -sh mysql-5.6.36-linux-glibc2.5-x86_64
1.1G	mysql-5.6.36-linux-glibc2.5-x86_64

三、把二進制文件目錄移動,並更名爲mysql目錄

[root@localhost src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql/
[root@localhost src]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin  COPYING  data  docs  include  lib  man  mysql-test  README  scripts  share  sql-bench  support-files

四、建立mysql運行用戶,建立mysql的數據存放目錄

[root@localhost mysql]# useradd mysql
useradd:用戶「mysql」已存在
[root@localhost mysql]# mkdir /data/mysql/
[root@localhost mysql]# ls -l /data/mysql/
總用量 0

五、配置安裝mysql:

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper

報錯:缺乏Perl,安裝他

[root@localhost mysql]# yum list |grep -i perl |grep -i dumper
perl-Data-Dumper.x86_64                  2.145-3.el7                   base     
perl-Data-Dumper-Concise.noarch          2.020-6.el7                   epel     
perl-Data-Dumper-Names.noarch            0.03-17.el7                   epel     
perl-XML-Dumper.noarch                   0.81-17.el7                   base     
[root@localhost mysql]# yum install -y perl-Data-Dumper
已加載插件:fastestmirror
base                                                                                                                                          | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                                          | 7.0 kB  00:00:00     
epel                                                                                                                                          | 3.2 kB  00:00:00     
http://ftp.sjtu.edu.cn/centos/7.5.1804/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed to connect to 2001:da8:8000:6023::230: 網絡不可達"
正在嘗試其它鏡像。
extras                                                                                                                                        | 3.4 kB  00:00:00     
updates                                                                                                                                       | 3.4 kB  00:00:00     
(1/4): updates/7/x86_64/primary_db                                                                                                            | 2.0 MB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                                                                                             | 147 kB  00:00:00     
(3/4): epel/x86_64/updateinfo                                                                                                                 | 935 kB  00:00:01     
(4/4): epel/x86_64/primary                                                                                                                    | 3.5 MB  00:00:07     
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * epel: ftp.cuhk.edu.hk
 * extras: mirrors.zju.edu.cn
 * updates: mirror.lzu.edu.cn
epel                                                                                                                                                     12586/12586
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

=====================================================================================================================================================================
 Package                                       架構                                版本                                      源                                 大小
=====================================================================================================================================================================
正在安裝:
 perl-Data-Dumper                              x86_64                              2.145-3.el7                               base                               47 k

事務概要
=====================================================================================================================================================================
安裝  1 軟件包

總下載量:47 k
安裝大小:97 k
Downloading packages:
perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                                                                       |  47 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                              1/1 
  驗證中      : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                              1/1 

已安裝:
  perl-Data-Dumper.x86_64 0:2.145-3.el7                                                                                                                              

完畢!

繼續配置安裝二進制文件:

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
Installing MySQL system tables...2018-06-06 23:15:52 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-06-06 23:15:52 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-06-06 23:15:52 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 2294 ...
2018-06-06 23:15:52 2294 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-06-06 23:15:52 2294 [Note] InnoDB: The InnoDB memory heap is disabled
2018-06-06 23:15:52 2294 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-06-06 23:15:52 2294 [Note] InnoDB: Memory barrier is not used
2018-06-06 23:15:52 2294 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-06-06 23:15:52 2294 [Note] InnoDB: Using Linux native AIO
2018-06-06 23:15:52 2294 [Note] InnoDB: Using CPU crc32 instructions
2018-06-06 23:15:52 2294 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-06-06 23:15:52 2294 [Note] InnoDB: Completed initialization of buffer pool
2018-06-06 23:15:52 2294 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-06-06 23:15:52 2294 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-06-06 23:15:52 2294 [Note] InnoDB: Database physically writes the file full: wait...
2018-06-06 23:15:52 2294 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-06-06 23:15:52 2294 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-06-06 23:15:52 2294 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-06-06 23:15:52 2294 [Warning] InnoDB: New log files created, LSN=45781
2018-06-06 23:15:52 2294 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-06-06 23:15:52 2294 [Note] InnoDB: Doublewrite buffer created
2018-06-06 23:15:52 2294 [Note] InnoDB: 128 rollback segment(s) are active.
2018-06-06 23:15:52 2294 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-06-06 23:15:52 2294 [Note] InnoDB: Foreign key constraint system tables created
2018-06-06 23:15:52 2294 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-06-06 23:15:52 2294 [Note] InnoDB: Tablespace and datafile system tables created.
2018-06-06 23:15:52 2294 [Note] InnoDB: Waiting for purge to start
2018-06-06 23:15:53 2294 [Note] InnoDB: 5.6.36 started; log sequence number 0
2018-06-06 23:15:53 2294 [Note] Binlog end
2018-06-06 23:15:53 2294 [Note] InnoDB: FTS optimize thread exiting.
2018-06-06 23:15:53 2294 [Note] InnoDB: Starting shutdown...
2018-06-06 23:15:54 2294 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2018-06-06 23:15:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-06-06 23:15:54 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-06-06 23:15:54 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 2316 ...
2018-06-06 23:15:54 2316 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-06-06 23:15:54 2316 [Note] InnoDB: The InnoDB memory heap is disabled
2018-06-06 23:15:54 2316 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-06-06 23:15:54 2316 [Note] InnoDB: Memory barrier is not used
2018-06-06 23:15:54 2316 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-06-06 23:15:54 2316 [Note] InnoDB: Using Linux native AIO
2018-06-06 23:15:54 2316 [Note] InnoDB: Using CPU crc32 instructions
2018-06-06 23:15:54 2316 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-06-06 23:15:54 2316 [Note] InnoDB: Completed initialization of buffer pool
2018-06-06 23:15:54 2316 [Note] InnoDB: Highest supported file format is Barracuda.
2018-06-06 23:15:54 2316 [Note] InnoDB: 128 rollback segment(s) are active.
2018-06-06 23:15:54 2316 [Note] InnoDB: Waiting for purge to start
2018-06-06 23:15:55 2316 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2018-06-06 23:15:55 2316 [Note] Binlog end
2018-06-06 23:15:55 2316 [Note] InnoDB: FTS optimize thread exiting.
2018-06-06 23:15:55 2316 [Note] InnoDB: Starting shutdown...
2018-06-06 23:15:56 2316 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

  ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

[root@localhost mysql]# echo $?
0

六、安裝成功後,複製配置文件到/etc/目錄下

[root@localhost mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

七、複製啓動腳本到 /etc/init.d/目錄下

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# ls -l !$
ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10565 6月   6 23:20 /etc/init.d/mysqld

八、修改啓動腳本,增長datadir和basedir目錄

[root@localhost mysql]# vim !$
vim /etc/init.d/mysqld

#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind

# MySQL daemon start/stop script.

# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.

# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO

# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/usr/local/mysql/
datadir=/data/mysql/

九、啓動mysql服務:

[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost mysql]# ps aux|grep mysql
root       2356  0.0  0.0 113264  1640 pts/0    S    23:22   0:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql//localhost.localdomain.pid
mysql      2463  3.5 24.0 1300784 449564 pts/0  Sl   23:22   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql//localhost.localdomain.pid
root       2487  0.0  0.0 112676   988 pts/0    R+   23:22   0:00 grep --color=auto mysql
[root@localhost mysql]# netstat -lntp
Active Internet connections (only servers)
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      896/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1106/master         
tcp6       0      0 :::22                   :::*                    LISTEN      896/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1106/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2463/mysqld

十、設置開機啓動:

[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on

[root@localhost mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS!

12.3-12.4 PHP安裝

LNMP的php與LAMP的不同,須要開啓php-fpm服務。 一、到src目錄,下載php的源碼包:

[root@localhost mysql]# cd /usr/local/src/
[root@localhost src]# ls
mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz  mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2
--2018-06-07 00:00:42--  http://cn2.php.net/distributions/php-5.6.32.tar.bz2
正在解析主機 cn2.php.net (cn2.php.net)... 36.51.255.144
正在鏈接 cn2.php.net (cn2.php.net)|36.51.255.144|:80... 已鏈接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:15055569 (14M) [application/octet-stream]
正在保存至: 「php-5.6.32.tar.bz2」

100%[===========================================================================================================================>] 15,055,569   522KB/s 用時 35s    

2018-06-07 00:01:17 (422 KB/s) - 已保存 「php-5.6.32.tar.bz2」 [15055569/15055569])

二、解壓源碼包:

[root@localhost src]# tar xjvf php-5.6.32.tar.bz2
//省略過程
php-5.6.32/pear/install-pear-nozlib.phar
php-5.6.32/pear/fetch.php
php-5.6.32/pear/Makefile.frag
php-5.6.32/README.SUBMITTING_PATCH

三、建立運行php-fpm服務的用戶:

[root@localhost php-5.6.32]# less /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:997:User for polkitd:/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
mysql:x:1000:1000::/home/mysql:/bin/bash
php-fpm:x:1001:1001::/home/php-fpm:/sbin/nologin

四、配置編譯文件,若是以前編譯過php源碼包,能夠先make clean,清理編譯文件,恢復剛解壓的狀態

[root@localhost php-5.6.32]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql/ --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
checking for cc... no
checking for gcc... no
configure: error: in `/usr/local/src/php-5.6.32':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

報錯:缺乏gcc:安裝他,再繼續配置

checking libxml2 install dir... no
checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

報錯:缺乏libxml2:安裝,再繼續配置

checking for OpenSSL support... yes
checking for Kerberos support... no
checking whether to use system default cipher list instead of hardcoded value... no
checking for DSA_get_default_method in -lssl... no
checking for X509_free in -lcrypto... no
checking for RAND_egd... no
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>

報錯:缺乏openssl:安裝他,再繼續配置

checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/

報錯:缺乏libcurl:安裝。再繼續配置:

checking for T1lib support... no
checking whether to enable truetype string function in GD... no
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.

報錯:缺乏jpeblib,安裝,再繼續配置:

checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

報錯:缺乏png,安裝,繼續配置:

checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.

報錯:缺乏freetype,安裝,繼續配置:

checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

報錯:缺乏libmcrypt,安裝,繼續配置:

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: main/php_config.h is unchanged
config.status: executing default commands

五、配置成功,編譯和安裝:

[root@localhost php-5.6.32]# make && make install
ldl -lxml2 -lz -lm -ldl -lcrypt  -o sapi/cgi/php-cgi
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorytreeiterator.inc
invertedregexiterator.inc
directorygraphiterator.inc
pharcommand.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary:        /usr/local/php-fpm/bin/
Installing PHP CLI man page:      /usr/local/php-fpm/php/man/man1/
Installing PHP FPM binary:        /usr/local/php-fpm/sbin/
Installing PHP FPM config:        /usr/local/php-fpm/etc/
Installing PHP FPM man page:      /usr/local/php-fpm/php/man/man8/
Installing PHP FPM status page:   /usr/local/php-fpm/php/php/fpm/
Installing PHP CGI binary:        /usr/local/php-fpm/bin/
Installing PHP CGI man page:      /usr/local/php-fpm/php/man/man1/
Installing build environment:     /usr/local/php-fpm/lib/php/build/
Installing header files:           /usr/local/php-fpm/include/php/
Installing helper programs:       /usr/local/php-fpm/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php-fpm/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php-fpm/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php-fpm/etc/pear.conf
You may want to add: /usr/local/php-fpm/lib/php to your php.ini include_path
/usr/local/src/php-5.6.32/build/shtool install -c ext/phar/phar.phar /usr/local/php-fpm/bin
ln -s -f phar.phar /usr/local/php-fpm/bin/phar
Installing PDO headers:           /usr/local/php-fpm/include/php/ext/pdo/
[root@localhost php-5.6.32]# echo $?
0

六、檢查php-fpm核心文件及安裝目錄結構:

[root@localhost ~]# ls /usr/local/php-fpm/
bin  etc  include  lib  php  sbin  var 
[root@localhost ~]# ls /usr/local/php-fpm/sbin/
php-fpm       //php-fpm的核心二進制文件
[root@localhost ~]# ls /usr/local/php-fpm/var/
log  run     //log 存放日誌的目錄、run存放pid的目錄

七、從源碼包裏拷貝配置文件php.ini到php-fpm/etc/目錄下:編輯php-fpm.conf配置文件

[root@localhost ~]# cp /usr/local/src/php-5.6.32/php.ini-production /usr/local/php-fpm/etc/php.ini

[root@localhost ~]# vim /usr/local/php-fpm/etc/php-fpm.conf   //與php.ini不一樣,要區分開
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]   // 模塊名字 
listen = /tmp/php-fcgi.sock
#listen=127.0.0.1:9000   //也能夠監聽ip地址與默認9000端口
listen.mode = 666   //當上面監聽的不是ip是sock的時候才生效
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

#sock文件的權限是666
[root@localhost ~]# ls -l /tmp/php-fcgi.sock 
srw-rw-rw- 1 root root 0 6月   7 13:05 /tmp/php-fcgi.sock

八、檢查配置文件語法:

[root@localhost ~]# /usr/local/php-fpm/sbin/php-fpm -t
[07-Jun-2018 13:02:50] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

九、設置開機啓動:

[root@localhost ~]# cp /usr/local/src/php-5.6.32/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  //拷貝啓動腳本
[root@localhost ~]# chmod 755 /etc/init.d/php-fpm    //修改成755的權限

[root@localhost ~]# chkconfig --add php-fpm  //加入啓動列表
[root@localhost ~]# chkconfig php-fpm on   //設置開機啓動
[root@localhost ~]# service php-fpm start   //開啓php-fpm服務
Starting php-fpm  done
[root@localhost ~]# ps aux|grep php-fpm
root       1450  0.0  0.2 123652  4944 ?        Ss   13:05   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm    1451  0.0  0.2 123652  4712 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1452  0.0  0.2 123652  4712 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1453  0.0  0.2 123652  4712 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1454  0.0  0.2 123652  4712 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1455  0.0  0.2 123652  4716 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1456  0.0  0.2 123652  4716 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1457  0.0  0.2 123652  4716 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1458  0.0  0.2 123652  4716 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1459  0.0  0.2 123652  4716 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1460  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1461  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1462  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1463  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1464  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1465  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1466  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1467  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1468  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1469  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
php-fpm    1470  0.0  0.2 123652  4720 ?        S    13:05   0:00 php-fpm: pool www
root       1472  0.0  0.0 112720   972 pts/0    R+   13:05   0:00 grep --color=auto php-fpm

12.5 Nginx介紹

Nginx是俄國人開發的一個小巧而強大的web服務,能夠到官網下載: nginx.org 最新的版本是1.13,穩定版本是1.12 stable

nginx有不少的應用場景:web服務、反向代理、負載均衡等。

nginx的靜態文件處理性能比Apache強不少。由於淘寶網站用nginx+tomcat來搭建java環境

nginx有一個著名的分支:淘寶網基於nginx定製開發的Tengine,他的配置文件名和服務名基本與nginx一致,是在nginx的基礎上增長了一些定製化的模塊,在安全限速方面有比較突出的性能,另外還支持js、css的合併,由於淘寶網站是大型的購物平臺,不少商品展現的頁面,含有大量的靜態文件,支持這些文件的合併,可以大大減小資源的請求,提升服務器的處理效率。

nginx的核心組件+lua相關模塊還可以組成一個支持lua的高性能的web容器openresty。

相關文章
相關標籤/搜索