网站首页 > 技术教程 正文
负载均衡建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性。 |
1 consul
1.1 consul简介
Consul 是一个支持多数据中心分布式高可用的服务发现和配置共享的服务软件。 服务发现以及注册:当服务Producer 启动时,会将自己的Ip/host等信息通过发送请求告知 Consul,Consul 接收到 Producer 的注册信息后,每隔一段时间会向 Producer 发送一个健康检查的请求,检验Producer是 否健康。
服务调用:当 Consumer 请求Product时,会先从 Consul 中拿到存储Product服务的 IP 和 Port 的临时表 (temp table),从temp table表中任选一个· Producer 的 IP 和 Port, 然后根据这个IP和Port,发送访问请 求;temp table表只包含通过了健康检查的 Producer 信息,并且每隔一段时间更新。
1.2 consul安装
拉取consul镜像
docker pull consul
2.构建consul容器
docker run -p 8500:8500 -d --name consul -v /docker/consul/data:/consul/data -- privileged=true –e CONSUL_BIND_INTERFACE='eth0'consul agent -server -bootstrap-expect 1 -data-dir /consul/data -node=ali -ui -client='0.0.0.0'
参数含义:
agent -server表示启动的是一个服务
-bootstrap-expect 1 表示等待多少个节点再启动,这里1个,就是自己一个就启动了
-node=texun_1 就是给consul服务起个别名为ali
-data-dir /opt/data 数据存储目录为/opt/data
-ui 启动默认ui界面
-client consul绑定在哪个client地址上,这个地址提供HTTP、DNS、RPC等服务,默认是 127.0.0.1,可指定允许客户端使用什么ip去访问
2 nginx安装nginx-upsync-module模块
1.将准备的素材copy到nginx容器
docker cp /home/nginx-upsync-module-master.zip nginx:/home/
docker cp /home/nginx-1.21.0.tar.gz nginx:/home/
2.进入容器解压安装包
unzip nginx-upsync-module-master.zip
tar -zxvf nginx-1.21.0.tar.gz
3.安装相关扩展
apt-get install -y gcc autoconf automake make libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev
4.进入解压的nginx安装包,进行编译安装
cd /home/nginx-1.21.0
#通过命令查看nginx版本与编译信息
nginx -V
#复制相关编译信息,添加nginx- upsync-module-master模块
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.21.0/debian/debuild-base/nginx-1.21.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' --add-module=/home/nginx-upsync-module-master
5.编译安装
make && make install
3 nginx动态负载均衡配置
upstream edu{
server 192.168.35.138;
upsync 172.17.0.3:8500/v1/kv/upstreams/nginx_test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
upsync_dump_path /etc/nginx/conf.d/server_test.conf;
include /etc/nginx/conf.d/server_test.conf;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
root /docker/www/;
index index.php index.html;
location / {
proxy_pass http://edu;
}
}
往consul加入nginx服务
curl -X PUT -d '{"weight":1,"max_fails":2,"fail_timeout":10}' http://192.168.35.139:8500/v1/kv/upstreams/nginx_test/192.168.35.131:81
curl -X PUT -d '{"weight":1,"max_fails":2,"fail_timeout":10}' http://192.168.35.139:8500/v1/kv/upstreams/nginx_test/192.168.35.131:80
接着查看server_test.conf文件,看看consul是否有将我们新增的nginx服务加入到负载均衡中。
nginx+consul做动态负载均衡(docker) | 《Linux就该这么学》 (linuxprobe.com)
猜你喜欢
- 2024-10-12 高级开发必须掌握Nginx之一 反向代理、动静分离、负载均衡
- 2024-09-25 面试题:Nginx 有哪些负载均衡策略?Nginx为什么要做动静分离?
- 2024-09-25 一张小图看尽 Nginx(看看一张图片)
- 2024-09-25 nginx的动静分离,你真的懂吗?(nginx+tomcat动静分离,linux)
- 2024-09-25 7、Nginx+Apache环境配置——动静分离
- 2024-09-25 通过 Consul-Template 实现动态配置Nginx负载服务
- 2024-09-25 Nginx、Consul、Upsync实现动态负载均衡配置
- 2024-09-25 30s 就可以掌握的 Nginx 片段(nginx 304)
- 2024-09-25 Jenkins for Kubernetes实现Slave动态伸缩
- 2024-09-25 Nginx总结(九) 实现系统的动静分离
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)