In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article shares the use of Compose orchestration tools and consul tools in the Docker container, as well as the configuration of the consul server. I hope you can get something from this article.
Docker compose configuration Common Field description build dockerfile context specify Dockerfile file name build image context path image specify image command execute command override default command container name specify container name, because container name is unique, if you specify custom name, you cannot scaledeploy specify deployment and running service related configuration, you can only use environment to add environment variable networks to network ports to expose container port in Swarm mode, which is the same as-p However, the port cannot be lower than the 60volumes mount host path or the command volume restart restart policy Default no,always, no-failure Unless-stopedhostname container hostname docker compose common command field description build rebuild service ps list container up create and start container exec execute command scale specify a service container startup quantity top display container process logs view container output down delete container, network, The data volume and mirror stop/start/restart stop / start / restart service compose command explains the basic use of the format docker-compose [options] [COMMAND] [ARGS...] docker-compose option-- verbose outputs more debugging information-- version print version and exit-f -- file FILE uses a specific compose template file. The default is docker-compose.yml-p,--project-name NAME to specify the project name. Directory name 1 is used by default. Install docker container and compose orchestration tool [root@localhost ~] # yum install-y\ > yum-utils\ # # set Source tool > device-mapper-persistent-data\ # # Mapping tool > lvm2 # # Mapping tool [root@localhost ~] # yum-config-manager-- add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo## loads Ali Cloud Image Source [root@localhost ~] # Yum install docker-ce-y # # install docker container [root@localhost ~] # systemctl stop firewalld.service # # close firewall [root@localhost ~] # setenforce 0 [root@localhost ~] # systemctl start docker # # Open docker container [root@localhost ~] # systemctl enable docker # # Boot self-start [root@localhost ~] # ps aux | grep docker # # check whether the docker process is enabled [root@localhost ~] # tee / etc/docker/daemon.json "registry-mirrors": ["https://3a8s9zx5.mirror.aliyuncs.com"]>} > EOF {" registry-mirrors ": [" https://3a8s9zx5.mirror.aliyuncs.com"]}[root@localhost ~] # systemctl daemon-reload # # reload daemon [root@localhost ~] # systemctl restart docker # # restart the docker service [root@localhost ~] # mount.cifs / / 192.168.100.100/LNMP-C7 / mnt/ Password for root@//192.168.100.100/LNMP-C7: [root@localhost ~] # cd / mnt/docker/ [root@localhost docker] # cp-p docker-compose / usr/bin/ # # copy docker-compose to / usr/bin/ directory [root@localhost docker] # docker-compose-v # # View version information docker-compose version 1.21.1 Build 5a3f1a32 、 Create Nginx orchestration instance [root@localhost docker] # cd ~ [root@localhost ~] # mkdir compose-nginx # # create working directory [root@localhost ~] # cd compose-nginx/ [root@localhost compose-nginx] # mkdir nginx # # create Nginx directory [root@localhost compose-nginx] # cd nginx/ [root@localhost nginx] # vim run.sh # # Edit startup script #! / bin/bash/usr/local/nginx/sbin/nginx # # launch Move the Nginx service [root@localhost nginx] # mkdir / abc [root@localhost nginx] # mount.cifs / / 192.168.100.3/LNMP-C7 / abc/Password for root@//192.168.100.3/LNMP-C7: [root@localhost nginx] # cp / abc/nginx-1.12.2.tar.gz. / # # copy the Nginx package to the current directory [root@localhost nginx] # vim Dockerfile # # write the container file FROM Centos:7RUN yum-y updateRUN yum-y install pcre-devel zlib-devel gcc gcc-c++ makeRUN useradd-M-s / sbin/nologin nginxADD nginx-1.12.2.tar.gz / usr/local/srcWORKDIR / usr/local/srcWORKDIR nginx-1.12.2RUN. / configure\-prefix=/usr/local/nginx\-user=nginx\-group=nginx\-with-http_stub_status_module & & make & & make installENV PATH / usr/local/nginx/sbin:$PATHEXPOSE 80EXPOSE 443RUN echo "daemon off "> > / usr/local/nginx/conf/nginx.confADD run.sh / run.shRUN chmod 755 / run.shCMD [" / run.sh "] [root@localhost nginx] # cd.. / [root@localhost compose-nginx] # vim docker-compose.yml # # create compose template script version:'3' # # version services: # # Service nginx: hostname: nginx # # container hostname build: Context:. / nginx # # create the file path of the container dockerfile: Dockerfile ports:-1216 dockerfile 80 # # Mapping port-1217 dockerfile 443 networks:-abc # # Network name volumes: -. / wwwroot:/usr/local/nginx/html # # data volume association Host site directory networks: # # declare network abc: [root@localhost compose-nginx] # docker-compose-f docker-compose.yml up-DVS # execute compose script on -d daemon [root@localhost compose-nginx] # cd wwwroot/ [root@localhost wwwroot] # vim index.htmlthis is testplate editing! # # Editing the homepage content [root@localhost wwwroot] # yum install tree-y [root@localhost wwwroot] # tree ~ # # View the entire required content structure / root ├── anaconda-ks.cfg ├── compose-nginx │ ├── docker-compose.yml # # orchestration template │ ├── nginx │ │ ├── Dockerfile # # Container script │ │ ├── nginx-1.12.2.tar.gz # # installation package │ │ └── run.sh # # start service script │ └── wwwroot │ └── index.html # # website homepage 3, View a web page with a browser
Consul Overview consul is an open source tool for implementing service discovery and configuration consul features in distributed systems: (1) consul supports health check and allows storage key-value pairs (2) consistency protocol uses Raft algorithm to ensure high availability of services. (3) member management and message broadcasting use GOSSIP protocol, support ACL access control for easy deployment Work seamlessly with lightweight containers such as docker to build consul services consul and agentconsul agent are deployed and run on every node that provides services. There are two operation modes: server,clientserver and client knowledge consul cluster level distinction, independent architecture topology diagram of application services built on top of cluster
Experimental environment consul server 192.168.13.128 Docker-ce, Compose 3, Consul, Consul-templateclient client node 192.168.13.129 Docker-ce, registrator1, Configure consul server [root@consul ~] # mkdir consul [root@consul ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / mnt/Password for root@//192.168.100.3/LNMP-C7: [root@consul ~] # cd / mnt/docker/ [root@consul docker] # cp consul_0.9.2_linux_amd64.zip / root/consul/ [root@consul docker] # cd / root/consul/ [root@consul consul] # unzip consul_0.9.2_linux_amd64.zip # # decompress consulArchive: consul_0.9.2_linux_amd64.zip inflating: consul [root@consul consul] # mv consul/ usr/bin/ # # easy for the system to identify [root@consul consul] # consul agent\ # Agent >-server\ # # provide server >-bootstrap\ >-ui\ # # web access interface >-data-dir=/var/lib/consul-data\ # # data storage directory >-bind=192.168.13.128\ # # Local address >-client=0.0.0.0\ # # all nodes >-node=consul-server01 & > / var/log/consul.log & # # specify the local node name [root@consul consul] # consul members # # View cluster information Node Address Status Type Build Protocol DCconsul-server01 192.168.13.128 Address Status Type Build Protocol DCconsul-server01 8301 alive server 0.9.2 dc1 [root@consul consul] # consul info | grep leader # # View leader leader = true leader_addr = 192.168.13.128VR 8300 [root@consul consul] # systemctl stop firewalld.service # # turn off the firewall [root@consul consul] # setenforce 0firewall # pass httpd Api gets cluster information [root@localhost consul] # curl 127.0.0.1:8500/v1/status/peers # # View all registered members of cluster server [root@localhost consul] # curl 127.0.0.1:8500/v1/status/leaders # # Raf leader [root@localhost consul] # curl 127.0.0.1:8500/v1/catalog/services # # Service [root@localhost consul] # curl 127.0.0.1:8500/v1/catalog/nodes # # Cluster Node details [root@localhost consul] # curl 127.0.0.1:8500/v1/catalog/nginx # # View nginx service information 2, Configure client node server [root@client ~] # docker run-d\ >-- name=registrator\ # # install registrator auto-registration function >-- net=host\ # # specify network >-v / var/run/docker.sock:/tmp/docker.sock\ # # specify data volume >-- restart=always\ > gliderlabs/registrator:latest\ # # Image >-ip=192.168.13.129\ # # Local address > consul:/ / 192.168.13.128 consul server address 3, Test whether the function is normal on the node server [root@client ~] # docker run-itd-p 83:80-- name test-01-h test01 nginx [root@client ~] # docker run-itd-p 84:80-- name test-02-h test02 nginx [root@client ~] # docker run-itd-p 88:80-- name test-03-h test03 httpd [root@client ~] # docker run-itd-p 89:80-name test-04-h test04 Httpd [root@client ~] # systemctl stop firewalld.service # # close the firewall [root@client ~] # setenforce 04, Verify that http and Nginx services are registered with consul
Overview of consul-template
It is the application of automatic replacement profile based on Consul.
You can query the service catalogs in Consul: Key, Key-values, etc.
Especially suitable for dynamic creation of configuration files
Is a daemon for querying consul cluster information in real time
1. Configure the template file [root@consul consul] # vim / root/consul/nginx.ctmpl upstream http_backend on the consul server {# declare the backend server pool {{range service "nginx"}} server {{.address}}: {{.Port}}; {{end} server {listen 1216; # # proxy port server_name localhost 192.168.13.128 # # Local address access_log / var/log/nginx/kgc.cn-access.log; index index.html index.php; location / {proxy_set_header HOST $host; # # header information proxy_set_header X-Real-IP $remote_addr; proxy_set_header Client-IP $remote_addr Proxy_set_header X-Fprwarded-For $proxy_add_x_forwarded_for; proxy_pass http://http_backend; # # Redirect backend CVM Pool} 2. Install and configure Nginx [root@consul consul] # cd / mnt/ [root@consul mnt] # tar zxvf nginx-1.12.2.tar.gz-C / opt/ # # extract Nginx [root@consul mnt] # cd / opt/nginx-1.12.2 [root@consul nginx-1.12.2] # yum install gcc gcc-c++ pcre-devel zlib-devel-y # # installation component [root@consul nginx-1.12.2] # on the consul server. / configure-- prefix=/usr/local/nginx # # configure [root@consul nginx-1.12.2] # make & & make install [root@consul nginx-1.12.2] # vim / usr/local/nginx/conf/nginx.conf # # modify the Nginx configuration file 17 http {18 include mime.types 19 include vhost/*.conf # # specify virtual host directory [root@consul nginx-1.12.2] # mkdir / usr/local/nginx/conf/vhost # # create virtual host directory [root@consul nginx-1.12.2] # mkdir / var/log/nginx # # create log file directory [root@consul nginx-1.12.2] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # # create Soft connection [root@consul nginx-1.12.2] # nginx # # enable the Nginx service [root@consul nginx-1.12.2] # netstat-natp | grep nginx3, Configure and start templeta [root @ consul nginx-1.12.2] # cd / mnt/docker/ [root@consul docker] # cp consul-template_0.19.3_linux_amd64.zip / root/ [root@consul docker] # cd / root/ [root@consul ~] # unzip consul-template_0.19.3_linux_amd64.zip # # install templetaArchive: consul-template_0.19.3_linux_amd64.zip inflating: consul-template on the consul server [root@consul ~] # mv consul-template / usr/bin [root@consul ~] # consul-template-consul-addr 192.168.13.128 root@consul 8500\ # # specify consul local address >-template "/ root/consul/nginx.ctmpl:/usr/local/nginx/conf/vhost/kgc.conf:/usr/local/nginx/sbin/nginx-s reload"\ # # specify the path to template >-log-level=info # # log level [root @ consul ~] # cd / usr/local/nginx/conf/vhost/ [root@consul vhost] # lskgc.conf # # automatically generate configuration file template upstream http_backend {server 192.168.13.129VLAR 83 # # automatically generate backend CCS address and port number server 192.168.13.129 server 84;} server {listen 1216; server_name localhost 192.168.13.128; access_log / var/log/nginx/kgc.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-Fprwarded-For $proxy_add_x_forwarded_for; proxy_pass http://http_backend;}} View with a browser
You can also view the visiting address 128on the back-end node server through docker logs-f test-01.
4. Create a nginx container node on the client side to detect service discovery and configuration updates, and do not turn off the firewall [root@localhost ~] # docker run-itd-p name test-05-h test05 nginx## continue browser access 128 server [root@client ~] # docker logs-f test-05192.168.13.128-- [09/Jan/2020:11:05:39 + 0000] # # polling access, or 128 server access node Load balancing is realized.
These are the details of Docker's use of Compose tools and configuration of consul server. Have you learned anything after reading it? If you want to know more about it, you are welcome to follow the industry information!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.