文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
安装 docker-engine
环境:Centos7
1.先检查是否安装旧版本 docker
[root@registry ~]# rpm -qa|grep docker
[root@registry ~]#
我这里没有安装,如果安装,请 rpm -e 卸载
2.编辑 docker.repo 文件,写入如下内容
[root@registry ~]# vim /etc/yum.repos.d/docker-main.repo
[docker-main-repo]
name=Docker main Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
3.安装 docker
[root@registry ~]# yum install docker-engine
4.关闭防火墙和 selinux
[root@registry ~]# systemctl stop firewalld.service
[root@registry ~]# systemctl disable firewalld.service
[root@registry ~]# vi /etc/selinux/config
修改 /etc/selinux/config 文件中的 SELINUX="" 为 disabled ,然后重启
5.增加 tcp 监听端口
修改 docker 配置文件
[root@registry ~]# vi /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -D -H tcp://0.0.0.0:2375
保存退出
6.启动 docker
[root@registry ~]# systemctl start docker
[root@registry ~]# ps -ef|grep docker
root 20803 1 0 8 月 09 ? 00:06:18 /usr/bin/dockerd -H unix:///var/run/docker.sock -D -H tcp://0.0.0.0:2375
root 20809 20803 0 8 月 09 ? 00:00:09 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime docker-runc --debug
root 31072 22506 0 10:29 pts/7 00:00:00 grep --color=auto docker
7.查看其它 docker 信息
[root@registry ~]# docker -H 192.168.20.112:2375 version
[root@registry ~]# docker -H 192.168.20.112:2375 info
[root@registry ~]# docker -H 192.168.20.112:2375 ps
附:新版 docker 内置 swarm 实现集群 我们安装的是 1.12 版 Docker Engine,Docker Swarm 已经被整合到了 Docker Engine,这样就可以更容易的把多个 Docker 主机组合成一整个规模更大可靠性更高的逻辑单元。
[root@master ~]# docker swarm --help
Usage: docker swarm COMMAND
Manage Docker Swarm
Options:
--help Print usage
Commands:
init Initialize a swarm
join Join a swarm as a node and/or manager
join-token Manage join tokens
update Update the swarm
leave Leave a swarm
Run 'docker swarm COMMAND --help' for more information on a command.
1)创建 swarm 管理节点
[root@master ~]# docker swarm init --listen-addr 0.0.0.0:2377 --advertise-addr 192.168.20.113
Swarm initialized: current node (79l4eevt1sx63cw8ewb7xf1fh) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-53zfa8v239nibt9eum4buemmq3wkfjsrqjxbte9ay93i3xzlsn-8cch0txhv5bl9bmlt7jh9gw68 \
192.168.20.113:2377
To add a manager to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-53zfa8v239nibt9eum4buemmq3wkfjsrqjxbte9ay93i3xzlsn-acsxqva1dj6m1gsjpaa6akhvg \
192.168.20.113:2377
看以看到管理节点已创建,多了几个监听端口:
TCP 端口 2377 集群管理端口
TCP 与 UDP 端口 7946 节点之间通讯端口
[root@master ~]# docker info
Containers: 9
Running: 6
Paused: 0
Stopped: 3
Images: 22
Server Version: 1.12.0
Storage Driver: devicemapper
Pool Name: docker-253:0-71406753-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 5.277 GB
Data Space Total: 107.4 GB
Data Space Available: 7.192 GB
Metadata Space Used: 9.925 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.138 GB
Thin Pool Minimum Free Space: 10.74 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2016-06-09)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: host bridge null overlay
Swarm: active
NodeID: 79l4eevt1sx63cw8ewb7xf1fh
Is Manager: true
ClusterID: a1annjmn8ks1tg6a3n0dqg2s4
Managers: 1
Nodes: 1
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot interval: 10000
Heartbeat tick: 1
Election tick: 3
Dispatcher:
Heartbeat period: 5 seconds
CA configuration:
Expiry duration: 3 months
Node Address: 192.168.20.113
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.793 GiB
Name: node1.docker.com
ID: HXUI:TQ3U:RMGP:5Q2W:V4L5:6JDM:4DB6:LEKK:4JBU:GQVP:NV2C:P72Y
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 60
Goroutines: 164
System Time: 2016-08-13T18:19:06.836430668+08:00
EventsListeners: 1
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-ip6tables is disabled
Insecure Registries:
192.168.20.113:5000
127.0.0.0/8
2)添加节点到集群
[root@node1 ~]# docker swarm join \
--token SWMTKN-1-53zfa8v239nibt9eum4buemmq3wkfjsrqjxbte9ay93i3xzlsn-8cch0txhv5bl9bmlt7jh9gw68 \
192.168.20.113:2377
This node joined a swarm as a worker.
3)在 manager 节点上查看节点
[root@master ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
1yid2aeraryzrhcdnmvyze6xq node2.docker.com Ready Active
79l4eevt1sx63cw8ewb7xf1fh * node1.docker.com Ready Active Leader
4)常见的双层(web+db)应用可按以下方法创建:
docker network create -d overlay mynet
docker service create --name frontend --replicas 5 -p 80:80/tcp \
--network mynet mywebapp
docker service create --name redis --network mynet redis:latest
以下为此应用的基本架构示意图:
这条命令声明了必要状态,即将由 5 套 Nginx 容器构成的 Swarm 作为单一内部负载均衡型服务,且于 Swarm 内任意节点的端口 80 上进行交付。
Swarm 模式下的引擎拥有自组织与自修复特性,意味着它们能够识别我们定义的应用,并在出现差错时持续检查并修复环境。举例来说,如果大家关闭某台运行有 Nginx 实例的设备,则另一节点上会自动启动一套新的容器。如果关闭 Swarm 内半数设备所使用的网络交换机,则另外一半设备会顶替而上,接管对应工作负载。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论