admin avatar

不要在pve环境中安装cloud-init,以及安装cloud-init后pve失联的解决方法

🕛 by admin

不要在pve服务器环境中安装cloud-init,以及安装cloud-init后pve失联的解决方法

说三遍,cloud-init在虚拟机中安装,cloud-init在虚拟机中安装,cloud-init在虚拟机中安装

pve官网说的很清楚,“此命令不打算在Proxmox VE主机上执行,而仅在虚拟机内执行。”

当时没有仔细查看文档,导致服务器下线了块36小时。

https://pve.proxmox.com/wiki/Cloud-Init_Support

如果在pve服务器环境中安装了cloud-init,大概率服务器会失联,原因很简单,cloud-init会接管网络

导致在pve配置的网络失效,从而导致pve失联。解决方法如下

从厂商控制后台开启救援模式,挂载硬盘root分区文件

mount /dev/md3 /mnt #查看分区信息 fdisk -l

编辑/var/spool/cron/crontabs/root,添加以下代码

1
2
3
4
#@reboot systemctl stop nftables.service
#@reboot systemctl start sshd.service
#@reboot apt purge cloud-init -y
#@reboot systemctl disable cloud-init-local cloud-init cloud-config cloud-final && systemctl stop cloud-init-local cloud-init cloud-config cloud-final 

编辑/etc/network/interfaces.d/50-cloud-init文件

ubuntu系统的cloud-init文件路径如下

/etc/netplan/50-cloud-init.yaml

安装了cloud-init就会出现50-cloud-init文件,就是这个文件接管了服务器网络,导致失联

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        ens33:
            addresses: [192.168.2.100/24]
            dhcp4: no
            gateway4: 192.168.2.1
            nameservers :
                    addresses: [8.8.8.8]
    version: 2

删除# network: {config: disabled}前面的#号,即表示关闭网络自动配置

重启服务器,没什么意外的话就可连接到服务器了,登录服务器后要卸载cloud-init

1
2
3
4
5
systemctl disable cloud-init-local cloud-init cloud-config cloud-final
  systemctl stop cloud-init-local cloud-init cloud-config cloud-final
sudo apt purge cloud-init -y
sudo rm -rf /etc/cloud && sudo rm -rf /var/lib/cloud/

再次重启服务器即可。

💘 相关文章

写一条评论