consul 安装

nginx 安装在之前有讲到过

阿里云centos 安装

(1)Consul 下载地址:https://www.consul.io/downloads.html,下载后解压就是一个可执行的二进制文件consul,配置好环境变量,检查 consul 是否可用 这是github地址:https://github.com/hashicorp/consul/releases 这是码云地址:https://gitee.com/mirrors/consul (2)下载完后,解压,得到一个可执行文件consul

启动consul报错(课件中启动方式)

consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -node=ali -bind=47.***.***.193 -ui -client=0.0.0.0

启动成功

consul agent -dev -ui -node=consul-dev -client=0.0.0.0 -bind=172.*****.138(阿里云私有ip)

consul agent -dev -ui -node=consul-dev -client=0.0.0.0

以上两种开启方式。带bind 和 不带bind 的却别是 不带bind 则只能服务器上 本机访问除了 8600 和 8500

输入:   http://47.*****.193:8500/

服务注册

curl -X PUT -d '{"weight":1,"max_fails":2,"fail_timeout":10}' http://127.0.0.1:8500/v1/kv/upstreams/swoole_test/127.0.0.1:8889

输入访问consul 

http://47.***.***.193:8500/

// 安装nginx upsync 模块 实现consul 读取.  平滑安装

Version:0.9 StartHTML:0000000105 EndHTML:0000005729 StartFragment:0000000141 EndFragment:0000005689

> cd /re redis_2004/file
> wget https://github.com/weibocom/nginx-upsync-module/archive/v2.1.0.tar.gz
> tar -zxvf v2.1.0.tar.gz
> cd nginx-1.17.4 -- 你编译的 nginx 模块中
> ./configure --add-module=/redis_2004/file/nginx-upsync-module-2.1.0
> make
> cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx2
> rm -rf /usr/local/nginx/sbin/nginx
> netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 76059/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6824/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7117/master
> cp /redis_2004/file/nginx-1.17.4/objs/nginx /usr/local/nginx/sbin/
cp :是否覆盖 "/usr/local/nginx/sbin/nginx" yes
cp: 无法创建普通文件 "/usr/local/nginx/sbin/nginx": 文本文件忙
> rm -rf /usr/local/nginx/sbin/nginx
> cp /redis_2004/file/nginx-1.17.4/objs/nginx /usr/local/nginx/sbin/
> make upgrade
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
make: *** [upgrade] 错误 1

ngixn 配置文件 

worker_processes  2;
worker_cpu_affinity auto;  #自动绑定cpu跟进程的关系
events {
    worker_connections  100000; #设置单个worker连接数
}
error_log /redis_2004/logs/error.log;
http {
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    upstream swo_http_up {
        server  192.168.169.140:9001;

        upsync  127.0.0.1:8500/v1/kv/upstreams/swoole_test upsync_timeout=6m upsync_interval=500ms  upsync_type=consul  strong_dependency=off;
        upsync_dump_path /redis_2004/17/servers_test.conf;
        include /redis_2004/17/servers_test.conf;
        
    }

    server {
        listen       80;
        server_name  localhost;

        location /swoole {
             proxy_pass http://swo_http_up;
        }

        location / {
            autoindex on;
            root /redis_2004/16;
        }
    }
}

配置好 并重启nginx 后查看 配置负载均很的文件中查看

/redis_2004/17/servers_test.conf

动态nginx+consul+upsync 实现动态负载均衡成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值