docker演示nginx負載均衡

2021-10-07 11:29:04 字數 2064 閱讀 2168

背景:在上篇docker演示nginx反向** 基礎上繼續

1. 分別編寫load_balancing_8000.py、load_balancing_8001.py指令碼(注意指令碼對應埠分別為8000、8001)

#!/usr/bin/python3

# -*- coding: utf-8 -*-

from flask import flask

def get_msg():

"""curl -x get ''

"""return "the server port is 8000"

if __name__ == "__main__":

e:\python\python38\python3.exe f:/ideaprojects/my-jooq/my-python/load_balancing_8000.py

* environment: production

warning: this is a development server. do not use it in a production deployment.

use a production wsgi server instead.

* debug mode: on

* restarting with stat

* debugger is active!

* debugger pin: 936-026-506

* running on (press ctrl+c to quit)

e:\python\python38\python3.exe f:/ideaprojects/my-jooq/my-python/load_balancing_8001.py

* environment: production

warning: this is a development server. do not use it in a production deployment.

use a production wsgi server instead.

* debug mode: on

* restarting with stat

* debugger is active!

* debugger pin: 936-026-506

* running on (press ctrl+c to quit)

1. 修改nginx.conf配置

# 定義nginx執行的使用者和使用者組

user nginx;

# nginx程序數,通常設定成和cpu的數量相等

worker_processes 4;

# 全域性錯誤日誌定義型別,[debug | info | notice | warn | error | crit]

error_log /var/log/nginx/error.log warn;

# 程序pid檔案

pid /var/run/nginx.pid;

# 單個程序最大連線數(最大連線數=連線數+程序數)

1. 開啟瀏覽器,檢視請求多次重新整理

2. 或者使用curl命令

從結果可以看出負載均衡成功,到此演示結束

docker上配置nginx負載均衡

1.安裝tomcat docker run d p 8088 8080 tomcat docker run d p 8089 8080 tomcat 安裝兩個例項,埠分別為8088,8089 2.安裝nginx docker run p 8080 80 d docker.io nginx 安裝ngi...

docker搭建nginx配置負載均衡

不對映檔案路徑的建立。docker run name nginx test p 81 80 d nginx 建立準備要對映的檔案路徑。mkdir p docker nginx 把nginx裡的預設配置檔案拷貝出來。容器id 容器中的檔案 宿主機檔案 容器id從上面剛剛執行的nginx test獲取 ...

nginx 為docker容器新增負載均衡

nginx作為當前最流行的負載均衡和反向 伺服器,它執行在linux平台,一般的.net 為了實現分流與負載,需要在多個應用伺服器的iis上部署,通過一些工具實現 的同步,然後再nginx上去配置它們.有了docker,你可以在多個linux上花個1秒鐘去run它即可,不用在iis上部署了,對於do...