Nginx安装与负载均衡配置
来源:互联网 发布:电气控制柜的设计软件 编辑:程序博客网 时间:2024/06/13 11:25
Nginx安装与负载均衡配置
1、CentOS下需要的依赖包
yum install gcc-c++ -y yum install pcre pcre-devel -y yum install zlib zlib-devel -y yum install openssl openssl-devel -y
2、下载nginx源码
wget http://nginx.org/download/nginx-1.13.1.tar.gzwget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/08a395c66e42.zipwget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
解压三个文件可得到
nginx-1.13.1
nginx-goodies-nginx-sticky
nginx_upstream_check_module-master
3、编译并安装nginx
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=../nginx-goodies-nginx-sticky --add-module=../nginx_upstream_check_module-master指定安装的目录,及依赖的组件源码
编译时出现异常
ngx_http_sticky_misc.c: In function 「ngx_http_sticky_misc_md5」:ngx_http_sticky_misc.c:152:15: ERROR:「MD5_DIGEST_LENGTH」 undeclared (first use in this function) u_char hash[MD5_DIGEST_LENGTH];
解决方式就是修改在你下载解压缩之后的sticky模块文件夹中的ngx_http_sticky_misc.c文件
将这两个模块 <openssl/sha.h> and<openssl/md5.h>包含到文件ngx_http_sticky_misc.c
#include <nginx.h>#include <ngx_config.h>#include <ngx_core.h>#include <ngx_http.h>#include <ngx_md5.h>#include <ngx_sha1.h>#include <openssl/sha.h>#include <openssl/md5.h>#include "ngx_http_sticky_misc.h"
安装
make && make install
4、启动nginx
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin -s stop
5、负载均衡的配置
vim conf/nginx.conf
worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $request_time $remote_addr'; server { listen 80; server_name hadoop4.ganymede.com; index index.jsp index.html index.htm; location /mdm { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://mdm_balance; } access_log /data/logs/nginx/a_access.log main; error_log /data/logs/nginx/a_error.log; } upstream mdm_balance{ sticky; server hadoop4:8086 weight=1 max_fails=2 fail_timeout=150s; server hadoop5:8086 weight=2 max_fails=2 fail_timeout=150s; }}
6、修改配置后reload服务
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf/usr/local/nginx/sbin/nginx -s reload -c /usr/local/nginx/conf/nginx.conf
阅读全文
1 0
- Nginx安装与负载均衡配置
- 安装 Nginx 配置负载均衡
- nginx的安装与负载均衡的配置
- centos7 nginx安装与配置实现负载均衡
- nginx安装及负载均衡配置
- Linux Ubuntu Nginx负载均衡 安装 配置
- Nginx安装及负载均衡配置
- ubuntu安装nginx及负载均衡配置
- CentOs nginx 安装 及 负载均衡配置
- linux安装nginx并且配置负载均衡
- centos安装nginx,配置负载均衡
- nginx的安装和负载均衡配置
- Nginx负载均衡与集群配置
- nginx代理与负载均衡配置
- nginx负载均衡介绍与配置
- nginx 负载均衡配置
- nginx配置负载均衡
- nginx负载均衡配置
- 正向代理与反向代理、负载均衡
- 解决浏览器登陆GitHub官网提示404的问题
- 两款Docker管理UI:DockerUI & Shipyard
- C# this.Invoke()的作用与用法
- Java多线程——获取多个线程任务执行完的时间
- Nginx安装与负载均衡配置
- 最大和
- js判断全选与全不选以及,js全不选时全选按钮会被勾掉
- NYOJ 23 取石子巴什博奕
- Python3安装geohash
- 【大数据部落】用R进行网站评论文本挖掘聚类
- cocos2dx获取系统当前时间
- 判定一个数独是否有效。
- Linux的吉祥物企鹅的名字?