node + nginx + mongo搭建负载均衡

基于node和nignx和mongo搭建负载均衡

nginx配置:

upstream back {                                                  #使用upstream设置不同的权重模块,权重越高nginx传递越多的连接,back是自定义的一个名称.会链接到proxy_pass http://back;
server 10.0.0.5:10000 fail_timeout=15s;
server 10.0.0.7:10000 fail_timeout=15s;
ip_hash;                      #采用ip哈希的算法,设置负载均衡

}

server {
client_max_body_size 50m;
server_name load.enterplorer.com;
access_log /var/log/nginx/back.access.log;
error_log /var/log/nginx/back.error.log;

listen 80;

location / {
proxy_pass http://back;                                 # 反向代理到上游服务器地址,就是upstream back 的back
proxy_http_version 1.1;             #这是http请求设置的
proxy_set_header Connection "";         #负载均衡的头部保持连接,不返回close
proxy_read_timeout 300; # Some requests take more than 30 seconds.
proxy_connect_timeout 300; # Some requests take more than 30 seconds.
proxy_set_header X-Forwarded-Proto $scheme;
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_set_header X-Frame-Options SAMEORIGIN;
}
}

mongodb配置:

dbpath=/home/mongodb/data
logpath=/home/mongodb/log/mongodb.log
logappend=true
port=27017
fork=true
noauth=true
master=true
oplogSize=2048
slave=true
source=10.0.0.7
slavedelay=1
autoresync=true

 

posted @ 2016-12-01 10:19  jay-  阅读(278)  评论(0编辑  收藏  举报