Nginx 运维架构之(Nginx+PHP)
2016-08-02 14:07
369 查看
1、首先我们来看下web服务器的排名情况
可以看到Nginx占有30.6%,Apache 52.0%,Nginx特点如下
1、配置简单,灵活,轻量。
2、高并发(静态小文件),静态几万的并发
3、占用资源少
4、功能种类比较多(web,cache,proxy),每一个功能都不是特别强
5、支持epoll模型,使得nginx可以支持高并发 Apache 选择 select模型
6、nginx可以搭配动态服务(FASTCGI接口)
6、利用nginx可以对ip限速,可以限制连接数
并发能力
nginx 1-3万 php 300-800 db 300-800.日pv2000万以下,并发1万以下都可以用nginx做反向代理
2、nginx的安装(centos6.7)
访问下nginx服务
一份简单的nginx配置
3、数据库MySQL的安装
4、php的安装
php的安装(5.3.27),需要先安装nginx和mysql
解决方法:
至此整个架构完成,下次我们再介绍nginx+tomcat nginx+keepalived
可以看到Nginx占有30.6%,Apache 52.0%,Nginx特点如下
1、配置简单,灵活,轻量。
2、高并发(静态小文件),静态几万的并发
3、占用资源少
4、功能种类比较多(web,cache,proxy),每一个功能都不是特别强
5、支持epoll模型,使得nginx可以支持高并发 Apache 选择 select模型
6、nginx可以搭配动态服务(FASTCGI接口)
6、利用nginx可以对ip限速,可以限制连接数
并发能力
nginx 1-3万 php 300-800 db 300-800.日pv2000万以下,并发1万以下都可以用nginx做反向代理
2、nginx的安装(centos6.7)
[root@centos02 tools]# yum install pcre pcre-devel openssl-devel -y [root@centos02 tools]# wget http://nginx.org/download/nginx-1.6.3.tar.gz [root@centos02 tools]# tar xf nginx-1.6.3.tar.gz [root@centos02 tools]# cd nginx-1.6.3 [root@centos02 nginx-1.6.3]# useradd -s /sbin/nologin -M nginx [root@centos02 nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module [root@centos02 nginx-1.6.3]# make && make install [root@centos02 nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx [root@centos02 nginx-1.6.3]# /application/nginx/sbin/nginx -t 检查语法 [root@centos02 nginx-1.6.3]# /application/nginx/sbin/nginx 启动nginx 简单截图下安装过程
访问下nginx服务
一份简单的nginx配置
[root@centos02 conf]# cat nginx.conf worker_processes 2; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.martin.com martin.com; location / { root html/www; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } access_log logs/access_www.log main; } server { listen 80; server_name bbs.martin.com; location / { root html/bbs; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } access_log logs/access_bbs.log main; } ###status server{ listen 80; server_name status.martin.org; location / { stub_status on; access_log off; } } }
3、数据库MySQL的安装
[root@centos02 tools]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz 这是个二进制包,无需编译 [root@centos02 tools]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz [root@centos02 tools]# useradd -s /sbin/nologin -M mysql [root@centos02 tools]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49 [root@centos02 tools]# ln -s /application/mysql-5.5.49/ /application/mysql [root@centos02 tools]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql [root@centos02 tools]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/support-files/mysql.server [root@centos02 tools]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld [root@centos02 tools]# chmod +x /etc/init.d/mysqld [root@centos02 mysql]# chown -R mysql.mysql /application/mysql/ [root@centos02 mysql]# cp support-files/my-small.cnf /etc/my.cnf过程中的相关截图
4、php的安装
php的安装(5.3.27),需要先安装nginx和mysql
[root@centos02 libiconv-1.14]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo [root@centos02 tools]# yum install zlib-devel libxml2-devel libjpeg-devel libiconv-devel -y [root@centos02 tools]# yum install freetype-devel libpng-devel gd-devel curl-devel libxslt-devel -y [root@centos02 libiconv-1.14]# yum -y install libmcrypt-devel mhash mhash-devel mcrypt libxslt-devel [root@centos02 tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz [root@centos02 tools]# tar xf libiconv-1.14.tar.gz [root@centos02 tools]# cd libiconv-1.14 [root@centos02 libiconv-1.14]# ./configure --prefix=/usr/local/libiconv [root@centos02 libiconv-1.14]# make && make install [root@centos02 tools]# tar xf php-5.3.27.tar.gz [root@centos02 tools]# cd php-5.3.27 [root@centos02 php-5.3.27]# ./configure \ > --prefix=/application/php5.3.27 \ > --with-mysql=/application/mysql \ > --with-iconv-dir=/usr/local/libiconv \ > --with-freetype-dir \ > --with-jpeg-dir \ > --with-png-dir \ > --with-zlib \ > --with-libxml-dir=/usr \ > --enable-xml \ > --disable-rpath \ > --enable-safe-mode \ > --enable-bcmath \ > --enable-shmop \ > --enable-sysvsem \ > --enable-inline-optimization \ > --with-curl \ > --with-curlwrappers \ > --enable-mbregex \ > --enable-fpm \ > --enable-mbstring \ > --with-mcrypt \ > --with-gd \ > --enable-gd-native-ttf \ > --with-openssl \ > --with-mhash \ > --enable-pcntl \ > --enable-sockets \ > --with-xmlrpc \ > --enable-zip \ > --enable-soap \ > --enable-short-tags \ > --enable-zend-multibyte \ > --enable-static \ > --with-xsl \ > --with-fpm-user=nginx \ > --with-fpm-group=nginx \ > --enable-ftp [root@centos02 php-5.3.27]# make报错如下
解决方法:
[root@centos02 php-5.3.27]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ [root@centos02 php-5.3.27]# touch ext/phar/phar.phar [root@centos02 php-5.3.27]# make && make install
[root@centos02 php-5.3.27]# ln -s /application/php5.3.27/ /application/php [root@centos02 php-5.3.27]# cp php.ini-production /application/php/lib/php.ini [root@centos02 php-5.3.27]# cd /application/php/etc/ [root@centos02 etc]# cp php-fpm.conf.default php-fpm.conf [root@centos02 etc]# cat php-fpm.conf [global] [www] user = nginx group = nginx listen = 127.0.0.1:9000 pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 [root@centos02 etc]# /application/php/sbin/php-fpm[root@centos02 etc]# netstat -lantup|grep php-fpm
/application/nginx/html/www [root@centos02 www]# cat index.php <?php phpinfo() ?>打开浏览器访问测试
至此整个架构完成,下次我们再介绍nginx+tomcat nginx+keepalived
相关文章推荐
- 让 Nginx 支持 WAF 防护功能web防火墙 - 沧海一粟 - Web系统架构与服务器运维,php开发
- 网站运维架构设计及安装过程(linux+nginx+php-fpm+pgsql+memcached+varnish+mysql)
- 门户网站架构Nginx+Apache+MySQL+PHP+Memcached+Squid
- nginx漏洞上传图片可入侵100万服务器 nginx+php的注意了
- centos+nginx+php+mysql(经典架构流程案例)
- 通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题
- [Linux] Ubuntu_9.04_server安装nginx+php(fastcgi)+nginx虚拟主机配置格式
- 搭建高性能Web服务器Nginx,10倍于Apache---Nginx+Php(FastCgi模式)
- 详解Nginx+php-5.4+Mysql-5.5+Memcached+redis的架构部署
- 门户网站架构Nginx+Apache+MySQL+PHP+Memcached+Squid
- 使用Nginx从零开始搭建基于LNMP架构的电影系统之一_Linux运维
- 详解Nginx+php-5.4+Mysql-5.5+Memcached+redis的架构部署 推荐
- nginx+mysql+php+cacti+rrdtool全方位架构急速版
- Nginx+php(FastCGI)+Memcached+Mysql+APC Nginx高性能web服务器安装 APC模块安装 l
- nginx学习总结四(nginx+php-cgi)
- 门户网站架构Nginx+Apache+MySQL+PHP+Memcached+Squid
- nginx学习总结四(nginx+php-cgi)
- LNMP一键安装Linux系统下Nginx+MySQL+PHP这种网站服务器架构
- 通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题
- 详解Nginx+php-5.4+Mysql-5.5+Memcached+redis的架构部署