12.1 LNMP架构介绍
和LAMP不同的是,提供web服务的是Nginx
并且php是作为一个独立服务存在的,这个服务叫做php-fpm
Nginx直接处理静态请求,动态请求会转发给php-fpm
用户并发支持很大,可以上好几万,Apache做不到
12.2 MySQL安装
[[email protected] ~]# cd /usr/local/src/ [[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz (过程省略) [[email protected] src]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz (过程省略) [[email protected] src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql [[email protected] src]# cd ../mysql/ [[email protected] mysql]# ls bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files [[email protected] 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-Data-Dumper.x86_64包 [[email protected] mysql]# useradd mysql [[email protected] mysql]# mkdir /data [[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql (过程省略) [[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf [[email protected] mysql]# vim /etc/my.cnf
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. SUCCESS! [[email protected] mysql]# ps aux |grep mysql root 1214 0.1 0.1 113264 1600 pts/0 S 21:59 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid mysql 1351 5.7 44.9 1300784 449548 pts/0 Sl 21:59 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 --socket=/tmp/mysql.sock root 1375 0.0 0.0 112676 984 pts/0 R+ 21:59 0:00 grep --color=auto mysql [[email protected] 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 803/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 904/master tcp6 0 0 :::22 :::* LISTEN 803/sshd tcp6 0 0 ::1:25 :::* LISTEN 904/master tcp6 0 0 :::3306 :::* LISTEN 1351/mysqld [[email protected] mysql]# chkconfig --add mysqld [[email protected] mysql]# chkconfig --list 注:该输出结果只显示 SysV 服务,并不包含 原生 systemd 服务。SysV 配置数据 可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。 查看在具体 target 启用的服务请执行 'systemctl list-dependencies [target]'。 mysqld 0:关1:关2:开3:开4:开5:开6:关 netconsole 0:关1:关2:关3:关4:关5:关6:关 network 0:关1:关2:开3:开4:开5:开6:关 [[email protected] mysql]# chkconfig mysqld on ##加入开机启动 [[email protected] mysql]# service mysqld stop ##现在可以用服务命令 Shutting down MySQL.. SUCCESS! [[email protected] mysql]# service mysqld start Starting MySQL. SUCCESS!
12.3/12.4 PHP安装
·LNMP下的PHP安装和LAMP下PHP安装有差别,需要开启php-fpm服务
·如果之前编译过php,那么进到源码包中,用make clean清除之前make过的文件
[[email protected] src]# cd php-5.6.30/ [[email protected] php-5.6.30]# make clean
·如果没有编译过的php,甚至么有下载php源码包,那么从下载开始做
[[email protected] src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2 (过程省略) [[email protected] src]# tar jxvf php-5.6.30 (过程省略) [[email protected] php-5.6.30]# useradd -s /sbin/nologin php-fpm ##也可以直接useradd php-fpm [[email protected] php-5.6.30]# ./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 (过程省略) [[email protected] php-5.6.30]# make && make install (过程省略) [[email protected] php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -m ##查看模块 (此处省略) [[email protected] php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -i ##查看信息 (此处省略) (php-fpm -m 和 php-fpm -i 配合php -m 和 php -i 使用) [[email protected] php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t ##测试语法 [12-Mar-2018 22:37:17] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2) [12-Mar-2018 22:37:17] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf' [12-Mar-2018 22:37:17] ERROR: FPM initialization failed [[email protected] php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini [[email protected] php-5.6.30]# cd /usr/local/php-fpm/etc/ [[email protected] etc]# vim php-fpm.conf
(listen也可以为127.0.0.1:9000,监听内部网络
listen.mode = 666 定义/tmp/php-fcgi.sock的权限为666)
[[email protected] etc]# cd .. [[email protected] php-fpm]# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [[email protected] php-fpm]# cd /etc/init.d/ [[email protected] init.d]# chmod 755 php-fpm ##更改php-fpm权限为755 [[email protected] init.d]# chkconfig --add php-fpm [[email protected] init.d]# chkconfig php-fpm on [[email protected] init.d]# chkconfig 注:该输出结果只显示 SysV 服务,并不包含 原生 systemd 服务。SysV 配置数据 可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。 查看在具体 target 启用的服务请执行 'systemctl list-dependencies [target]'。 mysqld 0:关1:关2:开3:开4:开5:开6:关 netconsole 0:关1:关2:关3:关4:关5:关6:关 network 0:关1:关2:开3:开4:开5:开6:关 php-fpm 0:关1:关2:开3:开4:开5:开6:关 [[email protected] init.d]# service php-fpm start Starting php-fpm done [[email protected] init.d]# ps aux |grep php-fpm root 123135 0.0 0.4 123612 4952 ? Ss 22:59 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 123136 0.0 0.4 123612 4708 ? S 22:59 0:00 php-fpm: pool www php-fpm 123137 0.0 0.4 123612 4708 ? S 22:59 0:00 php-fpm: pool www php-fpm 123138 0.0 0.4 123612 4708 ? S 22:59 0:00 php-fpm: pool www php-fpm 123139 0.0 0.4 123612 4708 ? S 22:59 0:00 php-fpm: pool www php-fpm 123140 0.0 0.4 123612 4712 ? S 22:59 0:00 php-fpm: pool www php-fpm 123141 0.0 0.4 123612 4712 ? S 22:59 0:00 php-fpm: pool www php-fpm 123142 0.0 0.4 123612 4712 ? S 22:59 0:00 php-fpm: pool www php-fpm 123143 0.0 0.4 123612 4712 ? S 22:59 0:00 php-fpm: pool www php-fpm 123144 0.0 0.4 123612 4712 ? S 22:59 0:00 php-fpm: pool www php-fpm 123145 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123146 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123147 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123148 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123149 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123150 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123151 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123152 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123153 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123154 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www php-fpm 123155 0.0 0.4 123612 4716 ? S 22:59 0:00 php-fpm: pool www root 123162 0.0 0.0 112676 976 pts/0 R+ 23:00 0:00 grep --color=auto php-fpm
(右侧的www就是php.ini配置文件中的www,而左侧php-fpm就是配置文件中定义的用户)
[[email protected] init.d]# ll /tmp/php-fcgi.sock srw-rw-rw- 1 root root 0 3月 12 23:04 /tmp/php-fcgi.sock
(而sock文件权限也是配置文件中定义的666)
·安装问题汇总:
1,configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
安装libcrul-devel
yum install -y libcurl-devel
12.5 Nginx介绍
·Nginx官网 nginx.org
·Nginx应用场景:web服务、反向代理、负载均衡
·Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,
和Nginx的最大区别在于Tenging增加了一些定制化模块,在安全限速方面表现突出,另外它支持对js,css合并
·Nginx核心+lua相关的组件和模块组成了一个支持lua的高性能web容器openresty
参考http://jinnianshilongnian.iteye.com/blog/2280928
原文地址:http://blog.51cto.com/11530642/2085834