我正在使用Docker/Node/Nginx設置一個Web服務器。我一直在玩docker-compose中的設置,並提出了兩個工作解決方案 - 但在負載平衡方面,其中一個可能太好了,無法成立(因爲它似乎允許我通過沒有創建額外的圖像/容器)。如果我所看到的實際上是合法的,並且多個圖像等不是負載平衡的要求,我正在尋找驗證。這個Docker/NGINX/Node設置實際上是否按預期負載平衡?
溶液1(無附加圖像):
搬運工-compose.yml
version: '3'
volumes:
node_deps:
services:
nginx:
build: ./nginx
image: nginx_i
container_name: nginx_c
ports:
- '80:80'
- '443:443'
links:
- node
restart: always
node:
build: ./node
image: node_i
container_name: node_c
command: "npm start"
ports:
- '5000:5000'
- '5001:5001'
- '5500:5000'
- '5501:5001'
volumes:
- ./node:/src
- node_deps:/src/node_modules
nginx.conf
http {
...
upstream shopster-node {
server node:5000 weight=10 max_fails=3 fail_timeout=30s;
server node:5500 weight=10 max_fails=3 fail_timeout=30s;
keepalive 64;
}
server {
...
}
}
溶液2(具有附加圖像):
version: '3'
volumes:
node_deps:
services:
nginx:
build: ./nginx
image: nginx_i
container_name: nginx_c
ports:
- '80:80'
- '443:443'
links:
- node_one
- node_two
restart: always
node_one:
build: ./node
image: node_one_i
container_name: node_one_c
command: "npm start"
ports:
- '5000:5000'
- '5001:5001'
volumes:
- ./node:/src
- node_deps:/src/node_modules
node_two:
build: ./node
image: node_two_i
container_name: node_two_c
command: "npm start"
ports:
- '5500:5000'
- '5501:5001'
volumes:
- ./node:/src
- node_deps:/src/node_modules
ngin x.conf
http {
...
upstream shopster-node {
server node_one:5000 weight=10 max_fails=3 fail_timeout=30s;
server node_two:5500 weight=10 max_fails=3 fail_timeout=30s;
keepalive 64;
}
server {
...
}
}
這兩種情況都加載該應用完美,在localhost &在指定端口上。我確信場景2是正確的負載平衡,因爲它模仿了傳統的多服務器場景。
有什麼辦法可以驗證場景1實際上是否按預期進行負載平衡?這將是我首選的方法,我只需要知道我可以信任它。