In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Environmental preparation:
Consul: a highly available, distributed service discovery tool
Master host-docker01:172.16.1.30
Node01 host-docker02:172.16.1.31
Node02 host-docker03:172.16.1.32
Note: because it is a test environment, temporarily turn off the firewall and disable selinux. If it is a server published on a public network, you cannot turn off the firewall. You can set iptables rules.
Project actions:
(1) deploy consul on docker01:
Download or upload the consul_1.5.1_linux_amd64 package:
[root@sqm-docker01 ~] # unzip consul_1.5.1_linux_amd64.zip # use the unzip tool to extract [root@sqm-docker01 ~] # mv consul / usr/local/bin/ [root@sqm-docker01 ~] # chmod + x / usr/local/bin/consul [root@sqm-docker01 ~] # consul agent-server-bootstrap-ui-data-dir=/var/lib/consul-data\ >-bind=172.16.1.30\ # docker01 The ip address of the machine >-client=0.0.0.0\ >-node=master
Parameter explanation:
-server: add a service
-bootstrap: it is generally used when server is a single node, and it is elected as leader since.
-data-dir: specify the directory where the data is stored
-ui: open the internal web interface
-bind: specify the ip to enable the service
-client: specify the client of the service
-node: the name used for communication within the cluster. The default is the hostname.
# keep the consul service running at the background:
[root@sqm-docker01] # nohup consul agent-server-bootstrap-ui-data-dir=/var/lib/consul-data-bind=172.16.1.30-client=0.0.0.0-node=master &
After running in the background, a file is generated under the current directory, and all the cluster information generated will be saved in this file:
# # check whether the service port is running:
8300: cluster node (published to the public)
8301: access within the cluster
8302: communication between data centers
8500: http--UI
8600: dns
# # View consul information:
[root@sqm-docker01 ~] # consul info
Description: consul information is mostly a number of algorithms, these algorithms to ensure data synchronization, and add-bootstrap self-elected to leader, but also through these algorithms to achieve.
# # View the internal information of the cluster:
[root@sqm-docker01 ~] # consul members
Log in to visit the web interface: http://172.16.1.30:8500
(2) Operation on docker02:
Deploy the consul service:
Download the progrium/consul image:
[root@sqm-docker02 ~] # docker pull myprogrium-consul
# # create a consul container and join the consul cluster:
[root@sqm-docker02] # docker run-d-- name consul-p 8301 8301:8301/udp-p 8500 8301:8301/udp-p 8500 8301:8301/udp-p 8600 8600:8600/udp-- restart=always progrium/consul-join 172.16.1.30-advertise 172.16.1.31-client 0.0.0.0-node=node01
Explanation:
-join: join the docker01 cluster, so specify the host address of docker01
-advertise: the local (docker02) address is advertised
-client: indicates that the host accesses the node
-node: custom node name is node01
Ensure that the container is functioning properly:
Check the page to see if the node has joined:
(3) operate on docker03:
Download the same progrium/consul image:
[root@sqm-docker02 ~] # docker pull myprogrium-consul
Run the container and join the cluster:
[root@sqm-docker03] # docker run-d-- name consul-p 8301 8301:8301/udp-p 8500 8301:8301/udp-p 8500 8301:8301/udp-p 8600 8600:8600/udp-- restart=always progrium/consul-join 172.16.1.30-advertise 172.16.1.32-client 0.0.0.0-node=node02
# Note that what needs to be advertised is its own ip address, and the node name is node02
After joining the cluster, view the cluster information on docker01:
[root@sqm-docker01 ~] # consul members
Browse the web interface to view:
Make sure that node1 and node2 have been added to the cluster
(4) install consul-template on docker01:
The package can be downloaded from github. Download path (customizable version): https://releases.hashicorp.com/consul-template/
Decompress it after download and give it the right to execute:
[root@sqm-docker01 ~] # unzip consul-template_0.19.5_linux_amd64.zip Archive: consul-template_0.19.5_linux_amd64.zip inflating: consul-template [root@sqm-docker01 ~] # mv consul-template / usr/local/bin/ [root@sqm-docker01 ~] # chmod + x / usr/local/bin/consul-template
Install it for the time being, and don't do anything else.
(5) deploy registrator:
It is mainly used to collect information about the container running service and send it to consul.
Automatically discover the services provided by docker container and register the services in the back-end services registry (data center).
Common data centers are: consul,etcd,zookeeper, related technologies can find relevant technical documents.
Deploy registrator on docker02 and docker03:
Note: # both should be deployed
Docker02:
I imported a locally downloaded image (pulled in pull):
[root@sqm-docker02] # docker load-- input myregistrator.tar
Run a registrator container:
[root@sqm-docker02] # docker run-d-name registrator-v / var/run/docker.sock:/tmp/docker.sock-- restart=always gliderlabs/registrator consul://172.16.1.31:8500
The function of the above command is to display the information collected from the container to port 8500 of this machine.
Visit the web web page to see if information about the container has been collected:
Url: http://172.16.1.30:8500/
Now run a ngnx service on docker02 to test whether it can be found:
[root@sqm-docker02] # docker run-d-P-- name test nginx
Docker03:
Do the same in docker02 to see if the service can be discovered:
Download the image and create a container:
[root@sqm-docker03] # docker run-d-name registrator-v / var/run/docker.sock:/tmp/docker.sock-- restart=always gliderlabs/registrator consul://172.16.1.32:8500
Run the nginx service:
[root@sqm-docker03] # docker run-d-- name test2-P nginx
Ensure that the container is functioning properly:
View the web web page:
Ensure that nginx container information on node2 can also be collected.
(6) deploy nginx on docker01 and provide reverse proxy:
1) install nginx:
Installation dependencies:
[root@sqm-docker01 ~] # yum-y install gcc pcre pcre-devel openssl openssl-devel zlib zlib-devel
Create a nginx user
[root@sqm-docker01] # useradd-M-s / usr/sbin/nologin nginx
Compile and install:
[root@sqm-docker01] # tar zxf nginx-1.14.0.tar.gz-C / usr/src/ [root@sqm-docker01 ~] # cd / usr/src/nginx-1.14.0/ [root@sqm-docker01 nginx-1.14.0] #. / configure-- prefix=/usr/local/nginx-- user=nginx-- group=nginx-- with-http_stub_status_module-- with-http_realip_module-- with-pcre-- with-http_ssl_module & make & & make install
Soft links:
[root@sqm-docker01] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/
Start nginx:
[root@sqm-docker01 ~] # nginx
2) now start deploying the consul-template plug-in that you just installed
The function of consul-template: write the collected information (the information collected by registrator into the container) into the template template, and finally into the configuration file of nginx, through which the automation is realized.
# # Writing consul-template web pages:
[root@sqm-docker01 ~] # cd / usr/local/nginx/ [root@sqm-docker01 nginx] # mkdir consul # create a directory under the nginx directory to store template pages [root@sqm-docker01 nginx] # cd consul/ [root@sqm-docker01 consul] # vim nginx.ctmpl
The content is as follows (implemented in go language):
Upstream http_backend {{range service "nginx"}} server {{.Address}}: {{end}} server {listen 8000; # listener port can be customized as long as it does not conflict with its own port 80 to server_name localhost; location / {proxy_pass Port}}
# # modify nginx configuration file:
[root@sqm-docker01 consul] # vim / usr/local/nginx/conf/nginx.conf
/ / generate a .conf file based on the template just now:
[root@sqm-docker01 consul] # consul-template-consul-addr 172.16.1.30 template-template "/ usr/local/nginx/consul/nginx.ctmpl:/usr/local/nginx/consul/vhost.conf:/usr/local/sbin/nginx-s reload"
Note: after executing the command, enter will be stuck in the terminal, so next we open another terminal to check.
You can also set it to run in the background: (plus nohup and & parameters):
[root@sqm-docker01 consul] # nohup consul-template-consul-addr 172.16.1.30 consul-addr 8500-template "/ usr/local/nginx/consul/nginx.ctmpl:/usr/local/nginx/consul/vhost.conf:/usr/local/sbin/nginx-s reload" &
# # you can see the address and port number of node01 and node02 in the vhost file, indicating that the nginx agent is successful.
(7) realize automatic service discovery:
To verify the implementation of service discovery, create containers on docker02 and docker03: (run based on nginx services)
The operation commands are as follows:
Docker02:
Mkdir htmlecho docker02_web01 > html/index.confdocker run-itd-- name web01-v / root/html:/usr/share/nginx/html-P nginx
To see it more visually, we run the second nginx container:
Docker run-itd-- name web02-P nginx:latestdocker exec-it web02 / bin/bashecho docker02_web02 > / usr/share/nginx/html/index.html
Docker03: (also create two containers):
Docker run-itd-- name web03-P nginx:latestdocker exec-it web03 / bin/bashecho docker03-web01 > / usr/share/nginx/html/index.htmldocker run-itd-- name web04-P nginx:latestdocker exec-it web04 / bin/bashecho docker03-web02 > / usr/share/nginx/html/index.htm
Finally, verify the automatically discovered nginx page:
Access the address of the proxy nginx server following the custom access port 8000
URL: http://172.16.1.30:8000/
The first page visited is the nginx page of the proxy server itself:
The second time I visited the first nginx page on docker02:
The third time I visited the second nginx page on docker02:
The nginx1 page on docker03:
The nignx2 page on docker03:
At this point, the cluster is deployed on the Docker to achieve an automatic discovery of the service, which has been built and tested.
-this is the end of this article. 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.