![单元用户-.slice 无法正确加载:参数无效](https://linux22.com/image/950786/%E5%8D%95%E5%85%83%E7%94%A8%E6%88%B7-.slice%20%E6%97%A0%E6%B3%95%E6%AD%A3%E7%A1%AE%E5%8A%A0%E8%BD%BD%EF%BC%9A%E5%8F%82%E6%95%B0%E6%97%A0%E6%95%88.png)
我一直在尝试在 22.04.1 登录节点上设置资源控制,这样用户就不会因为运行任何过于密集的东西而降低系统性能。我考虑过使用,cgroups
但显然因为它是一个 systemd 系统,user-.slice
所以我想要它。不幸的是,我甚至无法启动默认服务。
❯ sudo systemctl status user-.slice
Warning: The unit file, source configuration file or drop-ins of user-.slice changed on disk. Run 'systemctl daemon-reload' to reload units.
○ user-.slice - User Slice of UID
Loaded: error (Reason: Unit user-.slice failed to load properly, please adjust/correct and reload service manager: Invalid argument)
Drop-In: /usr/lib/systemd/system/user-.slice.d
└─10-defaults.conf
Active: inactive (dead)
Docs: man:[email protected](5)
我看不出哪个参数是无效的,并且我已经重新加载了单位,sudo systemctl daemon-reload
但它仍然说它们已经改变......
❯ sudo systemctl daemon-reload
❯ sudo systemctl restart user-.slice
Failed to start user-.slice: Unit user-.slice failed to load properly, please adjust/correct and reload service manager: Invalid argument
See system logs and 'systemctl status user-.slice' for details.
❯ systemctl status user-.slice
Warning: The unit file, source configuration file or drop-ins of user-.slice changed on disk. Run 'systemctl daemon-reload' to reload units.
○ user-.slice - User Slice of UID
Loaded: error (Reason: Unit user-.slice failed to load properly, please adjust/correct and reload service manager: Invalid argument)
Drop-In: /usr/lib/systemd/system/user-.slice.d
└─10-defaults.conf
Active: inactive (dead)
Docs: man:[email protected](5)
主要配置目前都是默认的:
❯ cat /usr/lib/systemd/system/user.slice
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=User and Session Slice
Documentation=man:systemd.special(7)
Before=slices.target
❯ cat /usr/lib/systemd/system/user-.slice.d/10-defaults.conf
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=User Slice of UID %j
Documentation=man:[email protected](5)
After=systemd-user-sessions.service
StopWhenUnneeded=yes
[Slice]
TasksMax=33%
最终,我只想添加 2 个内存和 CPU 上限设置:
❯ cat 50-user-caps.conf
[Slice]
CPUQuota=400%
MemoryMax=4G
知道发生什么事了吗?
由@steeldriver 回答
您无需与user-.slice
服务进行交互,只需与user-UID.slice
自动获取服务进行交互即可。
答案1
我认为这里的问题在于理解切片命名约定 - 特别是破折号“属于”哪个切片。来自man systemd.slice
:
The name of the slice encodes the location in the tree. The name consists of a dash-separated series of names, which describes the path to the slice from the root slice. The root slice is named -.slice. Example: foo-bar.slice is a slice that is located within foo.slice, which in turn is located in the root slice -.slice.
因此,在用户切片层次结构的情况下,有效的 systemctl status 命令是
systemctl status user-$(id -u).slice
或者例如systemctl status user-1000.slice
systemctl status user.slice
systemctl status -- -.slice
对于根切片
在根切片的情况--
下,需要防止-.slice
被解析为命令行选项。