ubuntu虚拟机克隆后需要进行的修改

在虚拟化中,如果采用机器克隆的情况,使用同一个主机名和系统id会造成机器冲突,需要进行主机名修改和机器id重置

1. 修改系统IP地址信息

  • 新版本使用netplan配置主机IP地址
ubuntu@ubuntu:~$ cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens160:
      addresses:
      - 192.168.63.31/24 		#配置主机IP地址
      gateway4: 192.168.63.1	#配置主机网关
      nameservers:
        addresses:
        - 192.168.64.3 			#配置主机主DNS
        - 223.5.5.5				#配置主机备DNS
        search: []
  version: 2

  • 配置完成后应用配置
root@ubuntu:~# netplan apply
  • 配置完成后的地址查看
root@ubuntu:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:9b:9c:48 brd ff:ff:ff:ff:ff:ff
    inet 192.168.63.31/24 brd 192.168.63.255 scope global ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe9b:9c48/64 scope link
       valid_lft forever preferred_lft forever
root@ubuntu:~#

2. 修改主机名

  • 克隆后的虚拟机,名字与模板一致,容易造成冲突,需要进行修改
root@ubuntu:~# hostnamectl
   Static hostname: ubuntu
Transient hostname: clt
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 25648f8254ff40be8832c34fd4744d35
           Boot ID: 191c8d415c854021aea170d7a7a9b863
    Virtualization: vmware
  Operating System: Ubuntu 20.04.6 LTS
            Kernel: Linux 5.4.0-146-generic
      Architecture: x86-64
root@ubuntu:~#
  • 修改主机名
root@ubuntu:~# hostnamectl set-hostname docker.sec.local
root@ubuntu:~# hostnamectl
   Static hostname: docker.sec.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 25648f8254ff40be8832c34fd4744d35
           Boot ID: 191c8d415c854021aea170d7a7a9b863
    Virtualization: vmware
  Operating System: Ubuntu 20.04.6 LTS
            Kernel: Linux 5.4.0-146-generic
      Architecture: x86-64
root@ubuntu:~#

3. 修改machine-id

  • ubuntu默认会带有machine-id,所有克隆出来的主机都和模板上的机器一致
root@ubuntu:~# hostnamectl
   Static hostname: docker.sec.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 25648f8254ff40be8832c34fd4744d35 	#默认生成的Machine ID
           Boot ID: 191c8d415c854021aea170d7a7a9b863
    Virtualization: vmware
  Operating System: Ubuntu 20.04.6 LTS
            Kernel: Linux 5.4.0-146-generic
      Architecture: x86-64
root@ubuntu:~#

  • 修改或者删除原有模板内的Machine ID
root@ubuntu:~# rm -f /etc/machine-id
root@ubuntu:~# systemd-machine-id-setup
Initializing machine ID from random generator.
root@ubuntu:~#

root@ubuntu:~# hostnamectl
   Static hostname: docker.sec.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 17958315705a4d1d94899f826d844a23	#生成新的ID值
           Boot ID: 191c8d415c854021aea170d7a7a9b863
    Virtualization: vmware
  Operating System: Ubuntu 20.04.6 LTS
            Kernel: Linux 5.4.0-146-generic
      Architecture: x86-64
root@ubuntu:~#

posted @ 2024-03-08 22:41  二乘八是十六  阅读(335)  评论(0编辑  收藏  举报