奇怪的事情发生了。我们的 Web 服务器中的系统主机名每分钟左右都会发生变化。以下是输出journalctl --since 09:00 | grep hostname
:
May 15 10:45:37 bbbbbb.example.com NetworkManager[711]: <info> Setting system hostname to 'bbbbbb.example.com' (from address lookup)
May 15 10:45:37 bbbbbb.example.com nm-dispatcher[18819]: Dispatching action 'hostname'
May 15 10:46:22 aaa.example.com NetworkManager[711]: <info> Setting system hostname to 'aaa.example.com' (from address lookup)
May 15 10:46:22 aaa.example.com nm-dispatcher[18991]: Dispatching action 'hostname'
May 15 10:47:07 bbbbbb.example.com NetworkManager[711]: <info> Setting system hostname to 'bbbbbb.example.com' (from address lookup)
May 15 10:47:07 bbbbbb.example.com nm-dispatcher[19112]: Dispatching action 'hostname'
May 15 10:47:52 aaa.example.com NetworkManager[711]: <info> Setting system hostname to 'aaa.example.com' (from address lookup)
May 15 10:47:52 aaa.example.com nm-dispatcher[19362]: Dispatching action 'hostname'
May 15 10:53:37 bbbbbb.example.com NetworkManager[711]: <info> Setting system hostname to 'bbbbbb.example.com' (from address lookup)
May 15 10:53:37 bbbbbb.example.com nm-dispatcher[20372]: Dispatching action 'hostname'
May 15 10:54:22 aaa.example.com NetworkManager[711]: <info> Setting system hostname to 'aaa.example.com' (from address lookup)
May 15 10:54:22 aaa.example.com nm-dispatcher[20495]: Dispatching action 'hostname'
May 15 10:55:07 bbbbbb.example.com NetworkManager[711]: <info> Setting system hostname to 'bbbbbb.example.com' (from address lookup)
May 15 10:55:07 bbbbbb.example.com nm-dispatcher[20596]: Dispatching action 'hostname'
May 15 11:01:37 aaa.example.com NetworkManager[711]: <info> Setting system hostname to 'aaa.example.com' (from address lookup)
May 15 11:01:37 aaa.example.com nm-dispatcher[21988]: Dispatching action 'hostname'
May 15 11:02:22 bbbbbb.example.com NetworkManager[711]: <info> Setting system hostname to 'bbbbbb.example.com' (from address lookup)
May 15 11:02:22 bbbbbb.example.com nm-dispatcher[22116]: Dispatching action 'hostname'
May 15 11:03:07 aaa.example.com NetworkManager[711]: <info> Setting system hostname to 'aaa.example.com' (from address lookup)
May 15 11:03:07 aaa.example.com nm-dispatcher[22248]: Dispatching action 'hostname'
May 15 11:10:22 bbbbbb.example.com NetworkManager[711]: <info> Setting system hostname to 'bbbbbb.example.com' (from address lookup)
May 15 11:10:22 bbbbbb.example.com nm-dispatcher[23507]: Dispatching action 'hostname'
这种情况已经持续了好几周了!我该怎么办?
/etc/hosts 是这样的:
127.0.0.1 localhost localhost.localdomain
127.0.0.1 www.example.com
127.0.0.1 adm.examplegroup.com
// I removed these 2 lines
127.0.0.1 aaa.example.com
127.0.0.1 bbbbbb.example.com
127.0.0.1 example.com
答案1
我相信您通过删除这两行已经解决了问题。
他们根本就不应该出现在那里。
在 Windows 世界中,这种情况永远不会发生,因为内核修复了主机名,并且不需要在其 hosts 文件中声明。
但在 unix 或 Linux 中,必须声明主机域,并且不能在同一级别定义多个(即如上所示的多个子域定义)。底部的那个是正确的,并且与包含 www 的那个不冲突。
那么接下来该做什么:至少需要保护 hosts 文件以防止未经授权的更改。
也许这是一个错误。或者可能是某种测试。但 hosts 文件不是进行实验的地方,尤其是在生产服务器中。
我假设你已经在 /etc/hostname 中设置了正确的域名
很高兴你发现了这个问题。