构建LNMP网站平台
构建lnmp平台需要linux服务器,Mysql数据库,PHP解析环境,区别主要在nginx与PHP协作配置上
一:部署nginx服务
1)安装支持软件
Nginx配置运行需要pcre,zlib 等软件包支持,因此预先安装这些软件的开发包,以提供相应库和文件,确保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 访问情况统计
Location /status //访问位置为:/status
Stub_status on; //打开状态统计功能
Access_log off; //关闭此位置日志记录
四 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'
五 安装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
测试访问php情况