AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 852621
Accepted
Mircea Vutcovici
Mircea Vutcovici
Asked: 2017-05-28 14:53:49 +0800 CST2017-05-28 14:53:49 +0800 CST 2017-05-28 14:53:49 +0800 CST

无法为 'nofile' 设置限制 - 在 LXD 非特权容器中“不允许操作”

  • 772

我在 ubuntu 17.04 主机上运行一个 centos7 非特权 LXD 容器。如果它在非特权模式下运行,我在容器内为 NOFILE 设置 ulimit 时遇到问题。

下面是重现的步骤:

$ lxc launch images:centos/7/amd64 mycontainer
$ lxc exec mycontainer bash
[root@mycontainer ~]# yum install strace
[root@mycontainer ~]# ulimit -n 200000
bash: ulimit: open files: cannot modify limit: Operation not permitted
[root@mycontainer ~]#
[root@mycontainer ~]# strace -e setrlimit bash -c 'ulimit -n 200000'
setrlimit(RLIMIT_NOFILE, {rlim_cur=200000, rlim_max=200000}) = -1 EPERM (Operation not permitted)
bash: line 0: ulimit: open files: cannot modify limit: Operation not permitted
+++ exited with 1 +++
[root@mycontainer ~]#

容器的配置细节:

$ sudo lxc config show mycontainer
architecture: x86_64
config:
  image.architecture: amd64
  image.build: "20170504_02:16"
  image.description: Centos 7 (amd64) (20170504_02:16)
  image.distribution: centos
  image.release: "7"
  volatile.base_image: 41c7bb494bbdf71c2aee471bb44a2318fd3424a0cd22091fb896a7614ae545eb
  volatile.eth0.hwaddr: 00:16:3e:61:e4:6c
  volatile.eth0.name: eth0
  volatile.idmap.base: "0"
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":140000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":140000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":140000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":140000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.power: STOPPED
  volatile.root.hwaddr: 00:16:3e:6b:93:1d
  volatile.root.name: eth1
devices: {}
ephemeral: false
profiles:
- default

作为一种解决方法,我可以使容器具有特权,但我更喜欢只授予此容器的 rlimit 访问权限,或者能够从 lxd 提高限制。以下是我如何获得特权:

$ lxc config set mycontainer security.privileged true
$ lxc restart mycontainer
$ sudo lxc config show mycontainer                                                                                                                   
architecture: x86_64
config:
  image.architecture: amd64
  image.build: "20170504_02:16"
  image.description: Centos 7 (amd64) (20170504_02:16)
  image.distribution: centos
  image.release: "7"
  security.privileged: "true"
  volatile.base_image: 41c7bb494bbdf71c2aee471bb44a2318fd3424a0cd22091fb896a7614ae545eb
  volatile.eth0.hwaddr: 00:16:3e:61:e4:6c
  volatile.eth0.name: eth0
  volatile.idmap.base: "0"
  volatile.idmap.next: '[]'
  volatile.last_state.idmap: '[]'
  volatile.last_state.power: RUNNING
devices: {}
ephemeral: false
profiles:
- default
centos7
  • 1 1 个回答
  • 3169 Views

1 个回答

  • Voted
  1. Best Answer
    Mircea Vutcovici
    2017-05-28T15:01:17+08:002017-05-28T15:01:17+08:00

    似乎在开发中有一个选项可以设置 lxd 的限制:

    解决方案将是:

    lxc config set mycontainer limits.kernel.nofile 200000
    lxc restart mycontainer
    

    看:

    • https://github.com/lxc/lxc/pull/1276
    • https://github.com/lxc/lxd/issues/3272
    • 1

相关问题

  • 如何在 Centos 上保持 openvpn 连接打开

  • LIST 上的 ProFTPd 超时

  • 与 AWS 中的其他系统相比,CentOS 报告的总内存较低

  • SELinux 阻止 Apache 写入文件

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve