栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

单机版swarm安装

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

单机版swarm安装

Ubantu下的docker安装
# 1.卸载旧版本
apt-get remove docker docker-engine docker.io containerd runc

# 2.安装前提依赖
apt update
apt-get install ca-certificates curl gnupg lsb-release

# 3.安装GPG证书
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

# 4.写入软件源信息
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

# 5.安装新版本docker
apt-get install docker-ce docker-ce-cli containerd.io

# 6.配置用户组
groupadd docker

#7.启动docker
systemctl start docker

#8.docker换源
# 修改 /etc/docker/daemon.json (如果该文件不存在,则创建)
{
    "registry-mirrors": [
        "https://hub-mirror.c.163.com"
	]
}

# 9.安装必要系统工具
apt-get -y install apt-transport-https ca-certificates curl software-properties-common

# 10.配置docker
# 添加 docker 配置 /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "registry-mirrors": ["docker镜像仓库国内加速"]
}

# 11.重启docker
service docker restart
单机版Swarm安装和试用
# 1.拉取swarm镜像
[root@zjs ~]# docker pull swarm
Using default tag: latest
Trying to pull repository docker.io/library/swarm ... 
latest: Pulling from docker.io/library/swarm
d85c18077b82: Pull complete 
1e6bb16f8cb1: Pull complete 
85bac13497d7: Pull complete 
Digest: sha256:406022f04a3d0c5ce4dbdb60422f24052c20ab7e6d41ebe5723aa649c3833975
Status: Downloaded newer image for docker.io/swarm:latest



# 2.初始化swarm
[root@zjs ~]# docker swarm init --advertise-addr 192.168.22.177
Swarm initialized: current node (elyfa6h1lx5o2s98une5vas4x) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join 
    --token SWMTKN-1-32h92m334z80z270d4duqdc3ysl1oyrjmxe1upyyfjyln12xxa-4gm603mczorxgh6751n5q7jya 
    192.168.22.177:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
#执行上面的命令后,当前的服务器就加入到swarm集群中,同时会产生一个唯一的token值,其它节点加入集群时需要用到这个token。
#--advertise-addr 表示swarm集群中其它节点使用后面的IP地址与管理节点通讯,上面也提示了其它节点如何加入集群的命令。
#3.查看是否安装成功
[root@zjs ~]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 1
Server Version: 1.13.1
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: journald
Cgroup Driver: systemd
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
**Swarm: active
 NodeID: elyfa6h1lx5o2s98une5vas4x
 Is Manager: true
 ClusterID: vi716cgvw33gzicrfqopasf9p
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
 Node Address: 192.168.22.177
 Manager Addresses:
  192.168.22.177:2377
Runtimes: docker-runc runc
Default Runtime: docker-runc
Init Binary: /usr/libexec/docker/docker-init-current
containerd version:  (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: e9c345b3f906d5dc5e8100b05ce37073a811c74a (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: 5b117de7f824f3d3825737cf09581645abbe35d4 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
 seccomp
  WARNING: You're not using the default seccomp profile
  Profile: /etc/docker/seccomp.json
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 1
Total Memory: 2.238 GiB
Name: zjs
ID: 653Y:7CME:GFPW:35SX:IGZL:UJP7:YSPZ:4OMV:J4EV:Z6FS:WFW2:YYHS
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-ip6tables is disabled
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Registries: docker.io (secure)

4.查看当前节点信息
[root@zjs ~]# docker node ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
elyfa6h1lx5o2s98une5vas4x *   zjs      Ready   Active        Leader
# 5.创建服务
[root@zjs ~]# docker service create --replicas 1 --network dockernet --name nginx-cluster -p 80:80 nginx
k7lupo9xu0cnd5ng1g4f7i7jx


# 6.查看服务列表
[root@zjs ~]# docker service ls
ID            NAME           MODE        REPLICAS  IMAGE
k7lupo9xu0cn  nginx-cluster  replicated  1/1       nginx:latest

# 7.查看指定服务
[root@zjs ~]# docker service ps nginx-cluster
ID            NAME             IMAGE         NODE     DESIRED STATE  CURRENT STATE           ERROR  PORTS
7t7xjpmao533  nginx-cluster.1  nginx:latest  zjs      Running        Running 17 seconds ago 
 
# 8.查看当前结点的任务       
[root@zjs ~]# docker ps
CONTAINER ID   IMAGE                                                                           COMMAND                  CREATED             STATUS              PORTS     NAMES
a9d78079fdc7  nginx@sha256:3e2ffcf0edca2a4e9b24ca442d227baea7b7f0e33ad654ef1eb806fbd9bedcf0   "nginx -g 'daemon ..."   22 seconds ago      Up 22 seconds       80/tcp     nginx-cluster.1.7t7xjpmao5335zaa8wp0c896a

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/870594.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号