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
// 安装nginx upsync 模块 实现consul 读取. 平滑安装
Version:0.9 StartHTML:0000000105 EndHTML:0000005729 StartFragment:0000000141 EndFragment:0000005689
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 实现动态负载均衡成功