In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-10-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use docker swarm to achieve clusters, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
(1) go compiles web programs.
Mainly to monitor ip:9090/Source browsing, and record the server host and access times.
Code
Package mainimport ("fmt", "log", "net/http", "runtime", "strconv"os") var i int = 0func sayHello (w http.ResponseWriter, r * http.Request) {/ / func sayHello () {ionization + fmt.Print (I) fmt.Print ("\ n") fmt.Print ("visit!" + "\ n") hostname Er: = os.Hostname () if er = = nil {dates: = "jenkins:" + "Login\ n" + "visit Count:" + strconv.Itoa (I) + "\ nHostname:" + hostname w.Write ([] byte (dates)) defer r.Body.Close ()} else {return}} func main () { Fmt.Print ("/ log.txt"] # can be monitored by tail-f log.txt in the container
Docker build-t ip:5000/swarm:0.0. /
Ubuntu@local:~/SWARM$ docker build-t 192.168.175.139:5000/swarm:0.0. / Sending build context to Docker daemon 6.629MB # Sending build context can be used to stop Step 1 26b542a8286bStep 7: FROM ubuntu:16.04-- > a51debf7e1ebStep 2 a51debf7e1ebStep 7: MAINTAINER ZHB-> Using cache-- > 26b542a8286bStep 3 26b542a8286bStep 7: COPY. / arch /-> Using cache-- > aff0b358480cStep 4 Using cache 7: RUN chmod 777 / arch-- > Using cache- -- > 6e07a223b571Step 5 ENTRYPOINT 7: RUN touch / log.txt-- > Using cache-- > 03be86c93b8aStep 6 Accord 7: EXPOSE 9090-> Using cache-- > fe9c6a7ab542Step 7 Accord 7: ENTRYPOINT ["sh" "- c", ". / arch > > / log.txt"]-- > Using cache-- > 6287178e0005Successfully built 6287178e0005Successfully tagged 192.168.175.139:5000/swarm:0.0
Push Mirror
Docker push ip:5000/swarm:0.0
(4) Master node swarm init
Docker swarm init
Other servers join the cluster
Docker swarm join-token * ip:2377
(5) create service
Docker service create-- replicas 6-- name=swarm-service-- publish 9090 IP:5000/swarm:0.0
Overall progress: 0 out of 6 tasks1/6: preparing [= >] 2 tasks1/6 6: preparing [= >] 3 preparing 6: preparing [= >] 4 preparing 6: preparing [= = >] 6: preparing [= >]
(6) web accesses ip:9090/Source and implements load balancing
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.