- 7
- 0
- 约6.12千字
- 约 10页
- 2016-04-09 发布于江苏
- 举报
nginx+keepalived实现高可用负载均衡方案.doc
学习文档
目 录
1. 引言 3
2. 环境说明 3
3. Nginx安装配置 3
4. Keepalived安装配置 5
5. 验证 9
引言
本介绍
主nginx负载均衡器:0 端口81(CentOS release 5.8)
副nginx负载均衡器:1 端口81(CentOS release 5.8)
Tomcat1: 9端口3030
Tomcat2: 0端口4040
VIP:2
软件:keepalived- 1.2.12 nginx-1.4.4
说明:keepalived 是一个基于VRRP协议来实现的WEB服务高可用方案,可以利用其来避免单点故障。一个WEB服务至少会有2台服务器运行Keepalived,一台为主服务器(MASTER),一台为备份服务器(BACKUP),但是对外表现为一个虚拟IP,主服务器会发送特定的消息给备份服务器,当备份服务器收不到这个消息的时候,即主服务器宕机的时候,备份服务器就会接管虚拟IP,继续提供服务,从而保证了高可用性。
Nginx安装配置
1.安装Nginx
获取Nginx稳定版,把 Nginx 安装到 /usr/local/nginx 目录下(两台机器都安装)的详细步骤:
yum –y install gcc openssl-devel pcre-devel zlib-devel(安装相关组件)
tar zxvf nginx-1.4.4.tar.gz
cd nginx-1.4.4
./configure
--prefix=/usr/local/nginx
--with-http_ssl_module
--with-http_flv_module
--with-http_gzip_static_module
--with-http_stub_status_module
make make install
分别在两台服务器编写配置文件
vim /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
upstream cart {
server 9:3030 weight=1;
server 0:4040 weight=1;
#ip_hash; #在没有做共享session的情况下ip_hash可以解决session问题
}
server {
listen 81;
server_name 0; #另外一台填写另外IP
charset utf-8;
location /cart {
root html;
index index.html index.htm;
proxy_next_upstream error timeout http_500 http_502 http_504;
proxy_read_timeout 10s;
proxy_pass http://cart;
proxy_set_header Host $host:81; #没用默认80端口需要加入
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
log_format access_log $remote_addr - $remote_us
原创力文档

文档评论(0)