标签:效果 本质 var 检查 roo 发送 定位 listen 内存
状态
|
概述
|
max_fails
|
允许请求失败的次数,默认为1。
|
max_conns
|
限制最大接受的连接数。
|
fail_timeout
|
在经历了max_fails次失败后,暂停服务的时间。
|
backup
|
预留的备份机器。
|
down
|
表示当前的server暂时不参与负载均衡。
|
主机
|
IP
|
备注
|
nginx01
|
172.24.10.21
|
Nginx负载均衡
|
nginx02
|
172.24.10.22
|
后端RS 01
|
nginx03
|
172.24.10.23
|
后端RS 02
|
nginx04
|
172.24.10.24
|
后端RS 03
|
1 [root@nginx02 ~]# mkdir /usr/share/nginx/balanc/ 2 [root@nginx02 ~]# echo ‘<h1>Rs_172.24.10.22</h1>‘ > /usr/share/nginx/balanc/index.html
[root@nginx02 ~]# cat > /etc/nginx/conf.d/rs.conf <<EOF server { listen 9090; server_name 172.24.10.22; location / { root /usr/share/nginx/balanc; index index.html; access_log /var/log/nginx/rs.access.log main; error_log /var/log/nginx/rs.error.log warn; } } EOF
1 [root@nginx02 ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@nginx02 ~]# nginx -s reload #重载配置文件
1 [root@nginx03 ~]# mkdir /usr/share/nginx/balanc/ 2 [root@nginx03 ~]# echo ‘<h1>Rs_172.24.10.23</h1>‘ > /usr/share/nginx/balanc/index.html
[root@nginx03 ~]# cat > /etc/nginx/conf.d/rs.conf <<EOF server { listen 9090; server_name 172.24.10.23; location / { root /usr/share/nginx/balanc/; index index.html; access_log /var/log/nginx/rs.access.log main; error_log /var/log/nginx/rs.error.log warn; } } EOF
1 [root@nginx03 ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@nginx03 ~]# nginx -s reload #重载配置文件
1 [root@nginx04 ~]# mkdir /usr/share/nginx/balanc/ 2 [root@nginx04 ~]# echo ‘<h1>Rs_172.24.10.24</h1>‘ > /usr/share/nginx/balanc/index.html
[root@nginx04 ~]# cat > /etc/nginx/conf.d/rs.conf <<EOF server { listen 9090; server_name 172.24.10.24; location / { root /usr/share/nginx/balanc/; index index.html; access_log /var/log/nginx/rs.access.log main; error_log /var/log/nginx/rs.error.log warn; } } EOF
[root@nginx04 ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 [root@nginx04 ~]# nginx -s reload #重载配置文件 [root@client ~]# curl 172.24.10.22:9090 <h1>Rs_172.24.10.22</h1> [root@client ~]# curl 172.24.10.23:9090 <h1>Rs_172.24.10.23</h1> [root@client ~]# curl 172.24.10.24:9090 <h1>Rs_172.24.10.24</h1>
[root@nginx01 ~]# vi /etc/nginx/conf.d/balance.conf upstream mybalance01 { server 172.24.10.22:9090; server 172.24.10.23:9090; server 172.24.10.24:9090; } server { listen 80; server_name balance.linuxds.com; access_log /var/log/nginx/mybalance.access.log main; error_log /var/log/nginx/mybalance.error.log warn; location / { proxy_pass http://mybalance01; index index.html; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; #允许客户端请求的最大单文件字节数 client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数 proxy_connect_timeout 300; #nginx跟后端服务器连接超时时间(代理连接超时) proxy_send_timeout 300; #后端服务器数据回传时间(代理发送超时) proxy_read_timeout 300; #连接成功后,后端服务器响应时间(代理接收超时) proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2) proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传 } }
1 [root@balance ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@balance ~]# nginx -s reload #重载配置文件
[root@balance ~]# vi /etc/nginx/conf.d/balance.conf upstream mybalance01 { server 172.24.9.11:9090 weight=1 max_fails=1 fail_timeout=2; server 172.24.9.12:9090 weight=8 max_fails=2 fail_timeout=2; server 172.24.9.13:9090 backup; #配置为备份服务器 } server { listen 80; server_name balance.linuxds.com; access_log /var/log/nginx/mybalance.access.log main; error_log /var/log/nginx/mybalance.error.log warn; location / { proxy_pass http://mybalance01; index index.html; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }
1 [root@balance ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@balance ~]# nginx -s reload #重载配置文件
[root@balance ~]# vi /etc/nginx/conf.d/balance.conf upstream mybalance01 { least_conn; server 172.24.10.21:9090; server 172.24.10.22:9090; server 172.24.10.23:9090; } server { listen 80; server_name balance.linuxds.com; access_log /var/log/nginx/mybalance.access.log main; error_log /var/log/nginx/mybalance.error.log warn; location / { proxy_pass http://mybalance01; index index.html; } }
1 [root@balance ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@balance ~]# nginx -s reload #重载配置文件
[root@balance ~]# vi /etc/nginx/conf.d/balance.conf upstream mybalance01 { ip_hash; server 172.24.10.21:9090; server 172.24.10.22:9090; server 172.24.10.23:9090; } server { listen 80; server_name balance.linuxds.com; access_log /var/log/nginx/mybalance.access.log main; error_log /var/log/nginx/mybalance.error.log warn; location / { proxy_pass http://mybalance01; index index.html; } }
1 [root@balance ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@balance ~]# nginx -s reload #重载配置文件
[root@balance ~]# vi /etc/nginx/conf.d/balance.conf upstream mybalance01 { fair; server 172.24.10.21:9090; server 172.24.10.22:9090; server 172.24.10.23:9090; } server { listen 80; server_name balance.linuxds.com; access_log /var/log/nginx/mybalance.access.log main; error_log /var/log/nginx/mybalance.error.log warn; location / { proxy_pass http://mybalance01; index index.html; } }
1 [root@balance ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@balance ~]# nginx -s reload #重载配置文件
[root@balance ~]# vi /etc/nginx/conf.d/balance.conf upstream mybalance01 { hash $request_uri; hash_method crc32; server 172.24.10.21:9090; server 172.24.10.22:9090; server 172.24.10.23:9090; } server { listen 80; server_name balance.linuxds.com; access_log /var/log/nginx/mybalance.access.log main; error_log /var/log/nginx/mybalance.error.log warn; location / { proxy_pass http://mybalance01; index index.html; } }
1 [root@balance ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 2 [root@balance ~]# nginx -s reload #重载配置文件
标签:效果 本质 var 检查 roo 发送 定位 listen 内存
原文地址:https://www.cnblogs.com/liujunjun/p/14128850.html