In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "Docker Stack how to deploy web cluster", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Docker Stack how to deploy web cluster" this article.
Environment
I used two centos7 virtual machines to do this tutorial, and their ip is
Master server: 192.168.0.105 / / is also a private warehouse server server 2: 192.168.0.49
All the code in this post is github address: https://github.com/lpxxn/godockerswarm
Set up Docker Swarm
I use 192.168.0.105 as the main server and open swarm on it.
Docker swarm init
After executing the command, the command to join the swarm will be given.
Execute the command to join swarm on 192.168.0.49
Docker swarm join-- token SWMTKN-1-425vswwmb8o34uhnmo58w0k4rfzs5okjtye7mokpqps1vl9ymq-0p6pr2gua7l8a6udb67tfndoo 192.168.0.105pur2377
In this way, we have built the swarm, and the two hosts have now established a relationship.
Web service
The web service writes a simple interface in go language and returns the name of the host: this makes it easy for us to see if there is a load.
Package mainimport ("fmt"log"net/http"os") func main () {http.HandleFunc ("/ hi", func (w http.ResponseWriter, r * http.Request) {hostName, _: = os.Hostname () fmt.Fprintf (w, "HostName:% s", hostName)}) log.Fatal (http.ListenAndServe (": 8000", nil))}
Docker file
Take a look at the dockerfile file:
Execution means to copy the code to the appropriate folder, expose the port, and run the program based on the golang situation. It's easy.
FROM golang# Copy the current directory contents into the containerCOPY. / go/src/github.com/lpxxn/godockerswarm/WORKDIR / go/src/github.com/lpxxn/godockerswarm/RUN go buildEXPOSE 8000CMD [". / godockerswarm"]
Take a look at the folder where the dockerfile file is located
Execute the docker build command in this directory:
Docker build. -t goweb:1.0
You can run the newly generated image.
Docker run-p 8100 docker run 8000 7a7e3
Submit the image to the private warehouse
I have more to say here about how to build a private warehouse server. You can take a look at my previous post.
Address: https://www.jb51.net/article/156168.htm
Because the machine on the cluster automatically takes the image from the repository and then runs the program, we need to push the image generated above to our private repository. I built it myself.
Rename using tag
Docker tag goweb:1.0 lpxxn.com:5000/goweb:1.0
Push
Docker push lpxxn.com:5000/goweb:1.0
Docker-compose file
Next, create the docker-compose.yml file
Image is the image we created above. Running five applications, docker will do its own load, port mapping 8111, automatically restart the service if it fails, and create its own network, which is very useful when there are multiple server services.
For the specific parameters, you can take a look at the official tutorial:
Https://docs.docker.com/compose/compose-file/
Version: "3" services: web: image: lpxxn.com:5000/goweb:1.0 deploy: replicas: 5 resources: limits: cpus: "0.1" memory: 50m restart_policy: condition: on-failure ports:-"8111 gowebnetnetworks 8000" networks:-gowebnetnetworks: gowebnet:
Deploy the application
To the final stage, the subordinate is as simple as executing the deploy command.
Docker stack deploy-c docker-compose.yml mygoweb
View started services
Docker service ps mygoweb
Test service
Look at these returned hostnames: different. Docker did the load for us.
These are all the contents of the article "how Docker Stack deploys web clusters". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.