节点 1:192.168.57.120
节点 2:192.168.57.127
集群操作
创建集群:docker swarm init
[root@centos ~]# docker swarm init
Swarm initialized: current node (sv2g7ljrt9leiw0caet9d9wj5) is now a manager.To add a worker to this swarm, run the following command:docker swarm join --token SWMTKN-1-2k0pyekm18le5xn3s4nm8wee115r89eibropgdj55idb5vtjx7-6s2bwk6xgcoguravw3efdxwv4 192.168.57.127:2377To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
添加worker node,在对应节点执行命令 :docker swarm join --token ...
添加manager node,当前节点执行命令:docker swarm join-token manager,再执行后续操作
******************
添加worker node
192.168.57.120执行如下命令
[root@centos ~]# docker swarm join --token SWMTKN-1-2k0pyekm18le5xn3s4nm8wee115r89eibropgdj55idb5vtjx7-6s2bwk6xgcoguravw3efdxwv4 192.168.57.127:2377
This node joined a swarm as a worker.
节点作为worker node加入集群
查看节点:docker node ls
[root@centos ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
51kgawqwx5hp3ytl55m9g8mcf centos Ready Active 19.03.6-rc2
sv2g7ljrt9leiw0caet9d9wj5 * centos Ready Active Leader 19.03.13-beta2
[
说明:查看节点需要在manager node上执行
manager node查看集群信息:docker info
[root@centos ~]# docker info
Client:Debug Mode: falseServer:Containers: 0Running: 0Paused: 0Stopped: 0Images: 40Server Version: 19.03.13-beta2Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: activeNodeID: sv2g7ljrt9leiw0caet9d9wj5Is Manager: trueClusterID: 4ehmddg5fn49wjz9zi88fi3peManagers: 1Nodes: 2Default Address Pool: 10.0.0.0/8 SubnetSize: 24Data Path Port: 4789Orchestration:Task History Retention Limit: 5Raft:Snapshot Interval: 10000Number of Old Snapshots to Retain: 0Heartbeat Tick: 1Election Tick: 10Dispatcher:Heartbeat Period: 5 secondsCA Configuration:Expiry Duration: 3 monthsForce Rotate: 0Autolock Managers: falseRoot Rotation In Progress: falseNode Address: 192.168.57.127Manager Addresses:192.168.57.127:2377Runtimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429runc version: dc9208a3303feef5b3839f4323d9beb36df0a9ddinit version: fec3683Security Options:seccompProfile: defaultKernel Version: 3.10.0-1127.18.2.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 1.777GiBName: centosID: OW47:PHLP:5MHC:TKKD:REMM:YJJL:5OWX:GJI4:HQPJ:QEY4:MK6Z:IBZDDocker Root Dir: /var/lib/dockerDebug Mode: falseUsername: lihu12344Registry: :provider=genericExperimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors: Restore Enabled: false
managers:1、nodes:2 ==> 集群中1个manager node,共2个节点
node address:192.168.57.127 ==> 当前节点ip地址
manager addresses:192.168.57.120:2377 ==> manager 节点 ip地址
worker node 查看集群信息:docker info
[root@centos ~]# docker info
Client:Debug Mode: falseServer:Containers: 4Running: 0Paused: 0Stopped: 4Images: 39Server Version: 19.03.6-rc2Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: activeNodeID: 51kgawqwx5hp3ytl55m9g8mcfIs Manager: falseNode Address: 192.168.57.120Manager Addresses:192.168.57.127:2377Runtimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: b34a5c8af56e510852c35414db4c1f4fa6172339runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657init version: fec3683Security Options:seccompProfile: defaultKernel Version: 3.10.0-957.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 1.777GiBName: centosID: GJSG:3CFX:XLTR:YOJU:ZOOL:QBES:YWSR:JRFH:TWXR:W5CM:Y2Y5:H2B5Docker Root Dir: /var/lib/dockerDebug Mode: falseUsername: lihu12344Registry: :Experimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors: Restore Enabled: false
is manager:false ==> 当前节点不为manager
node address: 192.168.57.120 ==> 当前节点ip
manager addresses: 192.168.57.127:2377 ==> manager 节点 ip地址
******************
添加 manager node
192.168.57.120 退出集群:docker swarm leave -f
manager node 192.168.57.127 执行命令:docker swarm join-token manager
[root@centos ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:docker swarm join --token SWMTKN-1-2k0pyekm18le5xn3s4nm8wee115r89eibropgdj55idb5vtjx7-0hfio4cb9wqk95nipipq5g7ii 192.168.57.127:2377
192.168.57.120 作为manager node加入
[root@centos ~]# docker swarm join --token SWMTKN-1-2k0pyekm18le5xn3s4nm8wee115r89eibropgdj55idb5vtjx7-0hfio4cb9wqk95nipipq5g7ii 192.168.57.127:2377
This node joined a swarm as a manager.
查看节点:docker node ls
[root@centos ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
51kgawqwx5hp3ytl55m9g8mcf centos Down Active 19.03.6-rc2
ewa94hkxarjjkuydx2jq2y3bm * centos Ready Active Reachable 19.03.6-rc2
sv2g7ljrt9leiw0caet9d9wj5 centos Ready Active Leader 19.03.13-beta2
说明:status 为down的节点为192.168.57.120退出集群导致
查看集群信息:docker info
[root@centos ~]# docker info
Client:Debug Mode: falseServer:Containers: 4Running: 0Paused: 0Stopped: 4Images: 39Server Version: 19.03.6-rc2Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: activeNodeID: ewa94hkxarjjkuydx2jq2y3bmIs Manager: trueClusterID: 4ehmddg5fn49wjz9zi88fi3peManagers: 2Nodes: 3Default Address Pool: 10.0.0.0/8 SubnetSize: 24Data Path Port: 4789Orchestration:Task History Retention Limit: 5Raft:Snapshot Interval: 10000Number of Old Snapshots to Retain: 0Heartbeat Tick: 1Election Tick: 10Dispatcher:Heartbeat Period: 5 secondsCA Configuration:Expiry Duration: 3 monthsForce Rotate: 0Autolock Managers: falseRoot Rotation In Progress: falseNode Address: 192.168.57.120Manager Addresses:192.168.57.120:2377192.168.57.127:2377Runtimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: b34a5c8af56e510852c35414db4c1f4fa6172339runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657init version: fec3683Security Options:seccompProfile: defaultKernel Version: 3.10.0-957.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 1.777GiBName: centosID: GJSG:3CFX:XLTR:YOJU:ZOOL:QBES:YWSR:JRFH:TWXR:W5CM:Y2Y5:H2B5Docker Root Dir: /var/lib/dockerDebug Mode: falseUsername: lihu12344Registry: :Experimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors: Restore Enabled: falseWARNING: Running Swarm in a two-manager configuration. This configuration providesno fault tolerance, and poses a high risk to lose control over the cluster.Refer to / to configure theSwarm for fault-tolerance.
managers:2、nodes:3 ==> 管理节点有2个,共有3个节点
is manager:true ==> 当前节点为manager 节点
node address: 192.168.57.120 ==> 当前节点的ip地址为 192.168.57.120
manager addresses:192.168.57.120:2377、192.168.57.127:2377 ==> 管理节点的ip地址
服务操作
创建服务
[root@centos ~]# docker service create -p 6379:6379 --replicas 1 --name redis redis
rvodfdouqjqrl9dnzcgpeiw4v
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
说明:创建服务操作需要在manager node上执行
查看服务列表:docker service ls
[root@centos ~]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
rvodfdouqjqr redis replicated 1/1 redis:latest *:6379->6379/tcp
查看服务运行信息:docker service ps redis
[root@centos ~]# docker service ps redis
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ma4ifebdonse redis.1 redis:latest centos Running Running 3 minutes ago
查看服务日志:docker service logs redis
[root@centos ~]# docker service logs redis
redis.1.ma4ifebdonse@centos | 1:C 22 Aug 2020 02:41:19.210 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis.1.ma4ifebdonse@centos | 1:C 22 Aug 2020 02:41:19.210 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis.1.ma4ifebdonse@centos | 1:C 22 Aug 2020 02:41:19.210 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/f
redis.1.ma4ifebdonse@centos | 1:M 22 Aug 2020 02:41:19.214 * Running mode=standalone, port=6379.
redis.1.ma4ifebdonse@centos | 1:M 22 Aug 2020 02:41:19.215 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis.1.ma4ifebdonse@centos | 1:M 22 Aug 2020 02:41:19.215 # Server initialized
redis.1.ma4ifebdonse@centos | 1:M 22 Aug 2020 02:41:19.215 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /f and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis.1.ma4ifebdonse@centos | 1:M 22 Aug 2020 02:41:19.215 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis.1.ma4ifebdonse@centos | 1:M 22 Aug 2020 02:41:19.216 * Ready to accept connections
更新服务,副本数变为2:docker service update --replicas 2 redis
[root@centos ~]# docker service update --replicas 2 redis
redis
overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged
查看服务:docker service ps redis
[root@centos ~]# docker service ps redis
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ma4ifebdonse redis.1 redis:latest centos Running Running 11 minutes ago
d7nkflpyw8ds redis.2 redis:latest centos Running Running 23 seconds ago
副本数变为2
查看服务详细信息:docker service inspect redis
[root@centos ~]# docker service inspect redis
[{"ID": "rvodfdouqjqrl9dnzcgpeiw4v","Version": {"Index": 24},"CreatedAt": "2020-08-22T02:41:13.095574991Z","UpdatedAt": "2020-08-22T02:52:06.00798984Z","Spec": {"Name": "redis","Labels": {},"TaskTemplate": {"ContainerSpec": {"Image": "redis:latest@sha256:09c33840ec47815dc0351f1eca3befe741d7105b3e95bc8fdb9a7e4985b9e1e5","Init": false,"StopGracePeriod": 10000000000,"DNSConfig": {},"Isolation": "default"},"Resources": {"Limits": {},"Reservations": {}},"RestartPolicy": {"Condition": "any","Delay": 5000000000,"MaxAttempts": 0},"Placement": {"Platforms": [{"Architecture": "amd64","OS": "linux"},{"OS": "linux"},{"OS": "linux"},{"Architecture": "arm64","OS": "linux"},{"Architecture": "386","OS": "linux"},{"Architecture": "mips64le","OS": "linux"},{"Architecture": "ppc64le","OS": "linux"},{"Architecture": "s390x","OS": "linux"}]},"ForceUpdate": 0,"Runtime": "container"},"Mode": {"Replicated": {"Replicas": 2}},"UpdateConfig": {"Parallelism": 1,"FailureAction": "pause","Monitor": 5000000000,"MaxFailureRatio": 0,"Order": "stop-first"},"RollbackConfig": {"Parallelism": 1,"FailureAction": "pause","Monitor": 5000000000,"MaxFailureRatio": 0,"Order": "stop-first"},"EndpointSpec": {"Mode": "vip","Ports": [{"Protocol": "tcp","TargetPort": 6379,"PublishedPort": 6379,"PublishMode": "ingress"}]}},"PreviousSpec": {"Name": "redis","Labels": {},"TaskTemplate": {"ContainerSpec": {"Image": "redis:latest@sha256:09c33840ec47815dc0351f1eca3befe741d7105b3e95bc8fdb9a7e4985b9e1e5","Init": false,"DNSConfig": {},"Isolation": "default"},"Resources": {"Limits": {},"Reservations": {}},"Placement": {"Platforms": [{"Architecture": "amd64","OS": "linux"},{"OS": "linux"},{"OS": "linux"},{"Architecture": "arm64","OS": "linux"},{"Architecture": "386","OS": "linux"},{"Architecture": "mips64le","OS": "linux"},{"Architecture": "ppc64le","OS": "linux"},{"Architecture": "s390x","OS": "linux"}]},"ForceUpdate": 0,"Runtime": "container"},"Mode": {"Replicated": {"Replicas": 1}},"EndpointSpec": {"Mode": "vip","Ports": [{"Protocol": "tcp","TargetPort": 6379,"PublishedPort": 6379,"PublishMode": "ingress"}]}},"Endpoint": {"Spec": {"Mode": "vip","Ports": [{"Protocol": "tcp","TargetPort": 6379,"PublishedPort": 6379,"PublishMode": "ingress"}]},"Ports": [{"Protocol": "tcp","TargetPort": 6379,"PublishedPort": 6379,"PublishMode": "ingress"}],"VirtualIPs": [{"NetworkID": "0yjl71w64xlkfw5ititsuao1z","Addr": "10.0.0.4/24"}]}}
]
服务回滚:docker service rollback redis
[root@centos ~]# docker service rollback redis
redis
service rolled back: rollback completed
查看服务信息:docker service ps redis
[root@centos ~]# docker service ps redis
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
ma4ifebdonse redis.1 redis:latest centos Running Running 16 minutes ago
副本数回滚为1
本文发布于:2024-02-03 03:45:56,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170690315448439.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |