gpt4 book ai didi

cloud - 使用 cloud-init 在 CentOS 上设置主机名

转载 作者:行者123 更新时间:2023-12-05 06:55:29 24 4
gpt4 key购买 nike

我想在我的云配置文件中使用通用配置,为部署的操作系统手动设置主机名。 cloud-init 的“主机名”适用于 ubuntu 图像,但不能使其具体适用于 Centos 云图像(CentOS 7.8)。我看到条目是在/etc/hosts 文件中生成的,但是“hostname”命令仍然返回“localhost.localdomain”

这是我的云配置文件:

preserve_hostname: true
hostname: worker1
fqdn: worker1.local
manage_etc_hosts: true

这是“主机名”命令的输出:

[root@localhost ~]# hostname
localhost.localdomain

这是/etc/hosts 的内容:

[root@localhost ~]# cat /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 worker1.local worker1
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

我不想采用 'hostnamectl' 的方法来设置主机名,因为它不适用于 ubuntu/其他操作系统。

那么我们如何使用 cloud-init 实现这一目标呢?

[版本信息:CentOS:7.8.2003云初始化:18.5]

最佳答案

你应该改变

preserve_hostname: True

preserve_hostname: False

关于cloud - 使用 cloud-init 在 CentOS 上设置主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65328699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com