更新时间:2022-09-23 19:40:02
ssh -i /Path/to/keyfile/keyfile.pem core@ec-2-server-path.compute.amazonaws.com
$ fleetctl
NAME: fleetctl - fleetctl is a command-line interface to fleet, the cluster-wide CoreOS init system. USAGE: fleetctl [global options] <command> [command options] [arguments...] [...]
[Unit] Description=MyApp After=docker.service Requires=docker.service [Service] TimeoutStartSec=0 ExecStartPre=-/usr/bin/docker kill busybox1 ExecStartPre=-/usr/bin/docker rm busybox1 ExecStartPre=/usr/bin/docker pull busybox ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done" ExecStop=/usr/bin/docker stop busybox1
myapp.service
。Description
会在日志中显示出来,所以***还是用容易辨别的值,方便你之后辨别日志。After=docker.service
和Requires=docker.service
意思是这个单元的配置只会在docker.service
生效后才会启动。ExecStart
选项可以让你去定义一条在单元配置启动时执行的命令。ExecStartPre
选项可以让你定义一条命令,在ExecStart
中定义的命令之前执行。这个选项可以用以做一些类似清理环境,设置环境的行为。-d
参数来运行fleet,因为加了这参数后fleet进程就不是容器的子进程了。这样的话,systemd会认为该进程已经退出了,然后该fleet单元就会终止服务。ExecStop
中定义的命令则会在该单元启动失败或者终止时执行。myapp.service
的配置文件或者创建之在那个你已经连接上的节点上去。$ fleetctl start myapp.service
$ fleetctl list-unit-files
$ fleetctl list-unit-files UNIT HASH DSTATE STATE TARGET myapp.service d4c61bf launched launched 85c0c595.../172.31.5.9 anotherapp.service e55c0ae launched launched 113f16a7.../172.31.22.187 someapp.service 391d247 launched launched a0b7a5f7.../172.31.22.22
myapp.service
,anotherapp.service
,someapp.service
)。在TARGET
一列中就列出了这些服务器的IP地址。$ fleetctl list-unit-files
UNIT HASH DSTATE STATE TARGET myapp.service d4c61bf launched launched 85c0c595.../172.31.5.9 anotherapp.service e55c0ae launched launched 113f16a7.../172.31.22.187 someapp.service 391d247 launched launched a0b7a5f7.../172.31.22.187
someapp.service
是跑在172.31.22.22这机器上的,但是现在是和anotherapp.service
一起跑在172.31.22.187的。所以在172.31.22.22从集群中被移走,还有someapp.service
被移动到跑着anotherapp.service
的健康节点上去时,发生了什么事情?