如何阻止 cloud-init 覆盖 AWS (CentOS) 上的主机名

问题描述 投票:0回答:5

我有一个在启动时运行的脚本(通过 rc.local),并根据从 AWS CLI 查询的实例名称设置我的主机名。它可以工作,并且在启动日志的末尾显示“登录:”

发现 cloud-init 正在覆盖我的主机名,所以我:

  • 在 /etc/cloud/cloud.cfg 中设置preserve_hostname:true
  • 在 /etc/cloud/cloud.cfg.d/00_defaults.cfg 的 cloud_config_modules 部分注释掉 set-hostname 和 update-hostname

但在 cloud-init 日志中,我仍然看到“正在运行模块 update-hostname”和“将信号量 update_hostname.always 迁移到 config-update-hostname,频率始终为”,启动后一两分钟主机名返回到 AWS 默认值.

发生什么事了?我该如何阻止它?

amazon-web-services centos hostname cloud-init
5个回答
7
投票

我知道这是一篇旧帖子,但我发现了解它很有用。

/etc/cloud/cloud.cfg
文件中,在
hostname: <fqdn/hostname>
下面添加
preserve_hostname: <true/false>

# 这将导致set+update主机名模块无法运行(如果为true)
保留主机名: false
主机名:我的主机名

来源:https://cloudinit.readthedocs.io/en/latest/topics/modules.html#set-hostname.


2
投票

https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/

请务必使用完整命令:

sudo hostnamectl set-hostname --static <persistent_host_name>


0
投票

试试这个:

$ sudo vi /etc/cloud/cloud.cfg

然后根据需要注释掉 'set_hostname'、'update-hostname' 和 'update_etc_hosts'。


0
投票

Ubuntu 略有不同: https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/

sudo hostnamectl set-hostname my.persistent.hostname

-9
投票

我真正讨厌的破解方法是创建一个每分钟设置一次主机名的 cron 作业。感谢改进建议。

© www.soinside.com 2019 - 2024. All rights reserved.