适合初学者的简单 CoreOS 配置(带密码登录)
与其他基于 Linux 的系统相比,CoreOS 需要相当大的学习曲线才能正确安装 - 例如,你必须为创建正确的 ignition 文件。这是一个巨大的障碍,特别是对于首次用户。
这篇文章试图通过提供适合大多数实际(特别是小规模)用例的基本配置并提供自定义配置的良好起点来缓解陡峭的学习曲线。
简单安装
首先,从 CoreOS Live CD 启动 VM。我们假设你有连接到 eth0 的 DHCP 网络。你将立即看到 shell。
VM 将通过 DHCP 自动获取 IP 地址。
你可以使用 TechOverflow 托管的 ignition 文件进行安装。你需要根据你的硬件/虚拟机管理程序使用正确的磁盘而不是 /dev/xvda。如有疑问,使用 lsblk 查找正确的磁盘名称。
现在运行安装命令:
install.sh
sudo coreos-installer install /dev/xvda --copy-network --ignition-url https://techoverflow.net/coreos.ign安装完成后,使用以下命令重启
commands.sh
reboot机器重启后,你可以使用默认登录凭据:
用户名:admin
密码: coreos
主机名是 CoreOS。
你绝对需要在安装后更改密码!如果你创建另一个用户,请记住你仍需要使用以下命令更改 admin 用户的密码
commands.sh
sudo passwd admin构建你自己的配置文件
这是我们用来创建正确配置文件的 Ignition YAML。使用我们在 https://fcct.techoverflow.net 的在线转译器将 YAML 编译为 JSON 文件。为了创建新的密码哈希,使用 TechOverflow 的基于 docker 的 mkpasswd 方法。
ignition.yaml
variant: fcos
version: 1.0.0
passwd:
users:
- name: admin
groups:
- "sudo"
- "docker"
password_hash: $y$j9T$n6h8P2ik8tfoNUFBBoly00$7bnrMF8oFrB25Fc3NqigqEH/MI5YXIJwtCG/iEsns.2
systemd:
units:
- name: docker.service
enabled: true
- name: containerd.service
enabled: true
- name: serial-getty@ttyS0.service
dropins:
- name: autologin-core.conf
contents: |
[Service]
# 覆盖主单元中的 Execstart
ExecStart=
# 添加带 `-` 前缀的新 Execstart 以忽略失败
ExecStart=-/usr/sbin/agetty --autologin admin --noclear %I $TERM
TTYVTDisallocate=no
storage:
files:
- path: /etc/hostname
mode: 0644
contents:
inline: |
CoreOS
- path: /etc/profile.d/systemd-pager.sh
mode: 0644
contents:
inline: |
# 告诉 systemd 打印信息时不使用分页器
export SYSTEMD_PAGER=cat
- path: /etc/sysctl.d/20-silence-audit.conf
mode: 0644
contents:
inline: |
# 将控制台消息日志级别从 DEBUG (7) 提高到 WARNING (4)
# 以隐藏交互式控制台的审计消息
kernel.printk=4
- path: /etc/ssh/sshd_config.d/20-enable-passwords.conf
mode: 0644
contents:
inline: |
# 启用 SSH 密码登录
PasswordAuthentication yes这产生以下转译的 JSON:
transpiled.json
{
"ignition": {
"version": "3.0.0"
},
"passwd": {
"users": [
{
"groups": [
"sudo",
"docker"
],
"name": "admin",
"passwordHash": "$y$j9T$n6h8P2ik8tfoNUFBBoly00$7bnrMF8oFrB25Fc3NqigqEH/MI5YXIJwtCG/iEsns.2"
}
]
},
"storage": {
"files": [
{
"contents": {
"source": "data:,CoreOS%0A"
},
"mode": 420,
"path": "/etc/hostname"
},
{
"contents": {
"source": "data:,%23%20Tell%20systemd%20to%20not%20use%20a%20pager%20when%20printing%20information%0Aexport%20SYSTEMD_PAGER%3Dcat%0A"
},
"mode": 420,
"path": "/etc/profile.d/systemd-pager.sh"
},
{
"contents": {
"source": "data:,%23%20Raise%20console%20message%20logging%20level%20from%20DEBUG%20(7)%20to%20WARNING%20(4)%0A%23%20to%20hide%20audit%20messages%20from%20the%20interactive%20console%0Akernel.printk%3D4%0A"
},
"mode": 420,
"path": "/etc/sysctl.d/20-silence-audit.conf"
},
{
"contents": {
"source": "data:,%23%20Enable%20SSH%20password%20login%0APasswordAuthentication%20yes%0A"
},
"mode": 420,
"path": "/etc/ssh/sshd_config.d/20-enable-passwords.conf"
}
]
},
"systemd": {
"units": [
{
"enabled": true,
"name": "docker.service"
},
{
"enabled": true,
"name": "containerd.service"
},
{
"dropins": [
{
"contents": "[Service]\\n# Override Execstart in main unit\\nExecStart=\\n# Add new Execstart with `-` prefix to ignore failure\\nExecStart=-/usr/sbin/agetty --autologin admin --noclear %I $TERM\\nTTYVTDisallocate=no\\n",
"name": "autologin-core.conf"
}
],
"name": "serial-getty@ttyS0.service"
}
]
}
}Check out similar posts by category:
CoreOS
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow