龙空技术网

负载均衡-nginx学习01

北漂的一只it狗 150

前言:

现在我们对“nginxclose_wait过多”大致比较珍视,大家都需要分析一些“nginxclose_wait过多”的相关内容。那么小编也在网摘上网罗了一些对于“nginxclose_wait过多””的相关知识,希望我们能喜欢,你们快快来了解一下吧!

相关环境

192.168.3.40(apache)已发布

192.168.3.49(nginx)已发布

192.168.3.52(elb)

1、相关依赖包安装

yum update -y

yum -y install gcc gcc+ gcc-c++ pcre pcre-devel zlib-devel openssl openssl-devel wget vim tree lsof

2、建立nginx用户及组和软件目录

groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx

mkdir -p /data /data/nginx1.6.2

cd /data

3、下载软件并安装

[root@elb data]# wget

[root@elb data]# ls

nginx-1.6.2.tar.gz

[root@elb data]# pwd

/data

[root@elb data]# tar -zxvf nginx-1.6.2.tar.gz

[root@elb nginx-1.6.2]# ./configure --help | grep upstrea 默认就安装了

--without-http_upstream_ip_hash_module

disable ngx_http_upstream_ip_hash_module

--without-http_upstream_least_conn_module

disable ngx_http_upstream_least_conn_module

--without-http_upstream_keepalive_module

disable ngx_http_upstream_keepalive_module

[root@elb nginx-1.6.2]# ./configure --user=nginx --group=nginx --prefix=/data/nginx1.6.2 --with-http_stub_status_module --with-http_ssl_module

[root@elb nginx-1.6.2]#make && make install

[root@elb nginx-1.6.2]# echo $?

[root@elb nginx-1.6.2]#ln -s /data/nginx1.6.2 /data/nginx

[root@elb data]# cd nginx

[root@elb nginx]# ls

conf html logs sbin

[root@elb sbin]# lsof -i :80

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

clock-app 2057 root 21u IPv4 121124 0t0 TCP 192.168.3.52:49828->42.99.254.162:http (CLOSE_WAIT)

nginx 43511 root 6u IPv4 158444 0t0 TCP *:http (LISTEN)

nginx 43512 nginx 6u IPv4 158444 0t0 TCP *:http (LISTEN

[root@elb nginx]# cd conf/

[root@elb conf]# ls

fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf

fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default

[root@elb conf]# egrep -v "#|~$" nginx.conf.default >nginx.conf

[root@elb conf]# vi nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

server {

listen 80;

server_name localhost;

location / {

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

}

#################

官方文档

Syntax: upstream name { ... }

Default: —

Context: http

##################

将以下这段放入http标签

upstream backend {

server backend1.example.com weight=5; 域名

server 127.0.0.1:8080 max_fails=3(检查web server3次失败踢出去) fail_timeout=30s(超时时间);

server unix:/tmp/backend3; socket

server backup1.example.com backup; 备份的主机

}

[root@elb conf]# vi nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

upstream backend {

server 192.168.3.40:80 max_fails=3 fail_timeout=30s;

server 192.168.3.49:80 max_fails=3 fail_timeout=30s;

}

server {

listen 80;

server_name ;

index index.html index.htm;

location / {

proxy_pass ;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

}

[root@elb conf]# ../sbin/nginx -t

nginx: the configuration file /data/nginx1.6.2/conf/nginx.conf syntax is ok

nginx: configuration file /data/nginx1.6.2/conf/nginx.conf test is successful

[root@elb conf]# ../sbin/nginx -s reload

负载均衡测试~

1、不同的客户端ie打开

2、脚本curl测试

[root@elb conf]# for n in `seq 100`;do curl 192.168.3.52;sleep 2;done

标签: #nginxclose_wait过多 #nginx162迅雷下载