Nginx负载均衡应用案例剖析

实验环境1
1测试硬件准备
三台虚拟机,两台做负载均衡一台做RS


#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 {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    include extra/upstream01.conf;
}
######################################
# 删除我们不需要的 添加这行内容
include extra/upstream01.conf;

然后我们需要在extra目录下面创建upstream01.conf 并编辑它
vim extra/upstream01.conf
#blog lb by cyt at 20180107
upstream blog_real_server {
        server 192.168.232.132:80 weight=5;    #upstream 定义一个vserver的名字                                                   blog_real_server
        server 192.168.232.133:80 weight=5;

}

        server {
                listen   80;

                server_name blog.etiantian.org;

                location / {

                proxy_pass http://blog_real_server;   # 通过proxy_pass 定义如果访问                                                    blog.etiantian.org 自动转到                                                        blog_real_server 下面定义的两台                                                    realserver上面去

        }
}

检查语法

然后保存退出后
[root@lb01 conf]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.1/conf/nginx.conf test is successful
还需要本机上面做一个本地域名解析操作 将本机的ip 解析为blog.etiantian.org

重启三台机器上面的nginx
/application/nginx/sbin/nginx -s reload
然后使用curl 命令测试

可以看到多次执行 会平均分配到两台机器上面去,从而是实现负载均衡。

猜你喜欢

转载自www.linuxidc.com/Linux/2018-01/150142.htm