Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of Docker Swarm cluster creation and visual management?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "what is the method of Docker Swarm cluster creation and visual management". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Node information:

Manager:192.168.220.194

Worker1:192.168.220.173

Worker2:192.168.220.197

Technology stack:

Docker 1.12

Shipyard

Swarm

Etcd

SwarmOps

Rethinkdb

Docker-proxy

Required resource package:

Quick start:

1. Install docker 1.12 (all nodes, minimum kernel limit centos7)

Set up the docker1.12 yum source:

Cat > / etc/yum.repos.d/docker.repo & 1

}

Get_ip () {

If [- z "$SHIPYARD_IP"]; then

SHIPYARD_IP= `docker run-- rm-- net=host alpine ip route get 8.8.8.8 | awk'{print $7;}'`

Fi

}

Start_discovery () {

Get_ip

ID=$ (docker run\

-ti\

-d\

-p 4001Disc 4001\

-p 7001purl 7001\

-- restart=always\

-- name $PREFIX-discovery\

Microbox/etcd:latest-addr $SHIPYARD_IP:$DISCOVERY_PORT-peer-addr $SHIPYARD_IP:$DISCOVERY_PEER_PORT)

}

Remove_discovery () {

Docker rm-fv $PREFIX-discovery > / dev/null 2 > & 1

}

Start_rethinkdb () {

ID=$ (docker run\

-ti\

-d\

-- restart=always\

-- name $PREFIX-rethinkdb\

Rethinkdb)

}

Remove_rethinkdb () {

Docker rm-fv $PREFIX-rethinkdb > / dev/null 2 > & 1

}

Start_proxy () {

TLS_OPTS= ""

If [$ENABLE_TLS = 1]; then

TLS_OPTS= "- e SSL_CA=$SSL_CA_CERT-e SSL_CERT=$SSL_CERT-e SSL_KEY=$SSL_KEY-e SSL_SKIP_VERIFY=1"

Fi

# Note: we add SSL_SKIP_VERIFY=1 to skip verification of the client

# certificate in the proxy image. This will pass it to swarm that

# does verify. This helps with performance and avoids certificate issues

# when running through the proxy. Ultimately if the cert is invalid

# swarm will fail to return.

ID=$ (docker run\

-ti\

-d\

-p $PROXY_PORT:$PROXY_PORT\

-- hostname=$HOSTNAME\

-- restart=always\

-- name $PREFIX-proxy\

-v / var/run/docker.sock:/var/run/docker.sock\

-e PORT=$PROXY_PORT\

-- volumes-from=$PREFIX-certs $TLS_OPTS\

Shipyard/docker-proxy:latest)

}

Remove_proxy () {

Docker rm-fv $PREFIX-proxy > / dev/null 2 > & 1

}

Start_swarm_manager () {

Get_ip

TLS_OPTS= ""

If [$ENABLE_TLS = 1]; then

TLS_OPTS= "- tlsverify-tlscacert=$SSL_CA_CERT-tlscert=$SSL_CERT-tlskey=$SSL_KEY"

Fi

EXTRA_RUN_OPTS= ""

If [- z "$DISCOVERY"]; then

DISCOVERY= "$DISCOVERY_BACKEND://discovery:$DISCOVERY_PORT"

EXTRA_RUN_OPTS= "--link $PREFIX-discovery:discovery"

Fi

ID=$ (docker run\

-ti\

-d\

-- restart=always\

-- name $PREFIX-swarm-manager\

-- volumes-from=$PREFIX-certs $EXTRA_RUN_OPTS\

Swarm:latest\

M-- replication-- addr $SHIPYARD_IP:$SWARM_PORT-- host tcp://0.0.0.0:$SWARM_PORT $TLS_OPTS $DISCOVERY)

}

Remove_swarm_manager () {

Docker rm- fv $PREFIX-swarm-manager > / dev/null 2 > & 1

}

Start_swarm_agent () {

Get_ip

If [- z "$DISCOVERY"]; then

DISCOVERY= "$DISCOVERY_BACKEND://discovery:$DISCOVERY_PORT"

EXTRA_RUN_OPTS= "--link $PREFIX-discovery:discovery"

Fi

ID=$ (docker run\

-ti\

-d\

-- restart=always\

-name $PREFIX-swarm-agent $EXTRA_RUN_OPTS\

Swarm:latest\

J-- addr $SHIPYARD_IP:$PROXY_PORT $DISCOVERY)

}

Remove_swarm_agent () {

Docker rm- fv $PREFIX-swarm-agent > / dev/null 2 > & 1

}

Start_controller () {

#-v $CERT_PATH:/etc/docker:ro\

TLS_OPTS= ""

If [$ENABLE_TLS = 1]; then

TLS_OPTS= "- tls-ca-cert $SSL_CA_CERT-tls-cert=$SSL_CERT-tls-key=$SSL_KEY-shipyard-tls-ca-cert=$SSL_CA_CERT-shipyard-tls-cert=$SSL_CERT-shipyard-tls-key=$SSL_KEY"

Fi

ID=$ (docker run\

-ti\

-d\

-- restart=always\

-- name $PREFIX-controller\

-- link $PREFIX-rethinkdb:rethinkdb\

-- link $PREFIX-swarm-manager:swarm\

-p $SHIPYARD_PORT:$SHIPYARD_PORT\

-- volumes-from=$PREFIX-certs\

$IMAGE\

-- debug\

Server\

-- listen: $SHIPYARD_PORT\

-d tcp://swarm:$SWARM_PORT $TLS_OPTS $SHIPYARD_ARGS)

}

Wait_for_available () {

Set + e

IP=$1

PORT=$2

Echo Waiting for Shipyard on $IP:$PORT

Docker pull ehazlett/curl > / dev/null 2 > & 1

TLS_OPTS= ""

If [$ENABLE_TLS = 1]; then

TLS_OPTS= "- k"

Fi

Until $(docker run-- rm ehazlett/curl-- output / dev/null-- connect-timeout 1-silent-- head-- fail $TLS_OPTS $SHIPYARD_PROTOCOL://$IP:$PORT/ > / dev/null 2 > & 1); do

Printf'.

Sleep 1

Done

Printf'\ n'

}

Remove_controller () {

Docker rm-fv $PREFIX-controller > / dev/null 2 > & 1

}

If ["$ACTION" = "deploy"]; then

Set-e

Check_certs

Get_ip

Echo "Deploying Shipyard"

Echo "- > Starting Database"

Start_rethinkdb

Echo "- > Starting Discovery"

Start_discovery

Echo "- > Starting Cert Volume"

Start_certs

Echo "- > Starting Proxy"

Start_proxy

Echo "- > Starting Swarm Manager"

Start_swarm_manager

Echo "- > Starting Swarm Agent"

Start_swarm_agent

Echo "- > Starting Controller"

Start_controller

Wait_for_available $SHIPYARD_IP $SHIPYARD_PORT

Echo "Shipyard available at $SHIPYARD_PROTOCOL://$SHIPYARD_IP:$SHIPYARD_PORT"

If [$ENABLE_TLS = 1] & & [!-z "$CERT_FINGERPRINT"]; then

Echo "SSL SHA-256 Fingerprint: $CERT_FINGERPRINT"

Fi

Echo "Username: admin Password: shipyard"

Elif ["$ACTION" = "node"]; then

Set-e

If [- z "$DISCOVERY"]; then

Echo "You must set the DISCOVERY environment variable"

Echo "with the discovery system used with Swarm"

Exit 1

Fi

Check_certs

Echo "Adding Node"

Echo "- > Starting Cert Volume"

Start_certs

Echo "- > Starting Proxy"

Start_proxy

Echo "- > Starting Swarm Manager"

Start_swarm_manager $DISCOVERY

Echo "- > Starting Swarm Agent"

Start_swarm_agent

Echo "Node added to Swarm: $SHIPYARD_IP"

Elif ["$ACTION" = "upgrade"]; then

Set-e

Check_certs

Get_ip

Echo "Upgrading Shipyard"

Echo "- > Pulling $IMAGE"

Docker pull $IMAGE

Echo "- > Upgrading Controller"

Remove_controller

Start_controller

Wait_for_available $SHIPYARD_IP $SHIPYARD_PORT

Echo "Shipyard controller updated"

Elif ["$ACTION" = "remove"]; then

# ignore errors

Set + e

Echo "Removing Shipyard"

Echo "- > Removing Database"

Remove_rethinkdb

Echo "- > Removing Discovery"

Remove_discovery

Echo "- > Removing Cert Volume"

Remove_certs

Echo "- > Removing Proxy"

Remove_proxy

Echo "- > Removing Swarm Agent"

Remove_swarm_agent

Echo "- > Removing Swarm Manager"

Remove_swarm_manager

Echo "- > Removing Controller"

Remove_controller

Echo "Done"

Else

Echo "Unknown action $ACTION"

Exit 1

Fi

-

Load Mirror (manager Node)

Docker load < shipyard.tar.gz

Docker load < shipyard-docker-proxy.tar.gz

Docker load < swarm.tar.gz

Docker load < microbox-etcd.tar.gz

Docker load < rethinkdb.tar.gz

Docker load < alpine.tar.gz

Run the following command:

Bash docker.sh

Load Mirror (worker Node)

Docker load < shipyard-docker-proxy.tar.gz

Docker load < swarm.tar.gz

Docker load < alpine.tar.gz

Run the following command:

Export ACTION=node DISCOVERY=etcd://:4001 & & bash docker.sh

View all node swarm-manager logs:

Docker logs-f shipyard-swarm-manager

If the service is displayed as follows, the service starts successfully:

If the following error occurs:

Solution: (all nodes)

Stop the docker service, delete / etc/docker/key.json, start the docker service

Systemctl stop docker.service (all nodes are executed at the same time, that is, before deleting the key.json file)

Rm-rf / etc/docker/key.json (all nodes do it at the same time, that is, delete the key.json after stopping the docker service)

Systemctl start docker.service (all nodes are executed at the same time, that is, after the key.json file is deleted)

Browser access:

Http://:8080

Node information:

3. Install SwarmOps:

Load the SwarmOps image:

Docker load < swarmops.tar.gz

Start the SwarmOps container:

Docker run-tdi-name swarmops-net=host-restart=always swarmops:0.0.2

Browser access:

Http://:10130

This is the end of the content of "what is the method of Docker Swarm cluster creation and visual management". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report