keepalived + nginx   :实现高可用

nginx:

web服务器

反向代理,也支持缓存(缓存在磁盘上)

支持FastCGI

tengine:淘宝官方在nginx原有的代码的基础上对nginx做了诸多改进,直接将很多第三方模块整合进了nginx,并作出了大量改进。

优点

Nginx保持10 000个没有活动的连接,而这些连接只占用2.5MB内存

主进程主要完成如下工作:

1. 读取并验正配置信息;

2. 创建、绑定及关闭套接字;

3. 启动、终止及维护worker进程的个数;

4. 无须中止服务而重新配置工作特性;

5. 控制非中断式程序升级,启用新的二进制程序并在需要时回滚至老版本;

6. 重新打开日志文件,实现日志滚动;

7. 编译嵌入式perl脚本;

worker进程主要完成的任务包括:

1. 接收、传入并处理来自客户端的连接;

2. 提供反向代理及过滤功能;

3. nginx任何能完成的其它任务;

cache loader进程主要完成的任务包括:

1. 检查缓存存储中的缓存对象;

2. 使用缓存元数据建立内存数据库;

cache manager进程的主要任务:

1. 缓存的失效及过期检验;

编译安装nginx

1、编译需要的环境

yum -y install  gcc  gcc-c++  autoconf  automake  zlib  zlib-devel  openssl  openssl-devel  pcre-devel  gd-devel

2、创建程序用户  groupadd  -r -g 311  nginx      &&  useradd  -r -g 311 -r -u 306 nginx

2.1、下载nginx包,与解压省略,

3、编译需要的选项

./configure \

--prefix=/usr/local/nginx\

--sbin-path=/usr/local/nginx/sbin/nginx \

--conf-path=/usr/local/nginx/etc/nginx.conf \

--error-log-path=/usr/local/nginx/log/error.log \

--http-log-path=/usr/local/nginx/log/access.log \

--pid-path=/var/run/nginx/nginx.pid  \

--lock-path=/var/lock/nginx.lock \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--http-client-body-temp-path=/usr/local/nginx/client/ \

--http-proxy-temp-path=/usr/local/nginx/proxy/ \

--http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \

--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \

--http-scgi-temp-path=/usr/local/nginx/scgi \

--with-file-aio\

--with-http_image_filter_module\

--add-module=/root/fastdfs-nginx-module/src\

--with-pcre=/usr/pcre-版本号\    指向的是源目录,不是安装目录

4、需要一个启动脚本 :vim  /etc/rc.d/init.d/nginx    脚本在下面↓

然后添加执行权限  chmod  x   /etc/rc.d/init.d/nginx

开机启动   chkconfig --add nginx     chkconfig --level 35  nginx on

5、启动服务  service  nginx   start

定义LNMP

nginx想要整合php不支持模块化方式安装,,必须把php编译成FastCGI模式!php-fpm

编译php最后一项

编辑php-fpm的配置文件:

# vim /usr/local/php/etc/php-fpm.conf

配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):

pm.max_children = 150   最大子进程个数

pm.start_servers = 8     刚开始启动子进程个数

pm.min_spare_servers = 5  最小空闲数

pm.max_spare_servers = 10  最大空闲数

pid = /usr/local/php/var/run/php-fpm.pid

接下来就可以启动php-fpm了:

# service php-fpm start

使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):

# ps aux | grep php-fpm

整合php与nginx

1、编辑/etc/nginx/nginx.conf,启用如下选项:

location ~ \.php$ {

root           html;   这个定义的是你php网页文件的位置

fastcgi_pass   127.0.0.1:9000;  反向代理方式

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /script$fastcgi_script_name;

include        fastcgi_params;

}

2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;

并在所支持的主页面格式中添加php格式的主页,类似如下:

location / {

root   html;

index  index.php index.html index.htm;

}

而后重新载入nginx的配置文件:

# service nginx reload

3、在/usr/html新建index.php的测试页面,测试php是否能正常工作:

# cat > /usr/html/index.php << EOF

<?php

phpinfo();

?>

接着就可以通过浏览器访问此测试页面了。

nginx主配置文件

server{ }:虚拟主机,每一个server定义一个虚拟主机。

location{ }:基于URI路径来定义访问属性的。

location / {      :定义一个URL路径

root   html;      :定义了URL路径下的所有网页文件在本地系统的那个地方

index  index.html index.htm;    :返回默认主页面是谁的

}

error_page   500 502 503 504  /50x.html;   若果你返回的错误代码是50....这几个,就读取/50x这个网页文件。

location = /50x.html {      :如果你访问的就是这个页面

root   html;       :要求这个页面位于。。。路径下

}

location URI :对当前路径及子路径下的所有对象都生效,倍。每一个核心可以绑定一个线程!

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;  定义PID文件,这里禁用是我们自定义的选项生效了

events {

worker_connections  1024; 事件驱动中,每一个work他所能支持的连接数,一个work支持1021个连接数!

}

http {

include       mime.types; 包含的文件

default_type  application/octet-stream; 默认支持的类型

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' 日志格式

#                  '$status $body_bytes_sent "$http_referer" '

#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main; 访问日志

sendfile        on; 提升文件下载性能

#tcp_nopush     on; 不做推送。先发送一个包,其余包缓存,等第一个包确认之后,在发送其余的包

#keepalive_timeout  0; 使用长连接

keepalive_timeout  65; 指定超时时间

#gzip  on;先压缩后发送,带宽小,访问量大适用

server {

Listen       80;

server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location  /  {    URI路径

root   html;   相对于URI,你的网页文件存放路径

index  index.html index.htm;    主页面支持的文件类型

}

#error_page  404              /404.html; }  返回的错误代码是404,那就去读取下面50X这个文件

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#    proxy_pass   http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

#    root           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

#    listen       8000;

#    listen       somename:8080;

#    server_name  somename  alias  another.alias;

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

# HTTPS server

#

#server {

#    listen       443 ssl;

#    server_name  localhost;

#    ssl_certificate      cert.pem;

#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;

#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;

#    ssl_prefer_server_ciphers  on;

dex  index.html index.htm;

#    }

#}

CentOS6.7安装部署Nginx(详解主配置文件)的更多相关文章

  1. Centos6.9安装部署nginx服务器

    (一)依赖包安装 首先,gcc,pcre,zlib,openssl安装一边(可以用非-devel,但是嫌麻烦....用非-devel的看这个链接) yum  -y install gcc ------ ...

  2. (转)windows 下安装配置 Nginx 详解

    windows 下安装配置 Nginx 详解 本文转自https://blog.csdn.net/kingscoming/article/details/79042874 nginx功能之一可以启动一 ...

  3. centos7 下 安装部署nginx

    centos7 下 安装部署nginx 1.nginx安装依赖于三个包,注意安装顺序 a.SSL功能需要openssl库,直接通过yum安装: #yum install openssl b.gzip模 ...

  4. 基于centos6.5安装部署mongdb3.6

    注意:不同的版本的centos,mongdb安装方式不同,请注意版本号!! 基于centos6.5安装部署mongdb3.6 方式有多种,本文介绍使用wget命令来下载获取mongdb,具体命令如下 ...

  5. Docker部署Nginx并修改配置文件

    Docker部署Nginx并修改配置文件 一.拉取nginx镜像 docker pull nginx 二.在宿主机中创建挂载目录 mkdir -p /data/nginx/{conf,conf.d,h ...

  6. 史上最全CentOS6离线安装部署Cloudera Manager5.9.3

    史上最全CentOS6离线安装部署Cloudera Manager5.9.3

  7. docker+nginx 安装部署修改资源目录配置文件和容器端口信息

    查看docker镜像 可以先查看docker下是否存在nginx镜像,使用如下这些命令查看: docker images: 列出所有镜像. docker images nginx: 列出所有nginx ...

  8. linux安装部署Nginx

    两个参考地址: NGINX的百度百科:https://baike.baidu.com/item/nginx/3817705?fr=aladdin NGINX的中文网站:http://www.nginx ...

  9. centos6.5安装部署zabbix监控服务端和客户端

    部署zabbix服务端需要LNMP环境(nginx,mysql,php),其它数据库也可以,我这里使用mysql,关于LNMP环境部署,可以参考我的另一遍文章:http://www.cnblogs.c ...

随机推荐

  1. ZROI 暑期高端峰会 A班 Day5 计算几何

    内积(点积) 很普及组,不讲了. \[(a,b)^2\le(a,a)(b,b)\] 外积(叉积) 也很普及组,不讲了. 旋转 对于矩阵 \(\begin{bmatrix}\cos\theta\\\si ...

  2. String.format()的详细用法

    问题 在开发的时候一段字符串的中间某一部分是需要可变的 比如一个Textview需要显示”XXX用户来自 上海 年龄 21 性别 男” 其中的 XXX 是用户名 每个用户也是不一样的 地区 上海 为可 ...

  3. Java 签名验签工具类

    public class SignatureUtil { private static final String CHARSET = "UTF-8"; private static ...

  4. scala 正则

    package com.program import scala.util.matching.Regex object RegexTest { def main(args: Array[String] ...

  5. 【RS】:论文《Neural Collaborative Filtering》的思路及模型框架

    [论文的思路] NCF 框架如上: 1.输入层:首先将输入的user.item表示为二值化的稀疏向量(用one-hot encoding) 2.嵌入层(embedding):将稀疏表示映射为稠密向量( ...

  6. BitSet源码

    public class BitSet1 implements Cloneable, java.io.Serializable { // >>>左边补0, << 右边补0 ...

  7. django 中进程监控工具flower的使用

    工程结构:请参考https://www.cnblogs.com/apple2016/p/11425307.html flower官方文档:https://flower.readthedocs.io/e ...

  8. [转帖]Java Netty简介

    Java Netty简介 https://www.cnblogs.com/ghj1976/p/3779820.html Posted on 2014-06-10 13:41 蝈蝈俊 阅读(2992) ...

  9. 建造(Builder)模式

    建造模式可以将一个产品的内部表象与产品的生成过程分割开来,从而可以使一个建造过程生成具有不同的内部表象的产品对象. 摘自EffectiveJava:当构造方法参数过多时使用建造者模式. 产品的内部表象 ...

  10. SPA单页面应用和MPA多页面应用(转)

    原文:https://www.jianshu.com/p/a02eb15d2d70 单页面应用 第一次进入页面时会请求一个html文件,刷新清除一下,切换到其他组件,此时路径也相应变化,但是并没有新的 ...