linux - Nginx 负载均衡器在 Docker 中运行的高可用性
问题描述
我正在运行我的后端 Web 服务器的 nginx 负载平衡器容器,
由于我只有一个容器作为 nginx 负载均衡器运行,因此在容器死亡/崩溃的情况下,客户端无法访问网络服务器,
下面是 nginx.conf
events {}
http {
upstream backend {
server 1.18.0.2;
server 1.18.0.3;
}
# This server accepts all traffic to port 80 and passes it to the upstream.
# Notice that the upstream name and the proxy_pass need to match.
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
}
下面是 Dockerfile:
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
我正在运行如下所示的 nginx 容器
docker run -d -it -p 8082:80 nginx-ls
我正在使用 http://serve-ip:8082 访问上面的服务器
容器可能随时崩溃或死机,在这种情况下,我的应用程序无法访问,所以我尝试运行像下面这样的另一个容器,但由于我使用相同的端口而出现以下错误,并且我们无法在同一主机中重新使用相同的端口.
docker run -d -it -p 8082:80 nginx-ls
06a20239bd303fab2bbe161255fadffd5b468098424d652d1292974b1bcc71f8
docker: Error response from daemon: driver failed programming external connectivity on endpoint
suspicious_darwin (58eeb43d88510e4f67f618aaa2ba06ceaaa44db3ccfb0f7335a739206e12a366): Bind for
0.0.0.0:8082 failed: port is already allocated.
所以我在不同的端口运行,它工作正常
docker run -d -it -p 8083:80 nginx-ls
但是当容器 8082 关闭时,我们如何告诉/配置客户端使用端口 8083 容器
还是有其他最佳方法来实现具有高可用性的 nginx 负载均衡器?
注意:由于某些原因,我不能使用 docker-compose
解决方案
推荐阅读
- security - 基于 IP 地址的“记住我”功能
- c# - CS0175 在此上下文中使用关键字“base”无效
- javascript - 如何从外部来源捕获 console.log?
- bash - Bash 脚本将 ipv4 地址与正则表达式变量匹配
- excel - VBA宏通过特定单元格值过滤表格并删除所有行
- java - 当超类型方法调用超类型和子类型中都存在的方法时调用哪个实例方法
- sql - SQL Server - 使用 Sum Up 连续连接重复和交叉行
- javascript - 为什么 JavaScript 闭包不能与双括号一起正常工作?
- php - 尝试在 Amazon AWS 上的 mySQL 数据库上使用 JSON_OBJECT 函数
- maven - 在詹金斯作业上多次执行`mvn test`