fastdfs集群搭建3

.在跟踪器节点上安装nginx

1. tracker 上安装的 nginx 主要为了提供 http 访问的反向代理、负载均衡以及缓存服务 

2.安装编译 nginx 所需的依赖包

yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl -devel

3.上传 ngx_cache_purge-2.3.tar.gz /usr/local/src,解压 

4.上传当前的稳定版本nginx/usr/local/src 目录 

5.编译安装 nginx(添加 ngx_cache_purge 模块

解压并进入目录

./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/ngx_cache_purge-2.3 

make && make install 

6.配置 nginx,设置负载均衡以及缓存 

user  root;

worker_processes  1; 

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

    use epoll;

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_names_hash_bucket_size 128;
  •     client_header_buffer_size 32k;
  •     large_client_header_buffers 4 32k;
  •     client_max_body_size 300m;

  • proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k; #设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限 proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:200m max_size=1g inactive=30d; 

proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp;

#设置 group1 的服务器

upstream fdfs_group1 {

     server 192.168.1.11:8888 weight=1 max_fails=2 fail_timeout=30s;

     server 192.168.1.12:8888 weight=1 max_fails=2 fail_timeout=30s;

}

#设置 group2 的服务器

upstream fdfs_group2 {

     server 192.168.1.21:8888 weight=1 max_fails=2 fail_timeout=30s;

     server 192.168.1.22:8888 weight=1 max_fails=2 fail_timeout=30s;

server {

    listen       8000;

    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

#设置 group 的负载均衡参数

    location /group1/M00 {

        proxy_next_upstream http_502 http_504 error timeout invalid_header;

        proxy_cache http-cache;

        proxy_cache_valid  200 304 12h;

        proxy_cache_key $uri$is_args$args;

        proxy_pass http://fdfs_group1;

        expires 30d;

    }

    location /group2/M00 {

proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;

        proxy_pass http://fdfs_group2;

        expires 30d;

    }

#设置清除缓存的访问权限

    location ~/purge(/.*) {

        allow 127.0.0.1;

        allow 192.168.1.0/24;

        deny all;

        proxy_cache_purge http-cache $1$is_args$args;

#error_page  404              /404.html;

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

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

root html; }

} } 

7.按以上 nginx 配置文件的要求,创建对应的缓存目录: 

mkdir -p /fastdfs/cache/nginx/proxy_cache

mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp 

8.启动nginx

/usr/local/nginx/sbin/nginx

七、使用 Keepalived + Nginx 组成的高可用负载均衡集群做两个 Tracker 节点中 Nginx 的负载均衡 

参考:http://www.cnblogs.com/sunys/p/6819018.html 

posted on 2017-05-12 14:22  fire-kylin  阅读(153)  评论(0编辑  收藏  举报