Forty-six, LNMP architecture introduction, MySQL installation, PHP installation, Nginx introduction
1. Introduction to LNMP Architecture
Different from LAMP is N:Nginx.
LNMP=Linux+Nginx+MySQL+PHP
Unlike LAMP, Nginx provides web services
And PHP exists as an independent service. This service is called php-fpm, which is PHP to put it bluntly.
Nginx processes static requests directly, and dynamic requests are forwarded to php-fpm
Nginx is much faster than Apache in processing static files, and its performance is much better. The number of concurrent users can reach tens of thousands, but Apache cannot.
2. MySQL installation
# cd /usr/local/src
First check whether the MySQL service is started: ps aux |grep mysql
Then delete the previous mysql.
# ps aux |grep mysql
root 17171 0.0 0.0 112676 984 pts/0 S+ 18:31 0:00 grep --color=auto mysql
# rm -rf /usr/local/mysql/
# rm -rf /etc/init.d/mysqld
/etc/my.cnf is temporarily reserved.
installation steps:
# cd /usr/local/src
# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
When doing this step of moving, there must be no mysql directory in the /usr/local/ directory, otherwise the file will be moved to the mysql directory instead of moving the file and renaming it to mysql.
# ls /usr/local/mysql/ //After moving, check whether the mysql directory is like this.
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
# cd /usr/local/mysql/
# useradd mysql
# mkdir /data/
# rm -rf /data/mysql/*
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
# echo $?
0
# cp support-files/my-default.cnf /etc/my.cnf Because /etc/ comes with my.cnf, I will copy it here.
Edit this file again: # vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock defines these two parameters
# cp support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql define these two parameters
# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/MRX.err'.
SUCCESS!
# ps aux |grep mysql
root 17740 0.0 0.0 113264 1604 pts/0 S 21:32 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/MRX.pid
mysql 17877 2.1 24.0 1300776 449540 pts/0 Sl 21:32 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/MRX.err --pid-file=/data/mysql/MRX.pid --socket=/tmp/mysql.sock
root 17901 0.0 0.0 112676 984 pts/0 R+ 21:33 0:00 grep --color=auto mysql
# chkconfig --add mysqld //放到服务列表,就能开机启动
# chkconfig mysqld on
# service mysqld stop //停止这个服务
Shutting down MySQL.. SUCCESS!
三、PHP安装
和LAMP安装PHP方法有差别,需要开启php-fpm服务
# cd /usr/local/src/
# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
# tar zxvf php-5.6.30.tar.gz
# cd php-5.6.30/
# make clean //会把之前编译过的文件全部删掉
# ./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-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --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-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl
报错了,少了个curl:
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
# yum install -y libcurl-devel
# ./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-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --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-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl
# make && make install
# ls /usr/local/php-fpm/ 和PHP相比多了sbin和var
bin etc include lib php sbin var
# ls /usr/local/php
bin etc include lib php
# ls /usr/local/php-fpm/sbin/
php-fpm //启动php-fpm的文件
# ls /usr/local/php-fpm/var
log run //log:存放日志,run,存放pid。
# /usr/local/php-fpm/sbin/php-fpm -m 查看模块
# /usr/local/php-fpm/sbin/php-fpm -i 查看PHP的信息,编译参数,configuration file的路径(配置文件)
# /usr/local/php-fpm/sbin/php-fpm -t
-t:php-fpm -t测试语法是否正确。
# cp php.ini-production /usr/local/php-fpm/php.ini
[root@MRX php-5.6.30]# cd /usr/local/php-fpm/etc/
[root@MRX etc]# vim php-fpm.conf
[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 //监听地址,可以监听socket,也可以监听IP
#listen = 127.0.0.1:9000 //一般都是监听这个IP,因为php-fpm是针对内部使用的,port默认是9000,可以改其他的。
listen.mode = 666 //当监听的是socket时,这句才会生效。用来定义socket文件的权限。
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
# cd /usr/local/src/php-5.6.30/
[root@MRX php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod 755 /etc/init.d/php-fpm
[root@MRX php-5.6.30]# chkconfig --add php-fpm
[root@MRX php-5.6.30]# chkconfig php-fpm on
# /usr/local/php-fpm/sbin/php-fpm -t
[19-Apr-2018 23:16:19] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful //这是没问题的
# service php-fpm start
Starting php-fpm [19-Apr-2018 23:15:30] ERROR: [pool www] cannot get uid for user 'php-fpm' //php-fpm这个用户不存在。
[19-Apr-2018 23:15:30] ERROR: FPM initialization failed
failed
# useradd php-fpm 创建这个用户
# service php-fpm start //再执行启动,就正常了
Starting php-fpm done
# ps aux |grep php-fpm
root 3110 0.0 0.2 123656 4940 ? Ss 23:21 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 3111 0.0 0.2 123656 4680 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3112 0.0 0.2 123656 4680 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3113 0.0 0.2 123656 4680 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3114 0.0 0.2 123656 4680 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3115 0.0 0.2 123656 4684 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3116 0.0 0.2 123656 4684 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3117 0.0 0.2 123656 4684 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3118 0.0 0.2 123656 4684 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3119 0.0 0.2 123656 4684 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3120 0.0 0.2 123656 4684 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3121 0.0 0.2 123656 4684 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3122 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3123 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3124 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3125 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3126 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3127 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3128 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3129 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
php-fpm 3130 0.0 0.2 123656 4688 ? S 23:21 0:00 php-fpm: pool www
root 3132 0.0 0.0 112680 984 pts/0 S+ 23:21 0:00 grep --color=auto php-fpm
php-fpm: User defined.
www: module name.
4. Introduction to Nginx
Nginx official website: Nginx.org, the latest stable version 1.14 (with stable).
Nginx application scenarios: web services, reverse proxy, load balancing.
The famous branch of Nginx: Taobao (Tengine developed based on Nginx), the service name and configuration file name are the same, the biggest difference from Nginx is that Tengine has added some customized modules, which are outstanding in terms of security speed limit, in addition, it supports js, css merge.
Nginx core + lua-related components and modules form a high-performance web container that supports lua, openresty, refer to http://jinnianshilongnian.iteye.com/blog/2280928