我们可以设置易于记忆的主机名的EC2实例? [英] Can we set easy-to-remember hostnames for EC2 instances?

查看:194
本文介绍了我们可以设置易于记忆的主机名的EC2实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑了几个EC2上的标准的Fedora实例。我觉得由亚马逊指定实例的公共主机名太奇怪,很难记住。我想将其更改为短的东西(如红/蓝/绿/等)。

I'm running a couple of standard Fedora instances on EC2. I feel the public hostnames of the instances assigned by Amazon are too weird and hard to remember. I'd like to change them to something short (like red/blue/green/etc).

有没有拉回在做这个?我如何设置它,这样它重新启动后仍然存在?

Is there any draw back in doing this? And how do I set it up such that it persists after reboots?

感谢。

推荐答案

在开始之前,请尝试运行主机名主机名--fqdn 并注意什么样的反应是。

Before you get started, try running hostname and hostname --fqdn and take note of what the responses are.

您可以编辑的/ etc /主机名,并设置一个主机名,重启后会留下来。您可以强制主机名是重载使用主机名-F的/ etc /主机名来读取值到主机名。 bash提示符将改变后,你登出再登录。

You can edit /etc/hostname and set a hostname, which will stick around after rebooting. You can force the hostname to be "reloaded" by using hostname -F /etc/hostname to read that value into the hostname. The bash prompt will change after you logout and login.

警告/注意
是的,这是不错的,在bash提示符设置为更有用的东西比主机名 IP-123-123-123-123 ,但我已经决定离开矿井(至少目前是这样),因为它似乎是一个很多事情真的指望有在一个标准的方式设置EC2实例的主机名。经过编辑的/ etc /主机名并更改主机名 Web服务器很多服务似乎失败,因为主机会没有解决,和Apache将无法启动。接下来,我修改 / etc / hosts中

warning / note:
Yes, it is nice to have the hostname in the bash prompt set to something more useful than ip-123-123-123-123 but I've decided to leave mine (at least for now) because it seems like a lot of things really count on having the hostname on ec2 instances set in a standard way. After editing /etc/hostname and changing the hostname to webserver a lot of the services seems to fail because the hostname would not resolve, and apache wouldn't start. Next I edited /etc/hosts and added in

127.0.0.1 webserver

作为第二行。阿帕奇然后将启动,但抱怨说,它无法找到FQDN。我证实,运行主机名--fqdn 不再奏效。

接下来,我咨询了男人主机并了解到,虽然你可以设置主机名看来, FQDN 是通过DNS查找返回。

Next I consulted man hostname and learned that while you can set the hostname it appears that the FQDN is what is returned via a DNS lookup.

您不能改变的FQDN(如返回的主机名--fqdn)或DNS域名(如返回dnsdomainname文件)使用此命令。该系统的FQDN是,分解器(3)返回的主机名的名称

THE FQDN

You can't change the FQDN (as returned by hostname --fqdn) or the DNS domain name (as returned by dnsdomainname) with this command. The FQDN of the system is the name that the resolver(3) returns for the host name.

从技术上讲:此FQDN名的getaddrinfo(3)返回由的gethostname(2)返回的主机名。 DNS域名是第一个点之后的部分。

Technically: The FQDN is the name getaddrinfo(3) returns for the host name returned by gethostname(2). The DNS domain name is the part after the first dot.

因此​​,它取决于配置(通常在/etc/host.conf中),你可以如何改变它。通常(如果主机文件DNS或NIS之前解析),你可以在/ etc / hosts中改变它。

Therefore it depends on the configuration (usually in /etc/host.conf) how you can change it. Usually (if the hosts file is parsed before DNS or NIS) you can change it in /etc/hosts.

我想可能是可以设置系统/骗过系统进入返回FQDN,像 IP-123-123-123-123.ec2.internal 尽管主机名是 Web服务器但在这一点上,它开始看起来更多的麻烦比它的价值,这对我来说有一个更好的bash提示符可能会造成大量的软件和配置问题的道路,所以我决定放弃。

I think it might be possible to set the system / fool the system into return the FQDN, something like ip-123-123-123-123.ec2.internal even though the hostname is webserver but at this point it started to seem like more trouble than it was worth, and that for me to have a nicer bash prompt might cause a lot software and configuration problems down the road and so I decided to give up.

我也学到了很多的Amazon EC2实例中使用一种叫做云初始化

I also learned that a lot of amazon ec2 instances use something called cloud-init:

云初始化是Ubuntu的软件包处理云实例早期初始化。它安装在Ubuntu的云图,并在官方提供的EC2 Ubuntu的图片。

cloud-init is the Ubuntu package that handles early initialization of a cloud instance. It is installed in the Ubuntu Cloud Images and also in the official Ubuntu images available on EC2.

它的一些配置的事情是:

Some of the things it configures are:

      
  • 设置默认的语言环境
  •   
  • 设置主机名
  •   
  • 在生成的SSH私钥
  •   
  • 添加SSH密钥到用户的.ssh / authorized_keys中,使他们可以登录
  •   
  • 设置临时安装点
  •   
  • setting a default locale
  • setting hostname
  • generate ssh private keys
  • adding ssh keys to user's .ssh/authorized_keys so they can log in
  • setting up ephemeral mount points

云-init的行为可以通过用户数据进行配置。用户的数据可以通过在实例启动时用户给出。这是通过--user-data或--user数据文件参数EC2-运行情况做了

cloud-init's behavior can be configured via user-data. User-data can be given by the user at instance launch time. This is done via the --user-data or --user-data-file argument to ec2-run-instances

我也发现了这个其中谈到如何主机配置了云初始化:

I also found this which talks about how the hostname is configured with cloud-init:

在EBS情况下,关机,后来开始就结束了一个不同的IP地址。

On EBS instances, a shutdown and later start would end up with a different IP address.

在其中用户已经不从其原始值改性的/ etc /主机名的情况下(由元数据的本地主机名'接种),则云初始化将再次设置主机名和更新的/ etc /主机名。

In the case where the user has not modified /etc/hostname from its original value (seeded by metadata's 'local-hostname'), then cloud-init will again set the hostname and update /etc/hostname.

在其中用户已经修改的/ etc /主机名的情况下,将保持用户进行管理。

In the case where the user has modified /etc/hostname, it will remain user managed.

此外,如果/etc/cloud/cloud.cfg包含'preserve_hostname'值设置为true,那么在/ etc /主机名永远不会被触及。

Additionally, if /etc/cloud/cloud.cfg contains 'preserve_hostname' value set to a True value, then /etc/hostname will not ever be touched.

有趣的外卖是,如果你不改变主机的云初始化包将保持最新的为您服务。

The interesting takeaway is that if you don't change the hostname the cloud-init package will keep it up to date for you.

如果别人有一种变通方法,也可以解决一些提到的问题,并帮助安抚,没有什么会打破,因为更改主机名,我很乐意听到它的EC2实例。

If someone else has a workaround or can address some of the issues mentioned and help reassure that nothing will break on ec2 instances because of changing the hostname I would be happy to hear it.

这篇关于我们可以设置易于记忆的主机名的EC2实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆