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 / 问题 / 1024599
Accepted
j4nd3r53n
j4nd3r53n
Asked: 2020-07-10 00:52:07 +0800 CST2020-07-10 00:52:07 +0800 CST 2020-07-10 00:52:07 +0800 CST

使用 cgroups/systemd 限制每个用户的资源使用

  • 772

Debian 10:我想限制所有用户的内存、CPU 等,除了root; 我找到了几篇关于这个的文章,但到目前为止,它们都围绕着 cgconfig 展开,这似乎不是现在完成的方式。我已经看到了一些使用切片的建议,因此对于 UID 1000,创建如下内容:

# cat /lib/systemd/system/user-1000.slice
[Unit]
Description=User and Session Slice
Documentation=man:systemd.special(7)
Before=slices.target
MemoryHigh=20M

[Slice]
Slice=user-slice

[Install]
WantedBy=multi-user.target

并使用systemctl enable user-1000.slice. 这似乎成功了一半:

 $ systemctl status user-1000.slice
Warning: The unit file, source configuration file or drop-ins of user-1000.slice changed on disk. Run 'systemctl daemon-reload' to reload units.
● user-1000.slice - User Slice of UID 1000
   Loaded: loaded (/lib/systemd/system/user-1000.slice; enabled; vendor preset: enabled)
  Drop-In: /usr/lib/systemd/system/user-.slice.d
           └─10-defaults.conf
   Active: active since Thu 2020-07-09 07:37:28 UTC; 1h 8min ago
     Docs: man:systemd.special(7)
           man:[email protected](5)
    Tasks: 7 (limit: 5237)
   Memory: 5.4M
   CGroup: /user.slice/user-1000.slice
           ├─session-15.scope
           │ ├─1089 sshd: jan [priv]
           │ ├─1107 sshd: jan@pts/1
           │ ├─1108 -bash
           │ ├─1113 systemctl status user-1000.slice
           │ └─1114 pager
           └─[email protected]
             └─init.scope
               ├─1092 /lib/systemd/systemd --user
               └─1093 (sd-pam)

但是,MemoryHigh未设置:

 $ systemctl show user-1000.slice
Slice=user.slice
ControlGroup=/user.slice/user-1000.slice
...
MemoryHigh=infinity
...

我似乎很接近,但一定少了点什么——那是什么?

systemd debian-buster cgroup
  • 1 1 个回答
  • 1348 Views

1 个回答

  • Voted
  1. Best Answer
    Michael Hampton
    2020-07-10T03:12:34+08:002020-07-10T03:12:34+08:00

    您错过了打印在屏幕上的警告:

    Warning: The unit file, source configuration file or drop-ins of user-1000.slice changed on disk. Run 'systemctl daemon-reload' to reload units.
    

    当您更改 systemd 单位时,您必须systemctl daemon-reload让 systemd 重新读取它们。此外,受影响的单位需要重新启动。

    也就是说,如果您希望更改适用于所有用户,您可能应该改写为覆盖user.slice。当然,您永远不应该编辑系统提供的文件,而是通过drop-in files使用覆盖。

    • 2

相关问题

  • SSH 会话在关机/重启时挂起

  • 我可以使用 systemd 重新启动依赖服务吗?

  • 让我的旧初始化脚本在 systemd 中工作的最简单方法是什么?

  • 在 CentOS 7 上为 systemd 启动的进程增加 nproc

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