如何在 Elastic Beanstalk 中增加 Docker 中的 ulimit?

Posted

技术标签:

【中文标题】如何在 Elastic Beanstalk 中增加 Docker 中的 ulimit?【英文标题】:How to increase ulimit in Docker in Elastic Beanstalk? 【发布时间】:2015-01-16 10:27:10 【问题描述】:

我想在 Elastic Beanstalk 中增加 Docker 中的 ulimit 以运行一些应用程序。 我知道我需要增加 Docker 主机的 ulimit 并重新启动 docker 服务,但找不到方法。

我写了关注.ebextensions/01limits.config,但仍然无法增加ulimit。

commands:
  01limits:
    command: echo -e "#commands\nroot soft nofile 65536\nroot hard nofile 65536\n* soft nofile 65536\n* hard nofile 65536" >> /etc/security/limits.conf
  02restartdocker:
    command: service docker restart

添加于 2014 年 11 月 20 日 09:37 GMT

还尝试了以下配置文件。

commands:
  01limits:
    command: echo -e "#commands\nroot soft nofile 65536\nroot hard nofile 65536\n* soft nofile 65536\n* hard nofile 65536" >> /etc/security/limits.conf
  02restartdocker:
    command: service docker stop && ulimit -a 65536 && service docker start

它成功增加了ulimit,但在管理控制台中显示以下错误:

[Instance: i-xxxxxxxx Module: AWSEBAutoScalingGroup ConfigSet: null] 命令在实例上失败。返回代码:1 输出:[CMD-AppDeploy/AppDeployStage1/AppDeployEnactHook/00flip.sh] 命令失败,错误代码 1:/opt/elasticbeanstalk/hooks/appdeploy/enact/00flip.sh 停止 nginx:[确定] 启动 nginx:[确定] 正在停止当前应用程序容器:1c**********...来自守护程序的错误响应:无法销毁容器 1c**********:驱动程序设备映射器无法删除根文件系统 1c*** ****************************************************** *********:设备忙 2014/11/20 09:06:36 错误:无法删除一个或多个容器。

我不确定这个配置是否合适。

【问题讨论】:

可能重复:***.com/questions/24318543/… 除了我的问题特定于 Elastic Beanstalk 之外,它是重复的。 【参考方案1】:

这已经很晚了,但这是(希望)解决您的问题的有效解决方案

initctl stop eb-docker && /sbin/service docker stop && ulimit -n 65536 && ulimit -c unlimited && export DMAP=$(df | grep /var/lib | awk 'print $1') && if [[ $DMAP ]]; then umount $DMAP; fi && /sbin/service docker start && initctl start eb-docker

解释如下:

停止 docker 容器服务 停止泊坞窗服务 应用你的 ulimit 设置(我的和你的不同) 找到有问题的 devicemapper 挂载并卸载它(如果没有挂载则处理) 启动泊坞窗 启动docker容器服务

这不是一个优雅的解决方案,但这就是围绕 EB 进行黑客攻击的生活。

您可能希望将其分解为更小的组件,但总体思路就在那里。

【讨论】:

【参考方案2】:

我正在运行试图更改文件限制的 apachectl 版本。它失败并导致容器出错。

但是,最终,我从容器内部运行了 ulimit 命令:

root@22806b77a474:/home# ulimit
unlimited

似乎 apachectl 试图提高 docker 容器中实际上并不存在的限制。我 ULIMIT_MAX_FILES 到一些不会导致问题的东西。

RUN sed -i 's/ULIMIT_MAX_FILES="$APACHE_ULIMIT_MAX_FILES:-ulimit -n 8192"/ULIMIT_MAX_FILES="ulimit -H -n"/' /usr/sbin/apachectl

【讨论】:

以上是关于如何在 Elastic Beanstalk 中增加 Docker 中的 ulimit?的主要内容,如果未能解决你的问题,请参考以下文章

AWS Elastic beanstalk:使用 docker 镜像时如何设置 ulimit

AWS Elastic Beanstalk - 增加实例磁盘容量

Elastic Beanstalk / ELB 增加了超过 60 毫秒的延迟

AWS Elastic Beanstalk - 设置 JVM 选项(堆空间)

在 Elastic Beanstalk 中插入新的 Nginx conf

如何在 elastic-beanstalk 中应用 ruby​​ 版本补丁