puppet故障分析Host is missing hostname and/or domain

这几天公司一个同事在研究puppet的过程中 puppetmaster端的日志里面老是报hostname错误,×××找了点资料并查看了源代码,最终解决了此类问题,特此分享!

问题故障:

以下是puppetmaster端 /var/log/message中报的信息

Mar 24 03:15:17 puppet-master puppet-master[26327]: Host is missing hostname and/or domain: www.app-node3.com
Mar 24 03:15:17 puppet-master puppet-master[26327]: Compiled catalog for www.app-node3.com in environment production in 0.08 seconds
Mar 24 03:15:30 puppet-master puppet-master[26327]: Host is missing hostname and/or domain: www.app-node3.com
Mar 24 03:15:30 puppet-master puppet-master[26327]: Compiled catalog for www.app-node3.com in environment production in 0.05 seconds
Mar 24 03:15:43 puppet-master puppet-master[26327]: Host is missing hostname and/or domain: www.app-node3.com
Mar 24 03:15:43 puppet-master puppet-master[26327]: Compiled catalog for www.app-node3.com in environment production in 0.05 seconds
Mar 24 03:15:48 puppet-master puppet-master[26327]: Host is missing hostname and/or domain: www.app-node3.com
Mar 24 03:15:48 puppet-master puppet-master[26327]: Compiled catalog for www.app-node3.com in environment production in 0.05 seconds

故障分析

初步分析一:

从错误分析来看应该是主机名或者域名有问题导致的, 而客户的主机名为puppet-master,certname为puppet-master.puppet.com,查过一些资料发现,puppet不允许命名自己的certname为puppet,puppet.com,所以导致了此类问题。

更改为其它名称后故障依旧

继续分析二:

既然报同样的错误 “Host is missing hostname and/or domain:”,说明这关键词在代码中是存在的,那么就分析代码吧。

1、首先先查找这段关键词在那个文件中

[root@puppetmaster ~]# grep "Host is missing hostname" `rpm -ql puppet`
grep: /etc/puppet/puppetca.conf: No such file or directory
grep: /etc/puppet/puppetd.conf: No such file or directory
/usr/lib/ruby/site_ruby/1.8/puppet/node.rb:        Puppet.warning "Host is missing hostname and/or domain: #{name}"

2、查看代码报错原因

[root@puppetmaster ~]# vim /usr/lib/ruby/site_ruby/1.8/puppet/node.rb
112     # First, get the fqdn
113     unless fqdn = parameters["fqdn"]
114       if parameters["hostname"] and parameters["domain"]
115         fqdn = parameters["hostname"] + "." + parameters["domain"]
116       else
117         Puppet.warning "Host is missing hostname and/or domain: #{name}"
118       end
119     end
120
121     # Now that we (might) have the fqdn, add each piece to the name
122     # list to search, in order of longest to shortest.

原因很简单,代码的意思是为了保证另外一个fact fqdn的存在,只有当hostname和domain两个fact都存在的情况下才可以,否则就会报错Puppet.warning "Host is missing hostname and/or domain: #{name}"

3、再次验证原因

从以下可以看出节点只能过来出来fact hostname

[root@puppetmaster ~]# facter | egrep -i 'hostname|domain|fqdn'
hostname => puppetmaster

解决方法

1、所有节点/etc/resolve.conf中加上domain

[root@puppetmaster ~]# vim /etc/resolv.conf
; generated by /sbin/dhclient-script
#nameserver 202.96.209.5
#nameserver 202.96.209.133
domain lixs.com

再次验证

[root@puppetmaster ~]# facter | egrep -i 'hostname|domain|fqdn'
domain => lixs.com
fqdn => puppetmaster.lixs.com
hostname => puppetmaster

2、修改node.rb代码,然后通过file资源推下去

2.1、删除以下代码

删除之后,就不存在fqdn这个fact了

# First, get the fqdn
unless fqdn = parameters["fqdn"]
  if parameters["hostname"] and parameters["domain"]
    fqdn = parameters["hostname"] + "." + parameters["domain"]
  else
    Puppet.warning "Host is missing hostname and/or domain: #{name}"
  end
end

2.2、去掉if判断语句,设置fqdn = 你设置的值

比如自定义的certname,不过节点一定要有自己设置的fact哦。

# First, get the fqdn
unless fqdn = parameters["fqdn"]
    fqdn = parameters["fact_certname"]
end

后记:不过这也不是一个错误,只不过是fact fqdn取不出来报的一个警告信息,如果你不管也没关系,只不过在message中会不停的多出这些垃圾信息,时间长了挺占空间的,呵呵!

返回主目录

交流方式:

微信公众号:puppet2014,可微信搜索加入,也可以扫描以下二维码进行加入

微信公众号

QQ交流群:296934942

Puppet_Errors
puppet常见错误, puppet故障分析, puppet troubleshooting, puppet错误分析