LNMP環境部署

構建LNMP網站平臺

構建lnmp平臺需要linux服務器,Mysql數據庫,PHP解析環境,區別主要在nginxPHP協作配置上

一:部署nginx服務

1)安裝支持軟件

Nginx配置運行需要pcrezlib 等軟件包支持,因此預先安裝這些軟件的開發包,以提供相應庫和文件,確保Nginx順利完成

[root@localhost /]# yum -y install pcre-devel zlib-devel

1)創建運行用戶組

[root@localhost /]# useradd -M -s /sbin/nologin nginx

1)編譯安裝Nginx

安裝目錄爲/usr/local/nginx 運行用戶和組均設置爲Nginx啓用http_stub_status_module模塊支持狀態統計,便於服務器連接情況。

[root@localhost src]# tar zxf nginx-1.6.2.tar.gz 
[root@localhost src]# cd nginx-1.6.2/
[root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.6.2]# make && make install

爲了使Nginx服務器運行方便,可以爲主程序nginx創建連接文件

[root@localhost nginx-1.6.2]# ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin/
[root@localhost nginx-1.6.2]# ls -l /usr/local/sbin/nginx 
lrwxrwxrwx. 1 root root 27 Mar 18 15:03 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx

二:Nginx運行控制

1)檢查配置文件

apache的主程序類似,Nginx主程序提供了 -t 選項用來對配置文件進行檢查

[root@localhost nginx-1.6.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

1)啓動 停止 nginx

直接運行Nginx即可啓動Nginx服務器,使用默認配置文件,若要改其他配置文件,需要加-C配置文件路徑

[root@localhost nginx-1.6.2]# nginx
[root@localhost nginx-1.6.2]# netstat -anpt | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      8002/nginx: master

三:訪問狀態統

Nginx 訪問情況統計

截圖00.png

Location /status  //訪問位置爲:/status

  Stub_status  on;  //打開狀態統計功能

 Access_log   off;    //關閉此位置日誌記錄

截圖01.png

Mysql安裝步驟

[root@centos1 src]# yum -y install ncurses-devel
[root@centos1 cmake-2.8.12]# ./configure && make && make install 
[root@centos1 mysql-5.5.38]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYCONFDIR=/etc/
[root@centos1 mysql-5.5.38]# make && make install 
[root@centos1 mysql-5.5.38]# cp support-files/my-medium.cnf /etc/my.cnf 
[root@centos1 mysql-5.5.38]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@centos1 mysql-5.5.38]# chmod +x /etc/rc.d/init.d/mysqld 
[root@centos1 mysql-5.5.38]# chkconfig --add mysqld
[root@centos1 mysql-5.5.38]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@centos1 mysql-5.5.38]# . /etc/profile

初始化數據庫

[root@centos1 mysql-5.5.38]# groupadd mysql
[root@centos1 mysql-5.5.38]# useradd -M -s /sbin/nologin mysql -g mysql
[root@centos1 mysql-5.5.38]# chown -R mysql:mysql /usr/local/mysql
[root@centos1 mysql-5.5.38]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
[root@centos1 mysql-5.5.38]# service mysqld start
[root@centos1 mysql-5.5.38]# mysqladmin -u root password '123456'

截圖02.png

安裝php解析環境

[root@localhost conf]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
[root@localhost src]# tar zxf php-5.3.28.tar.gz 
[root@localhost src]# cd php-5.3.28/
[root@localhost php-5.3.28]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib
[root@localhost php-5.3.28]# make && make install

安裝後調整

[root@localhost php-5.3.28]# cp php.ini-development /usr/local/php5/php.ini
[root@localhost php-5.3.28]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@localhost php-5.3.28]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/

配置Nginx支持php環境

[root@localhost php-5.3.28]# cd /usr/local/php5/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# useradd -M -s /sbin/nologin php
[root@localhost etc]# vim php-fpm.conf

pid = run/php-fpm.pid                     確認pid文件位置

user = php 運行用戶

group = php 運行組

pm.start_servers = 20                       啓動開啓進程數

pm.min_spare_servers = 5                    最少空閒進程數

pm.max_spare_servers = 35

pm.max_children = 50

[root@localhost etc]# /usr/local/sbin/php-fpm 
[root@localhost etc]# netstat -anpt | grep php-fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      12575/php-fpm: mast

支持nginx解析php

截圖03.png

測試訪問php情況

截圖04.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章