linux中和salt中的fqdn测试小节

 

设置hosts文件和hostname文件

[root@dawn-hnyd-yd-1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.1.188  dawn-hnyd-yd-1  dawn-hnyd-yd-1.dawnedu.com
[root@dawn-hnyd-yd-1 ~]# cat /etc/hostname 
dawn-hnyd-yd-1
[root@dawn-hnyd-yd-1 ~]# 

 

在salt-ssh机器上执行获取fqdn操作

发现它找的是hosts文件中最长的主机名,优先级高于了hostname文件

[root@linux-node1 /srv/salt/prod/cluster]# salt-ssh '*' grains.get fqdn_ip4
linux-test:
    - 10.0.1.188
[root@linux-node1 /srv/salt/prod/cluster]# salt-ssh '*' grains.get fqdn
linux-test:
    dawn-hnyd-yd-1.dawnedu.com
[root@linux-node1 /srv/salt/prod/cluster]# cat /etc/salt/roster
# Sample salt-ssh config file
linux-test:
  host: 10.0.1.188
  user: root
  passwd: devopsedu.com
  port: 22
  minion_opts:
    grains:  
      proj-role: ha
      ha-role: ha_slave
[root@linux-node1 /srv/salt/prod/cluster]# 

  

 

假如删除测试机器中hosts文件解析

[root@dawn-hnyd-yd-1 ~]# cat /etc/hostname 
dawn-hnyd-yd-1
[root@dawn-hnyd-yd-1 ~]# vim /etc/hosts
[root@dawn-hnyd-yd-1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@dawn-hnyd-yd-1 ~]# 

  

再次测试时发现有缓存,刷新minion端才行。

此时的fqdn用的就是hostname中的了。而不是使用hosts了。

看来hosts文件优先级比hostname文件高,影响fqdn

[root@linux-node1 /srv/salt/prod/cluster]# salt-ssh '*' grains.get fqdn
linux-test:
    dawn-hnyd-yd-1.dawnedu.com
[root@linux-node1 /srv/salt/prod/cluster]# salt-ssh '*' grains.get fqdn
linux-test:
    dawn-hnyd-yd-1.dawnedu.com
[root@linux-node1 /srv/salt/prod/cluster]# salt-ssh '*' saltutil.sync_grains
linux-test:
[root@linux-node1 /srv/salt/prod/cluster]# salt-ssh '*' grains.get fqdn
linux-test:
    dawn-hnyd-yd-1
[root@linux-node1 /srv/salt/prod/cluster]# salt-ssh '*' grains.get fqdn_ip4
linux-test:
    - 10.0.1.188
[root@linux-node1 /srv/salt/prod/cluster]# 

 

 

posted on 2019-02-28 17:15  nmap  阅读(386)  评论(0编辑  收藏  举报

导航