In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article takes Docker-compose and Docker-consu as examples to analyze the installation and configuration methods of Docker native orchestration tools. After reading the complete article, I believe you have some understanding of the installation and configuration methods of native orchestration tools.
Docker native choreography tool 1. Docker-compose concept
The default management object of Compose is the project, which manages the life cycle of a set of containers in the project through subcommands.
The Compose project is implemented by Python, and the implementation invokes API provided by the Docker service to manage the container.
Step 1: install the Docker-ce engine
It's relatively simple, instead of repeating it, go directly to the shell script.
#! / bin/bash#Docker engine deployment # install dependency package yum install yum-utils device-mapper-persistent-data lvm2-y # set Ali cloud image source yum-config-manager-- add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# install Docker-ceyum install-y docker-ce# turn off firewall and enhanced security features systemctl stop firewalld.servicesetenforce start Docker and set it to boot Systemctl start docker.servicesystemctl enable docker.service# network optimization echo "net.ipv4.ip_forward=1" > > / etc/sysctl.confsysctl-pservice network restart systemctl restart docker2, Deploy docker-compose# download and install composecurl-L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname-s`-`uname-m`-o / usr/local/bin/docker-compose# to facilitate calling chmod + x / usr/local/bin/docker-compose# to establish compose site mkdir / root/docker_compose3, compose exercise examples
Docker Compose configuration common fields
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 deploy specify deployment and running service related configuration, you can only use environment to add environment variable networks to network ports exposure container port in Swarm mode, which is the same as-p, but the port cannot be lower than 60volumes mount host path or command volume restart restart policy Default no,always, no-failure,unless-stopedhostname container hostname
Docker Compose common commands
Field description build Reconstruction Service ps list Container up create and start Container exec execute commands inside the container scale specify a service container startup quantity top display container process logs view container output log files down delete container, network, data volume and mirror stop/start/restart stop / start / restart service
Collective deployment nginx+Tomcat
# establish the version number of compose file vim / root/docker-compose/docker-compose.yml#compose There are 1, 2, 3version: '3.3 domains # service name services: nginx:# hostname hostname: nginx# the directory needed to establish the image, Dockerfile script name build: context:. / nginx dockerfile: Dockerfile# mapping host port ports:-1216 Dockerfile# 80-1200 nginx dockerfile working group: same cluster one name networks:-test# directory for establishing dataset volumes: -. / wwwroot:/usr/local/nginx/html tomcat: hostname: tomcat build: context:. / tomcat Dockerfile: Dockerfile ports:-888 networks:-testnetworks: test:# needs to create a new image service needs to be placed in the compose work site [root@localhost docker_compose] # lsdocker-compose.yml nginx tomcat# creation container "- f" specifies the compose file docker-compose-f docker-compose.yml up-d II, Docker-consul Cluster + template experiment preparation name role IP address preloading Environment centos7- 1master192.168.142.66Docker-ce, Compose 3, Consul, Consul-templatecentos7-2slave1192.168.142.77Docker-ce, registratorcentos7-minslave2192.168.142.136Docker-ce, registratordocker-consul Cluster experiment steps
Master end
/ / installation consultant [root @ localhost ~] # mkdir consul [root@localhost ~] # cd consul/ [root@localhost consul] # unzip consul_0.9.2_linux_ amd64.zip [root @ localhost consul] # lsconsul consul_0.9.2_linux_amd64.zip
Background start
/ / move files Easy to identify [root@localhost consul] # mv consul / usr/bin/ [root@localhost consul] # consul agent\-server\-bootstrap\-ui\-data-dir=/var/lib/consul-data\-bind=192.168.142.66\-client=0.0.0.0\-node=consul-server01 & > / var/log/consul.log & [root@localhost consul] # jobs [1] + running consul agent-server-bootstrap-ui-data-dir=/var / lib/consul-data-bind=192.168.142.66-client=0.0.0.0-node=consul-server01 & > / var/log/consul.log &
"agent" uses agent proxy function
"- server" provides server function
"- bootstrap" participates in the election of leader
"- ui" provides user interface
Storage location of the "- data-dir" parameter
"- bind" binding address
"- node" defines the node name
Check the cluster
/ / View cluster information [root@localhost consul] # consul membersNode Address Status Type Build Protocol DCconsul-server01 192.168.142.66 alive server 0.9.22 dc1// filter leader information [root@localhost consul] # consul info | grep leader leader = true leader_addr = 192.168.142.66 alive server 8300
Get cluster information through httpd api
Curl 127.0.0.1:8500/v1/status/peers / / View cluster server members
Curl 127.0.0.1:8500/v1/status/leader / / Cluster Raf leader
All services registered with curl 127.0.0.1:8500/v1/catalog/services / /.
Curl 127.0.0.1:8500/v1/catalog/nginx / / View nginx service information
Curl 127.0.0.1:8500/v1/catalog/nodes / / Cluster node details
Make the containers in the node server join automatically
/ / install registrator (registrar) / / this tool can check the running status of the container to register automatically, and can also log out of the service of docker container [root@localhost] # docker run-d\-name=registrator\-- net=host\-v / var/run/docker.sock:/tmp/docker.sock\-- restart=always\ gliderlabs/registrator:latest\-ip=192.168.142.77\ consul://192.168.142.66:8500
Test whether the function is normal
[root@localhost] # docker run-itd-pRV 83V80-- name test-01-h test01 nginx [root@localhost] # docker run-itd-pRV 84RV 80-- name test-02-h test02 nginx [root@localhost] # docker run-itd-pRV 85V80-- name test-03-h test03 httpd [root@localhost] # docker run-itd-pRV 86V80-- name test-04-h test04 httpd
Verify that the cluster is established successfully
Enter http://192.168.142.66:8500 in the browser, click "NODES", and then click "consurl-seerver01" to see the five services (graphical interface)
Set up template to act as agent
Compile and install nginx manually
There's nothing to say. Just pretend. Version: nginx1.12.0
Install consul-template
Template is a daemon, which is used to query consul cluster information in real time and use templates to generate configuration files in real time.
[root@localhost ~] # unzip consul-template_0.19.3_linux_amd64.zip// enable template command [root@localhost ~] # mv consul-template / usr/bin/
Write nginx profile template
[root@localhost consul] # vim nginx.ctmpl / / nginx configuration file template upstream http_backend {/ / Server pool name {{range service "nginx"}} server {{.Address}: {{.Port}}; / / call variables: server node address and port {{end}} server {listen 110; server 192.168.142.66 / / Masterside address access_log / var/log/nginx/kgc.cn-access.log; index index.html index.php; location / {/ / request header information setting proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; / / backend server IP proxy_set_header Client-IP $remote_addr / / client's IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; / / forward jump address proxy_pass http://http_backend; / / request to jump to http_backend server pool}}
Configure
/ / change the nginx configuration file [root@localhost nginx-1.12.0] # vim / usr/local/nginx/conf/nginx.conf// insert the following content include vhost/\ * .conf under line 18 / / add include to facilitate nginx to identify the configuration file generated by the template / / this file is not available at this time Need to create [root@localhost nginx-1.12.0] # cd / usr/local/nginx/conf/ [root@localhost conf] # mkdir vhost/ / create virtual machine directory / / enable template template (enter monitoring mode when enabled) [root@localhost ~] # consul-template-consul-addr 192.168.142.66 virtual machine 8500\-template "/ root/consul/nginx.ctmpl:/usr/local/nginx/conf/vhost/kgc.conf:/ Usr/local/nginx/sbin/nginx-s reload "\-- log-level=info
"- consul-addr" # specify the address of the consular side
"- template" # followed from left to right are: template file path, generated configuration file name, overloaded nginx
"--log-level" # level written to the log
Because template is built on the basis of consul cluster, the nginx container in slave can be directly identified after starting template.
When a new nginx container is added later, it will be automatically added to the configuration file after directly run a new container.
After reading the above, have you mastered the configuration and deployment of Docker-compose and Docker-consul? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.