Nginx搭建负责均衡
2016-05-24 13:36
1061 查看
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor
Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。
上一次我们介绍了kairosdb的集群搭建,现在我们在集群的基础上搭建一个负载均衡,就是用Nginx作为一个代理服务器即可。
一、环境
我们需要单独使用一个服务器作为Nginx服务器,我使用的环境为:
二、安装Nginx
# tar zxvf nginx-1.10.0.tar.gz
# cd nginx-1.10.0
需要安装 gcc-c++否则报错./configure: error: can not define uint32_t
# yum -y install gcc gcc-c++ autoconf automake
#./congigure --prefix=/usr/local/nginx;
#make install;
三、修改配置
# cd /usr/local/nginx/conf
#vim nginx.conf
内容如下:
四、验证
启动好Nginx之后,访问10.10.10.174:80,他会自动访问到10.10.10.172:8080或者10.10.10.173:8080。
Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。
上一次我们介绍了kairosdb的集群搭建,现在我们在集群的基础上搭建一个负载均衡,就是用Nginx作为一个代理服务器即可。
一、环境
我们需要单独使用一个服务器作为Nginx服务器,我使用的环境为:
服务器说明 | CPU | Memory | Disk | IP | OS | Software |
Nginx | 2 core | 4 g | 100 g | 10.10.10.174 | centos7 | nginx-1.10.0.tar.gz |
# tar zxvf nginx-1.10.0.tar.gz
# cd nginx-1.10.0
需要安装 gcc-c++否则报错./configure: error: can not define uint32_t
# yum -y install gcc gcc-c++ autoconf automake
#./congigure --prefix=/usr/local/nginx;
#make install;
三、修改配置
# cd /usr/local/nginx/conf
#vim nginx.conf
内容如下:
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { upstream myServer{ server 10.10.10.172:8080 weight=1; #这里是你自己要做负载均衡的服务器地址1 server 10.10.10.173:8080 weight=1; #这里是要参与负载均衡的地址2 } 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"'; # '$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 10.10.10.174; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://myServer; #root html; #index index.html index.htm; }
# redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; lo 4000 cation = /50x.html { root html; } }保存之后启动,Nginx即可,命令如下:
cd usr/local/nginx/sbin ./nginx重启命令如下:
cd /usr/local/nginx/sbin ./nginx -s reload检查Nginx的配置是否正确
nginx -t -c /usr/local/nginx/conf/nginx.conf 或者 cd /usr/local/nginx/sbin ./nginx -t
四、验证
启动好Nginx之后,访问10.10.10.174:80,他会自动访问到10.10.10.172:8080或者10.10.10.173:8080。
相关文章推荐
- php和nginx默认上传文件大小限制的解决办法
- mac LaunchRocket图像化管理 php-fpm nginx mysql
- LVS+keepalived+Nginx实现负载均衡时前后端故障全自动化处理
- Nginx配置文件详细说明
- Nginx报错403 forbidden (13: Permission denied)的解决办法
- 分步LVS: 详解利用Keepalived+Nginx解决站点高可用性
- Nginx 之六: Nginx十万并发优化
- nginx平滑升级
- Centos 6.5中Nginx的安装.
- CentOS 7编译安装Nginx1.9.0
- Linux下nginx源码包安装
- Linux操作系统安装nginx
- 转:Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解
- nginx-rtmp-module 指令详解
- nginx上传文件大小
- nginx配置优先级
- Redstone 云观象台 服务器部署 - Nginx配置文件
- nginx查看目标文件夹内容
- Nginx安装与配置文件解析
- 转: 基于nginx的hls直播系统