由于Docker池大小而导致AWS ElasticBeanstalk容器死亡的良好解决方案

时间:2018-04-06 20:52:58

标签: amazon-web-services docker amazon-elastic-beanstalk

我遇到了Docker达到池大小限制的问题,该限制是磁盘的100%(12Gb)。我按照aws:

的建议运行了这个命令的cronjob
sudo docker ps -q | xargs sudo docker inspect --format='{{ .State.Pid }}' | xargs -IZ sudo fstrim /proc/Z/root/"

但是我需要一个更好的解决方案,因为这个解决方案不够强大,aws还建议在https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html为你的应用程序添加第二个磁盘。

我想要做的只是将一个短暂的磁盘添加到容器/ tmp,这是我的应用程序添加/删除大量文件的地方。

我发现设置.ebextensions文件很棘手,因为它是EB的默认配置,我需要确保当前设置不会更改。我开始使用这种格式,但我不确定映射是否正确。

option_settings:
  aws:autoscaling:launchconfiguration:
    BlockDeviceMappings: /dev/xvda=:16:true:gp2,/dev/xvdcz=:12:true:gp2,/dev/sdh=:12:true:gp2

我怎样才能确定这是对的?如何设置和映射我的容器的/ tmp文件夹?

这是我的环境:

因此,对于我在aws面板上看到的内容,我有两个SSD磁盘连接到配置的EC2。

/dev/xvda   16GB gp2 100IOPS
/dev/xvdz   12GB gp2 100IOPS

看看df它显示我有一个100GB的磁盘,我不知道它来自哪里。

当我登录EC2时,它显示:

[ec2-user@ip ~]$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G   84K  1.9G   1% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
/dev/xvda1       16G  1.8G   14G  12% /

坐骑是这样的:

[ec2-user@ip ~]$ mount
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=1918844k,nr_inodes=479711,mode=755)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /dev/shm type tmpfs (rw,relatime)
/dev/xvda1 on / type ext4 (rw,noatime,data=ordered)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)
/dev/xvda1 on /var/lib/docker/plugins type ext4 (rw,noatime,data=ordered)
/dev/xvda1 on /var/lib/docker/devicemapper type ext4 (rw,noatime,data=ordered)
/dev/mapper/docker-202:1-524315-c2f6bc2b0afd5c8fa3e5ea2a230d20a7b29b5949a9c43211f87285111970212e on /var/lib/docker/devicemapper/mnt/c2f6bc2b0afd5c8fa3e5ea2a230d20a7b29b5949a9c43211f87285111970212e type ext4 (rw,relatime,stripe=128,data=ordered)
shm on /var/lib/docker/containers/e0a908391b776bcbef403f411c031ab9d0cc48fb0aa05c178c41598042cf956e/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k)
nsfs on /var/run/docker/netns/1b779e66ebaa type nsfs (rw)

lvs输出:

    [ec2-user@ ~]$ sudo lvs
      LV          VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      docker-pool docker twi-aot--- 11.96g             20.04  3.44

Docker inspect显示:

},
        "GraphDriver": {
            "Data": {
                "DeviceId": "68",
                "DeviceName": "docker-202:1-524315-c2f6bc2b0afd5c8fa3e5ea2a230d20a7b29b5949a9c43211f87285111970212e",
                "DeviceSize": "107374182400"
            },
            "Name": "devicemapper"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/var/log/eb-docker/containers/eb-current-app",
                "Destination": "/var/log/worker",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

如果我登录我的容器,我会看到以下地图。

root@e0a908391b77:/# df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-202:1-524315-c2f6bc2b0afd5c8fa3e5ea2a230d20a7b29b5949a9c43211f87285111970212e   99G  594M   93G   1% /
tmpfs                                                                                              64M     0   64M   0% /dev
tmpfs                                                                                             1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/xvda1                                                                                         16G  1.8G   14G  12% /etc/hosts
shm                                                                                                64M     0   64M   0% /dev/shm
tmpfs                                                                                             1.9G     0  1.9G   0% /proc/scsi
tmpfs                                                                                             1.9G     0  1.9G   0% /sys/firmware

0 个答案:

没有答案