配合nginx,使用docker來臨時替代故障服務器啟動后臺的一次嘗試

由于點擊量實在太大,不得不在ngip,cepip都啟動了點擊處理程序,然后nginx配置負載均衡轉發到這兩個程序。

然而點擊處理消耗了大量的內存,最終導致ngip沒有多余的內存了。

這樣穩定跑了一天。

渠道那邊問,給下游渠道的后臺登不上去了。

才想起來因為內存不夠,我關閉了渠道的后臺。

此刻面臨著要么把點擊關掉,挪動到別的服務器,要么想辦法啟動備用的渠道后臺。

實在是看到點擊穩定的太好,舍不得這樣放棄。

于是決定在docker集群上啟動渠道后臺。

1. ?創建編排模板(之前沒有嘗試過在一個應用中暴露兩個端口,這次決心試試)

ports:

- '8078'

- '8088'

privileged: true

restart: always

volumes:

- /root:/root_doc

labels:

aliyun.scale: '1'

aliyun.auto_scaling.min_instances: '1'

aliyun.routing.port_8088: http://media.xx.XX.com

aliyun.routing.port_8078: http://download.media.xx.XX.com

aliyun.auto_scaling.max_cpu: '80'

aliyun.auto_scaling.min_cpu: '10'

aliyun.auto_scaling.step: '1'

2. 創建好需要的Dockerfile,docker.sh,start.sh. 創建好應用和觸發器。然后本地push上集群。

3. 看到在節點上的端口映射為 0.0.0.0:32769->8078/tcp, 0.0.0.0:32768->8088。

4. 打開nginx配置文件,開始配置轉發:

upstream ups_cpa-n-down {

server 172.17.0.8:32769 max_fails=3 fail_timeout=4s weight=2;

}

upstream ups_cpa-n {

server 172.17.0.8:32768 max_fails=3 fail_timeout=4s weight=2;

}

#server {

#? ? ? listen 8088;

#? ? ? listen [::]:8088;

#

#? ? ? server_name media.XXX.com ;

#

#? ? ? location / {

#? ? ? ? ? ? ? proxy_pass http://ups_cpa-n;

#? ? ? ? ? ? ? proxy_store off;

#? ? ? ? ? ? ? proxy_redirect off;

#? ? ? ? ? ? ? proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

#? ? ? ? ? ? ? proxy_set_header X-Real-IP $remote_addr;

#? ? ? ? ? ? ? proxy_set_header Host $http_host;

#? ? ? }

#}

#

#server {

#? ? ? listen 8078;

#? ? ? listen [::]:8078;

#

#? ? ? server_name media.XXX.com ;

#

#? ? ? location / {

#? ? ? ? ? ? ? proxy_pass http://ups_cpa-n-down;

#? ? ? ? ? ? ? proxy_store off;

#? ? ? ? ? ? ? proxy_redirect off;

#? ? ? ? ? ? ? proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

#? ? ? ? ? ? ? proxy_set_header X-Real-IP $remote_addr;

#? ? ? ? ? ? ? proxy_set_header Host $http_host;

#? ? ? }

#}

5. 為何會寫出上述配置呢?因為 nginx服務器掛載了 media.XXX.com 的域名,所以最好在nginx上監聽渠道后臺原來監聽的 8078(下載),8088(處理json請求):

server {

listen 80;

listen [::]:80;

server_name media.XXX.com ;

location / {

root /home/arch/XX_N-v1;

index login.html index.html index.htm;

}

location /XX_N {

alias /home/arch/XX_N-v1;

index login.html index.html index.htm;

}

}

6. ngr一下,然后打開渠道后臺,登錄成功!但是下載時,提示找不到文件!

實在沒有時間了,于是將ngip上的點擊程序遷移到msgIP,終于有內存了!然后注釋nginx添加的server段,啟動渠道后臺,一切恢復正常了。

思考:要想真正在生產環境中幫上忙,應該優化那些地方呢? 想想 pop.zoo local域名?

比如,port固定綁定,這樣幾點的固定的端口就會提供固定的服務。

ports:

- "10080:80"

- "10022:22"

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容