使用 tljh-config
配置 TLJH#
tljh-config
是用于更改 TLJH 配置的命令行程序。
运行 tljh-config
#
您可以通过两种方式运行 tljh-config
以管理员用户身份登录 JupyterHub 后,在终端内运行。推荐使用此方法。
通过其他方式(例如 SSH)登录服务器后,以 root 身份直接调用
/opt/tljh/hub/bin/tljh-config
。这是一个高级用例,本指南中未详细介绍。
设置/取消设置配置属性#
TLJH 的配置以嵌套树结构组织。您可以使用以下命令设置特定属性
sudo tljh-config set <property-path> <value>
其中
<property-path>
是您要设置的属性的点分隔路径。<value>
是您要将属性设置为的值。
例如,要为 DummyAuthenticator 设置密码,您需要设置 auth.DummyAuthenticator.password
属性。您可以按如下方式操作
sudo tljh-config set auth.DummyAuthenticator.password mypassword
这只能设置字符串和数值属性,不能设置列表。
要取消设置配置属性,您可以使用以下命令
sudo tljh-config unset <property-path>
取消设置配置属性会从配置文件中删除该属性。如果您只想更改属性的值,则应使用 set
并用所需的值覆盖它。
以下列出了按类别划分的一些现有 <property-path>
基本 URL#
使用 base_url
确定 JupyterHub 使用的基本 URL。此参数将直接传递给 c.JupyterHub.base_url
。
身份验证#
使用 auth.type
确定要使用的身份验证器。配置中 auth.{auth.type}
下的所有参数都将直接传递给身份验证器本身。
端口#
使用 http.port
和 https.port
设置 TLJH 将侦听的端口,默认情况下分别为 80 和 443。但是,如果您更改这些端口,请注意 TLJH 会对系统执行许多其他操作(主要是用户帐户和 sudo 规则),这可能会破坏您的其他应用程序的安全假设,因此请务必谨慎使用。
sudo tljh-config set http.port 8080
sudo tljh-config set https.port 8443
sudo tljh-config reload proxy
(tljh-set-listen-address)
侦听地址#
使用 http.address
和 https.address
设置 TLJH 将侦听的地址,默认情况下为空地址(这意味着它默认侦听所有接口)。
sudo tljh-config set http.address 127.0.0.1
sudo tljh-config set https.address 127.0.0.1
sudo tljh-config reload proxy
用户列表#
users.allowed
接受要允许的用户名users.banned
接受要禁止的用户名users.admin
接受要指定为管理员的用户名sudo tljh-config add-item users.allowed good-user_1 sudo tljh-config add-item users.allowed good-user_2 sudo tljh-config add-item users.banned bad-user_6 sudo tljh-config add-item users.admin admin-user_0 sudo tljh-config remove-item users.allowed good-user_2
用户服务器限制#
limits.memory
指定每个单独用户可使用的最大内存。默认情况下没有内存限制。限制可以指定为绝对字节值。您可以使用后缀 K、M、G 或 T 分别表示千字节、兆字节、千兆字节或兆兆字节。将其设置为None
会禁用内存限制。sudo tljh-config set limits.memory 4G
即使您希望单个用户尽可能多地使用内存,将内存限制设置为总物理内存的 80-90% 仍然是最佳实践。这可以防止一个用户意外地通过 OOM 导致机器瘫痪。
limits.cpu
一个浮点数,表示每个用户可使用的总 CPU 核数。默认情况下没有 CPU 限制。1 表示一个完整的 CPU,4 表示 4 个完整的 CPU,0.5 表示半个 CPU,依此类推。此值最终转换为百分比并向下舍入到最接近的整数百分比,即 1.5 转换为 150%,0.125 转换为 12%,依此类推。将其设置为None
会禁用 CPU 限制。sudo tljh-config set limits.cpu 2
用户环境#
user_environment.default_app
设置用户启动到的默认应用程序。目前只能设置为:classic
和 jupyterlab
。
sudo tljh-config set user_environment.default_app jupyterlab
额外的用户组#
users.extra_user_groups
是一个配置选项,可用于自动将用户添加到特定组。默认情况下,未定义额外的组。
可以使用以下命令将用户与所需的现有组“配对”
tljh-config set
,如果只有一个用户要添加到所需组
tljh-config set users.extra_user_groups.group1 user1
tljh-config add-item
,如果多个用户要添加到组中
tljh-config add-item users.extra_user_groups.group1 user1
tljh-config add-item users.extra_user_groups.group1 user2
查看当前配置#
要查看当前配置,您可以运行以下命令
sudo tljh-config show
这将打印您的 TLJH 的当前配置。这在寻求支持时非常有用!
重新加载 JupyterHub 以应用配置#
修改配置后,您需要重新加载 JupyterHub 才能使其生效。您可以使用以下命令执行此操作
sudo tljh-config reload
这不应影响任何正在运行的用户。JupyterHub 将重新启动并加载新配置。
高级:config.yaml
#
tljh-config
是一个简单的程序,用于修改位于 /opt/tljh/config/config.yaml
的 config.yaml
文件的内容。tljh-config
是编辑/查看配置的推荐方法,因为在终端文本编辑器中手动编辑 YAML 是一个主要的错误来源。
要了解有关 tljh-config
用法的更多信息,您可以使用 --help
标志。--help
标志可以直接使用,以获取有关命令一般用法的信息,也可以在位置参数之后使用。例如,在 remove-item
等参数之后使用它会提供有关此特定命令的信息。
sudo tljh-config --help
usage: tljh-config [-h] [--config-path CONFIG_PATH] [--validate] [--no-validate] {show,unset,set,add-item,remove-item,reload} ...
positional arguments:
{show,unset,set,add-item,remove-item,reload}
show Show current configuration
unset Unset a configuration property
set Set a configuration property
add-item Add a value to a list for a configuration property
remove-item Remove a value from a list for a configuration property
reload Reload a component to apply configuration change
options:
-h, --help show this help message and exit
--config-path CONFIG_PATH
Path to TLJH config.yaml file
--validate Validate the TLJH config
--no-validate Do not validate the TLJH config
sudo tljh-config remove-item --help
usage: tljh-config remove-item [-h] key_path value
positional arguments:
key_path Dot separated path to configuration key to remove value from
value Value to remove from key_path
optional arguments:
-h, --help show this help message and exit