LNMP架構介紹

 

12.一、LNMP架構介紹php

  • 和LAMP不一樣的是,提供web服務的是Nginx
  • 而且php是做爲一個獨立的服務存在的,這個服務叫作php-fpm
  • Nginx直接處理靜態請求,動態請求會轉發給php-fpm

 

12.二、MySQL安裝css

  • cd /usr/local/src
  •  wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 
  •  tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
  •  mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
  •  cd /usr/local/mysql
  •  useradd mysql
  •  mkdir /data/
  •  ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  •  cp support-files/my-default.cnf  /etc/my.cnf 
  •  cp support-files/mysql.server /etc/init.d/mysqld
  •  vi /etc/init.d/mysqld
  • 定義basedir和datadir
  •  /etc/init.d/mysqld start

 

[root@zgxlinux-01 src]# rm -rf /usr/local/mysql/mysql

[root@zgxlinux-01 src]# rm -rf /etc/init.d/mysqld linux

[root@zgxlinux-01 src]# tar mysql-5.6.39-linux-glibc2.12-x86_64.tar.gznginx

[root@zgxlinux-01 src]# mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysqlgit

[root@zgxlinux-01 src]# ls /usr/local/mysql/
bin      docs     man         scripts    support-files
COPYING  include  mysql-test  share
data     lib      README      sql-bench
[root@zgxlinux-01 src]# rm -rf /data/mysql*
[root@zgxlinux-01 src]# ls /data/
mariadb  wwwroot
[root@zgxlinux-01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[root@zgxlinux-01 mysql]# echo $?
0web

[root@zgxlinux-01 mysql]# vim /etc/my.cnf

sql

[root@zgxlinux-01 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@zgxlinux-01 mysql]# vim /etc/init.d/mysql vim

[root@zgxlinux-01 mysql]# mv /etc/init.d/mysql /etc/init.d/mysqld
[root@zgxlinux-01 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@zgxlinux-01 ~]# ps aux |grep mysql
root      1713  0.0  0.1 113308  1616 pts/0    S    16:45   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/zgxlinux-01.pid
mysql     1852  1.0 44.8 1302720 451564 pts/0  Sl   16:45   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=zgxlinux-01.err --pid-file=/data/mysql/zgxlinux-01.pid --socket=/tmp/mysql.sock
root      1878  0.0  0.0 112720   984 pts/0    R+   16:46   0:00 grep --color=auto mysql
[root@zgxlinux-01 mysql]# chkconfig --add mysqld
[root@zgxlinux-01 mysql]# chkconfig mysqld on
[root@zgxlinux-01 mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@zgxlinux-01 mysql]# service mysqld start
Starting MySQL. SUCCESS! 
[root@zgxlinux-01 mysql]# ps aux |grep mysqld
root      1985  0.0  0.1  11816  1604 pts/0    S    16:48   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/zgxlinux-01.pid
mysql     2124  1.3 45.2 1302720 455144 pts/0  Sl   16:48   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=zgxlinux-01.err --pid-file=/data/mysql/zgxlinux-01.pid --socket=/tmp/mysql.sock
root      2148  0.0  0.0 112720   984 pts/0    R+   16:48   0:00 grep --color=auto mysqldapi

 

12.三、PHP安裝

  • 和LAMP安裝PHP方法有差異,須要開啓php-fpm服務
  •  cd /usr/local/src/
  •  wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
  •  tar zxf php-5.6.30.tar.gz
  •  useradd -s /sbin/nologin php-fpm
  •  cd 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
  • make && make install
  •  cp php.ini-production /usr/local/php-fpm/etc/php.ini
  •  vi /usr/local/php/etc/php-fpm.conf //寫入以下內容(參考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/php-fpm.conf)
  •  cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  •  chmod 755 /etc/init.d/php-fpm
  •  chkconfig --add php-fpm
  •  chkconfig php-fpm on
  •  service php-fpm start
  •  ps aux |grep php-fpm

 

#安裝過程

[root@zgxlinux-01 src]# cd php-5.6.32/
[root@zgxlinux-01 php-5.6.32]# make clean
[root@zgxlinux-01 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
[root@zgxlinux-01 php-5.6.32]# echo $?
1
[root@zgxlinux-01 php-5.6.32]# yum install -y libcurl-devel
[root@zgxlinux-01 php-5.6.32]# echo $?
0
[root@zgxlinux-01 php-5.6.32]# make && make install

[root@zgxlinux-01 php-5.6.32]#  echo $?
0
[root@zgxlinux-01 php-5.6.32]# ls /usr/local/php-fpm/
bin  etc  include  lib  php  sbin  var
[root@zgxlinux-01 php-5.6.32]# ls /usr/local/php/
bin  etc  include  lib  php
[root@zgxlinux-01 php-5.6.32]# ls /usr/local/php-fpm/sbin/
php-fpm
[root@zgxlinux-01 php-5.6.32]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
[root@zgxlinux-01 php-5.6.32]# cd /usr/local/php-fpm/etc/
[root@zgxlinux-01 etc]# ls
pear.conf  php-fpm.conf.default  php.ini

[root@zgxlinux-01 etc]# vim php-fpm.conf

[root@zgxlinux-01 etc]# cd /usr/local/src/php-5.6.32
[root@zgxlinux-01 php-5.6.32]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@zgxlinux-01 php-5.6.32]# chmod 755 /etc/init.d/php-fpm
[root@zgxlinux-01 php-5.6.32]# chkconfig --add php-fpm
[root@zgxlinux-01 php-5.6.32]# chkconfig php-fpm on
[root@zgxlinux-01 php-5.6.32]# service php-fpm start
Starting php-fpm [25-Nov-2018 18:35:02] ERROR: [pool www] cannot get uid for user 'php-fpm'
[25-Nov-2018 18:35:02] ERROR: FPM initialization failed
 failed
[root@zgxlinux-01 php-5.6.32]# useradd php-fpm
[root@zgxlinux-01 php-5.6.32]# service php-fpm start
Starting php-fpm  done
[root@zgxlinux-01 php-5.6.32]# ps aux |grep php-fpm
root     53532  0.1  0.4 123672  4936 ?        Ss   18:37   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm  53533  0.0  0.4 123672  4696 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53534  0.0  0.4 123672  4696 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53535  0.0  0.4 123672  4696 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53536  0.0  0.4 123672  4696 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53537  0.0  0.4 123672  4700 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53538  0.0  0.4 123672  4700 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53539  0.0  0.4 123672  4700 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53540  0.0  0.4 123672  4700 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53541  0.0  0.4 123672  4700 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53542  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53543  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53544  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53545  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53546  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53547  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53548  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53549  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53550  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53551  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
php-fpm  53552  0.0  0.4 123672  4704 ?        S    18:37   0:00 php-fpm: pool www
root     53554  0.0  0.0 112720   980 pts/0    R+   18:37   0:00 grep --color=auto php-fpm
 

 

12.五、Nginx介紹

  • Nginx官網 nginx.org,最新版1.13,最新穩定版1.12 
  •  Nginx應用場景:web服務、反向代理、負載均衡
  •  Nginx著名分支,淘寶基於Nginx開發的Tengine,使用上和Nginx一致,服務名,配置文件名都同樣,和Nginx的最大區別在於Tenging增長了一些定製化模塊,在安全限速方面表現突出,另外它支持對js,css合併
  •  Nginx核心+lua相關的組件和模塊組成了一個支持lua的高性能web容器openresty,參考http://jinnianshilongnian.iteye.com/blog/2280928
相關文章
相關標籤/搜索