Ubuntu18.04.5不重启的情况下更改主机名并在集群之间能够相互映射
程序员文章站
2024-03-19 22:23:16
...
问题记录:想在不重启Ubuntu18.04.5的情况下更改主机名并在集群之间能够相互映射
(1)查看Ubuntu的版本
cat /proc/version linux内核版本号 gcc编译器版本 Ubuntu版本号
Linux version 5.4.0-42-generic ([email protected])
(gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020
uname -a 显示linux的内核版本和系统是多少位的:X86_64代表系统是64位的
Linux seibigdata-virtual-machine 5.4.0-42-generic #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
lsb_release -a
No LSB modules are available. //类别是ubuntu
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS //发行日期或者是发行版本号
Release: 18.04
Codename: bionic //ubuntu的代号名称
(2)修改主机名
hostnamectl
之前的主机名
1)sudo hostnamectl set-hostname master
master
2)sudo /etc/hosts # 修改之前的主机名为master,并在后面添加其他和自己的主机ip映射
127.0.0.1 localhost
127.0.1.1 master
# 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
172.27.102.191 master
172.27.102.200 slave1
172.27.102.201 slave2
172.27.102.202 slave3
3)ls -l /etc/cloud/cloud.cfg
如果运行上面的语句,显示没有目录,我们修改主机名就已经成功了,否则的话运行4)修改preserve_hostname
4)sudo nano /etc/cloud/cloud.cfg (该步骤可以没有)
preserve_hostname并将值从false更改为true
hostnamectl
master
依次改完其他三台的主机名上操作,改为slave1、slave2、slave3
5)ping slave1 # 可以ping通,映射成功
PING slave1 (172.27.102.200) 56(84) bytes of data.
64 bytes from slave1 (172.27.102.200): icmp_seq=1 ttl=64 time=0.612 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=2 ttl=64 time=0.380 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=3 ttl=64 time=0.374 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=4 ttl=64 time=0.401 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=5 ttl=64 time=0.337 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=6 ttl=64 time=0.260 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=7 ttl=64 time=0.324 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=8 ttl=64 time=0.377 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=9 ttl=64 time=0.306 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=10 ttl=64 time=0.292 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=11 ttl=64 time=0.297 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=12 ttl=64 time=0.361 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=13 ttl=64 time=0.383 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=14 ttl=64 time=0.390 ms
64 bytes from slave1 (172.27.102.200): icmp_seq=15 ttl=64 time=0.364 ms
下一篇: Python遇到的一些小问题