日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

手把手搭建一个容器化+代理网关+可视化管理环境

發(fā)布時間:2024/8/23 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 手把手搭建一个容器化+代理网关+可视化管理环境 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

作者 | togettoyou

來源 | SuperGopher

前言

本文主要分享個人服務(wù)器的應(yīng)用部署方案現(xiàn)狀,容器化+代理網(wǎng)關(guān)+可視化管理。

準(zhǔn)備階段

我購買的是騰訊云服務(wù)器(2 核 4GB 3Mbps)

域名也是在騰訊云備案過的,提前準(zhǔn)備域名解析

配置環(huán)境

安裝 Docker

curl?-sSL?https://get.daocloud.io/docker?|?sh

安裝 Docker Compose

curl?-L?https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname?-s`-`uname?-m`?>?/usr/local/bin/docker-compose chmod?+x?/usr/local/bin/docker-compose

設(shè)置鏡像加速和開機自啟

mkdir?/etc/docker echo?'{"registry-mirrors":["https://reg-mirror.qiniu.com/"]}'?>?/etc/docker/daemon.json sudo?systemctl?daemon-reload sudo?systemctl?restart?docker sudo?systemctl?enable?docker

部署 Traefik

創(chuàng)建 Traefik 目錄,并在該目錄下進行系列操作

cd?~ mkdir?traefik cd?traefik/

創(chuàng)建 Traefik 的啟動配置

vi?traefik.yml#?定義監(jiān)聽端口:web(80)?和 websecure(443) entryPoints:web:address:?":80"websecure:address:?":443" #?配置發(fā)現(xiàn)提供者,這里為?docker providers:docker:?{} #?開啟?Traefik?面板訪問?(8080端口) api:dashboard:?trueinsecure:?true #?創(chuàng)建名稱為?open-https?的??tls?配置(會使用?Let's?Encrypt?自動生成?https?證書) certificatesResolvers:open-https:acme:email:?"youremail@qq.com"storage:?"acme.json"httpChallenge:entryPoint:?web

創(chuàng)建名稱為 traefik 的 Docker 網(wǎng)絡(luò)環(huán)境,后續(xù) Traefik 和需要代理的應(yīng)用容器都需要部署在該網(wǎng)絡(luò)環(huán)境下才可以被訪問到

docker?network?create?traefik

創(chuàng)建 docker-compose 配置

vi?docker-compose.ymlversion:?'3' services:traefik:image:?traefik:v2.4#?需要將本地的?/var/run/docker.sock?掛載到?Traefik?容器內(nèi),才可以使用到?docker?配置發(fā)現(xiàn)volumes:-?/var/run/docker.sock:/var/run/docker.sock-?$PWD/traefik.yml:/etc/traefik/traefik.ymlrestart:?always#?把?Traefik?容器監(jiān)聽的?80?和?443?端口映射到宿主機(以后宿主機只要暴露?80?和?443?就可以了,所有流量通過?Traefik?代理)ports:-?"80:80"-?"443:443"#?使用自定義的?traefik?網(wǎng)絡(luò)networks:-?traefik#?標(biāo)簽配置,Traefik?的配置發(fā)現(xiàn)是通過標(biāo)簽抓取的labels:#?開啟?redirectscheme?中間件,中間件名稱為?redirect-https?,該中間件可以重定向?http?到?https?,達到強制?https?的目的-?"traefik.http.middlewares.redirect-https.redirectscheme.scheme=https"#?配置一個名稱為?traefik-service?的服務(wù),容器內(nèi)端口為?8080-?"traefik.http.services.traefik-service.loadbalancer.server.port=8080"#?配置一個名稱為?https-traefik?的路由,代理服務(wù)為?traefik-service#?監(jiān)聽域名為?traefik.togettoyou.com?,端口為?websecure?(443)?的流量請求#?開啟?tls?,使用?open-https?,自動簽發(fā)證書-?"traefik.http.routers.https-traefik.service=traefik-service"-?"traefik.http.routers.https-traefik.rule=Host(`traefik.togettoyou.com`)"-?"traefik.http.routers.https-traefik.entrypoints=websecure"-?"traefik.http.routers.https-traefik.tls=true"-?"traefik.http.routers.https-traefik.tls.certresolver=open-https"#?配置一個名稱為?http-traefik?的路由,代理服務(wù)為?traefik-service#?監(jiān)聽域名為?traefik.togettoyou.com?,端口為?web?(80)?的流量請求#?使用?redirect-https?中間件,將?http?請求重定向到?https,即重定向到了上面配置的?https-traefik?路由-?"traefik.http.routers.http-traefik.service=traefik-service"-?"traefik.http.routers.http-traefik.rule=Host(`traefik.togettoyou.com`)"-?"traefik.http.routers.http-traefik.entrypoints=web"-?"traefik.http.routers.http-traefik.middlewares=redirect-https"networks:traefik:external:?true

啟動 Traefik

docker-compose?up?-d

訪問 http://traefik.togettoyou.com 時會發(fā)現(xiàn)被 302 重定向到了 https://traefik.togettoyou.com ,并且自動配置了證書

查看面板也可以發(fā)現(xiàn)和我們預(yù)期的一致

部署 Docker 可視化工具

Portainer 是一個 Docker 的可視化圖形工具。

同理,我們創(chuàng)建 Portainer 目錄,并在該目錄進行系列操作

cd?~ mkdir?portainer cd?portainer/

創(chuàng)建 docker-compose 配置

vi?docker-compose.ymlversion:?'3' services:portainer:image:?portainer/portainer-ce#?掛載?/var/run/docker.sock?,并持久化?portainer?數(shù)據(jù)volumes:-?/var/run/docker.sock:/var/run/docker.sock-?$PWD/data:/datarestart:?always#?使用自定義的?traefik?網(wǎng)絡(luò)networks:-?traefiklabels:#?配置一個名稱為?portainer-service?的服務(wù),容器內(nèi)端口為?9000-?"traefik.http.services.portainer-service.loadbalancer.server.port=9000"#?配置一個名稱為?https-portainer?的路由,代理服務(wù)為?portainer-service#?監(jiān)聽域名為?docker.togettoyou.com?,端口為?websecure?(443)?的流量請求#?開啟?tls?,使用?open-https?,自動簽發(fā)證書-?"traefik.http.routers.https-portainer.service=portainer-service"-?"traefik.http.routers.https-portainer.rule=Host(`docker.togettoyou.com`)"-?"traefik.http.routers.https-portainer.entrypoints=websecure"-?"traefik.http.routers.https-portainer.tls=true"-?"traefik.http.routers.https-portainer.tls.certresolver=open-https"#?配置一個名稱為?http-portainer?的路由,代理服務(wù)為?portainer-service#?監(jiān)聽域名為?docker.togettoyou.com?,端口為?web?(80)?的流量請求#?使用?redirect-https?中間件,將?http?請求重定向到?https,即重定向到了上面配置的??https-portainer?路由-?"traefik.http.routers.http-portainer.service=portainer-service"-?"traefik.http.routers.http-portainer.rule=Host(`docker.togettoyou.com`)"-?"traefik.http.routers.http-portainer.entrypoints=web"-?"traefik.http.routers.http-portainer.middlewares=redirect-https"networks:traefik:external:?true

啟動 Portainer

docker-compose?up?-d

查看面板

訪問 docker.togettoyou.com

總結(jié)

利用 Docker + Traefik + Portainer ,極大方便了我們個人服務(wù)器應(yīng)用部署。Traefik 監(jiān)聽著 80 和 443 端口,因此服務(wù)器只需要暴露出這兩個端口,其他的流量請求都交由 Traefik 來代理,基于 Traefik 的配置發(fā)現(xiàn)機制,在部署我們的容器應(yīng)用時只要在 Label 加上 Traefik 的規(guī)則即可;對于容器應(yīng)用的啟動停止、日志查看等使用 Portainer 綽綽有余,幾乎不需要登陸到服務(wù)器上操作查看。

往期推薦

Spring 完美導(dǎo)入 IDEA

k8s集群居然可以圖形化安裝了?

使用這個庫,讓你的服務(wù)操作 Redis 速度飛起

將 k8s 制作成 3D 射擊游戲,好玩到停不下來

點分享

點收藏

點點贊

點在看

總結(jié)

以上是生活随笔為你收集整理的手把手搭建一个容器化+代理网关+可视化管理环境的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。