简体   繁体   English

在AWS OpsWorks(Chef)中更改主机名

[英]Change hostname in AWS OpsWorks (Chef)

In AWS OpsWorks, I'm using this community hostname cookbook. 在AWS OpsWorks中,我正在使用此社区主机名食谱。 To set my hostname to append a domain to it. 设置我的主机名以将域附加到该主机名。

Original FQDN: apple-pie.localdomain 原始FQDN: apple-pie.localdomain

node.default["set_fqdn"] = "*.example.com"
include_recipe 'hostname'

Changes to FQDN: apple-pie.localdomain.example.com 对FQDN的更改: apple-pie.localdomain.example.com

However, after about 10 mins, the hostname goes back to the original hostname without my domain append. 但是,大约10分钟后,主机名将恢复为原始主机名,而没有附加我的域。

I've checked the OpsWorks lifecycle: 我检查了OpsWorks生命周期:

After a new instance finishes booting, AWS OpsWorks does the following: 新实例完成启动后,AWS OpsWorks将执行以下操作:

  1. Runs the built-in Setup recipes. 运行内置的安装程序配方。

  2. Runs any custom Setup recipes. 运行任何自定义安装程序配方。

  3. Runs the built-in Deploy recipes. 运行内置的“部署”配方。

  4. Runs any custom Deploy recipes. 运行任何自定义的部署配方。

And I'm running the recipe in my custom Deploy recipe, so it should be the last thing that runs. 我正在自定义“部署”配方中运行该配方,因此它应该是最后运行的东西。 No idea why/how it gets reset to the original hostname. 不知道为什么/如何将其重置为原始主机名。

Thanks! 谢谢!

I figured it out. 我想到了。 You're suppose to override the default template in Chef that AWS provides. 您假设将覆盖AWS提供的Chef中的默认模板。

Extending AWS OpsWorks Configuration Files Using Custom Templates 使用自定义模板扩展AWS OpsWorks配置文件

So in my cookbook, I made a file called: 因此,在我的食谱中,我创建了一个名为:

opsworks_stack_state_sync/templates/default/hosts.erb opsworks_stack_state_sync /模板/默认/ hosts.erb

Add the file looks like this: 添加文件如下所示:

# This file was generated by OpsWorks
# any manual changes will be removed on the next update.

# Set the hostname with proper format, the rest are aliases.
127.0.0.1 localhost localhost.example.com
127.0.1.1 <%= node[:opsworks][:instance][:hostname] %>.example.com <%= node[:opsworks][:instance][:hostname] %>

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

# OpsWorks Layer State
<% seen = [] -%>
<% node[:opsworks][:layers].each do |layer_name, layer_config| -%>
<% layer_config[:instances].each do |instance_name, instance_config| -%>
<% if !seen.include?(instance_name) && instance_config[:private_ip] -%>
<%= Resolv.getaddress(instance_config[:private_ip]) %> <%= instance_name %>
<% if instance_config[:ip] %>
<%= Resolv.getaddress(instance_config[:ip]) %> <%= instance_name %>-ext
<% end %>
<% seen << instance_name %>
<% end -%>
<% end -%>
<% end -%>

And that will set your hostname to apple-pie.example.com . 然后将您的主机名设置为apple-pie.example.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM