亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Docker容器部署consul的詳細(xì)步驟

 更新時(shí)間:2022年02月07日 16:28:50   作者:小柏ぁ  
Consul 是一個(gè)支持多數(shù)據(jù)中心分布式高可用的 服務(wù)發(fā)現(xiàn)和配置共享 的服務(wù)軟件,接下來通過本文給大家介紹Docker?consul部署的詳細(xì)過程,需要的朋友可以參考下

Consul簡(jiǎn)介

Consul 是一個(gè)支持多數(shù)據(jù)中心分布式高可用的 服務(wù)發(fā)現(xiàn) 和 配置共享 的服務(wù)軟件,由 HashiCorp 公司用 Go 語言開發(fā), 基于 Mozilla Public License 2.0 的協(xié)議進(jìn)行開源。 Consul 支持 健康檢查,并允許 HTTP 、GRPC 和 DNS 協(xié)議調(diào)用 API 存儲(chǔ)鍵值對(duì).
命令行超級(jí)好用的虛擬機(jī)管理軟件 vgrant 也是 HashiCorp 公司開發(fā)的產(chǎn)品.
一致性協(xié)議采用 Raft 算法,用來保證服務(wù)的高可用. 使用 GOSSIP 協(xié)議管理成員和廣播消息, 并且支持 ACL 訪問控制.

Consul 使用場(chǎng)景

  • Docker 實(shí)例的注冊(cè)與配置共享
  • Coreos 實(shí)例的注冊(cè)與配置共享
  • SaaS 應(yīng)用的配置共享、服務(wù)發(fā)現(xiàn)和健康檢查。
  • vitess 集群
  • 與 confd 服務(wù)集成,動(dòng)態(tài)生成 nginx 和 haproxy 配置文件

-consul部署- 

服務(wù)器:192.168.37.100 Docker-ce、Consul、Consul-template
服務(wù)器:192.168.37.107 Docker-ce、registrator
template模板(更新配置文件)
registrator(自動(dòng)發(fā)現(xiàn)+注冊(cè)到consul-server端)
后端每更新出一個(gè)容器,會(huì)向registrator進(jìn)行注冊(cè),控制consul完成更新操作,consul會(huì)觸發(fā)consultemplate模板進(jìn)行熱更新(reload)
核心機(jī)制: consul :自動(dòng)發(fā)現(xiàn)、自動(dòng)更新,為容器提供服務(wù)(添加、刪除、生命周期)—------consul服務(wù)器

創(chuàng)建consul目錄

[root@localhost ~]# hostnamectl set-hostname consul
[root@localhost ~]# su
[root@consul ~]# mkdir /root/consul

將consul壓縮包壓縮并放到/use/bin下

[root@consul ~]# cd consul/
[root@consul ~/consul]# ls
consul_0.9.2_linux_amd64.zip
[root@consul ~/consul]# unzip consul_0.9.2_linux_amd64.zip
Archive:  consul_0.9.2_linux_amd64.zip
  inflating: consul
[root@consul ~/consul]# ls
consul  consul_0.9.2_linux_amd64.zip
[root@consul ~/consul]# mv consul /usr/bin/

配置consul的模式 

onsul agent \
-server \                 server模式
-bootstrap              前端框架
-ui \                可被訪問的web界面
-data-dir=/var/lib/consul-data \
-bind=192.168.37.100 \
-client=0.0.0.0 \                       registrator(應(yīng)用服務(wù)器-docker-tomcat/apache)
-node=consul-server01 &> /var/ log / consul.log & 

[root@consul ~/consul]# consul agent \
> -server \
> -bootstrap \
> -ui \
> -data-dir=/var/lib/consul-data \
> -bind=192.168.37.100 \
> -client=0.0.0.0 \
> -node=consul-server01 &> /var/log/consul.log &
[1] 24144
[root@consul ~/consul]# consul members
Node             Address              Status  Type    Build  Protocol  DC
consul-server01  192.168.37.100:8301  alive   server  0.9.2  2         dc1

此時(shí)我們看群集信息

[root@consul ~/consul]# consul members
Node             Address              Status  Type    Build  Protocol  DC
consul-server01  192.168.37.100:8301  alive   server  0.9.2  2         dc1

查看詳細(xì)信息,過濾出leader

[root@consul ~/consul]# consul info | grep leader
        leader = true
        leader_addr = 192.168.37.100:8300

查看consul界面。使用8500端口,8300是通信端口

容器服務(wù)自動(dòng)加入consul集群

安裝Gliderlabs/Registrator Gliderlabs/Registrator

可檢查容器運(yùn)行狀態(tài)自動(dòng)注冊(cè),還可注冊(cè)docker容器的服務(wù)信息到服務(wù)配置中心(consul 8300 -----》8500展示)。目前支持Consul、Etcd和skyDNS2。

在192.168.37.107執(zhí)行以下操作

[root@server ~]# docker run -d \
> --name=registrator \
> --net=host \
> -v /var/run/docker.sock:/tmp/docker.sock \
> --restart=always \
> gliderlabs/registrator:latest \
> -ip=192.168.37.107 \
> consul://192.168.37.100:8500
 
###下面的是加載
Unable to find image 'gliderlabs/registrator:latest' locally
latest: Pulling from gliderlabs/registrator
Image docker.io/gliderlabs/registrator:latest uses outdated schema1 manifest format. Please upgrade to a sc        hema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/depr        ecated-schema-v1/
c87f684ee1c2: Pull complete
a0559c0b3676: Pull complete
a28552c49839: Pull complete
Digest: sha256:6e708681dd52e28f4f39d048ac75376c9a762c44b3d75b2824173f8364e52c10
Status: Downloaded newer image for gliderlabs/registrator:latest
2536df1b1fbb77dcbf5d2e09295f222496ecc63f00a49020ce6976decd52a439

查看容器

[root@server ~]# docker ps -a
CONTAINER ID   IMAGE                           COMMAND                  CREATED          STATUS          PORTS     NAMES
2536df1b1fbb   gliderlabs/registrator:latest   "/bin/registrator -i…"   51 seconds ago   Up 50 seconds             registrator

測(cè)試服務(wù)發(fā)現(xiàn)功能是否正常

安裝兩個(gè)nginx和2個(gè)apache

docker run -itd -p:83:80 --name test-01 -h test01 nginx
docker run -itd -p:84:80 --name test-02 -h testo2 nginx
docker run -itd -p:88:80 --name test-03 -h test03 httpd
docker run -itd -p:89:80 --name test-04 -h test04 httpd

此時(shí)去網(wǎng)頁查看

 安裝consul-template

Consul-Template 是一個(gè)守護(hù)進(jìn)程,用于實(shí)時(shí)查詢consul集群信息,并更新文件系統(tǒng)上任意數(shù)量的指定模板,生成配置文件。更新完成以后,可以選擇運(yùn)行shell命令執(zhí)行更新操作,重新加載Nginx。Consul-Template可以查詢consul中的服務(wù)目錄、Key、 Key-values 等。

這種強(qiáng)大的抽象功能和查詢語言模板可以使Consul-Template 特別適合動(dòng)態(tài)的創(chuàng)建配置文件。例如:創(chuàng)建 Apache/Nginx (nginx upstream) Proxy Balancers、Haproxy Backends

準(zhǔn)備template nginx模板文件

--------------------------------------------------在consul上操作----------------------------------------------------

[root@consul ~/consul]# vim nginx.ctmp1
upstream http_backend {
     {{range service "nginx"}}
       server {{.Address}}:{{.Port}};
        {{end}}
}
server {
    listen 83;
    server_name localhost 192.168.37.100;
    access_log /var/log/nginx/xiao.cn-access.log;
    index index.html index.php;
     location / {
        proxy_set_header HOST $host;
        proxy_set_header x-Real-IP $remote_addr;
        proxy_set_header client-IP $remote_addr ;
        proxy_set_header x-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://http_backend;
     }

 安裝nginx

####安裝所需軟件包
[root@server ~]# yum install gcc pcre-devel zlib-devel -y
###解壓nginx軟件包
[root@server ~]# tar zxf nginx-1.12.0.tar.gz
###執(zhí)行
[root@server /opt/nginx-1.12.0]# ./configure --prefix=/usr/local/nginx
##編譯
[root@server /opt/nginx-1.12.0]# make && make install

修改配置文件,讓其識(shí)別.conf文件結(jié)尾的文件

 創(chuàng)建vhost目錄

[root@server /usr/local/nginx/conf]# mkdir vhost

創(chuàng)建nginx日志目錄

[root@server /usr/local/nginx/conf/vhost]# mkdir /var/log/nginx.log

啟動(dòng)nginx

[root@server /usr/local/sbin]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@server /usr/local/sbin]# nginx

查看是否啟動(dòng)

[root@server /usr/local/sbin]# netstat -natp |grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      54739/nginx: master

配置并啟動(dòng)template

[root@consul ~/consul]# unzip consul-template_0.19.3_linux_amd64.zip
Archive:  consul-template_0.19.3_linux_amd64.zip
  inflating: consul-template
[root@consul ~/consul]# ls
consul_0.9.2_linux_amd64.zip  consul-template  consul-template_0.19.3_linux_amd64.zip  nginx.ctmp1
[root@consul ~/consul]# mv consul-template /usr/bin

 ##關(guān)聯(lián)nginx虛擬目錄中的子配置文件操作

[root@consul ~/consul]# consul-template -consul-addr 192.168.37.100:8500 \
> -template "/root/consul/nginx.ctmp1:/usr/local/nginx/conf/vhost/xiao.conf:/usr/local/nginx/sbin/nginx -s reload" \
> --log-level=info

查看生成配置文件 

是都可以訪問。 

到此這篇關(guān)于Docker容器部署consul的詳細(xì)步驟的文章就介紹到這了,更多相關(guān)Docker consul 部署內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論