![ec2 ubuntu 服务器 18.04 上出现 Cloud-init 相关错误](https://linux22.com/image/1018306/ec2%20ubuntu%20%E6%9C%8D%E5%8A%A1%E5%99%A8%2018.04%20%E4%B8%8A%E5%87%BA%E7%8E%B0%20Cloud-init%20%E7%9B%B8%E5%85%B3%E9%94%99%E8%AF%AF.png)
我的 EC2 Ubuntu 18.04 服务器上出现以下错误。如果有人知道原因和解决方案,请帮助我。
当我尝试时Cloud-init status
我得到了status: error
结果。
下面显示的错误日志来自/var/log/cloud-init-output.log
:
Cloud-init v. 19.4-33-gbb4131a2-0ubuntu1~18.04.1 running 'init-local' at Fri, 01 May 2020 13:12:14 +0000. Up 8.38 seconds.
2020-05-01 13:12:14,988 - util.py[WARNING]: failed stage init-local
failed run of stage init-local
------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 653, in status_wrapper
ret = functor(name, args)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 323, in main_init
init.fetch(existing=existing)
File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 352, in fetch
return self._get_data_source(existing=existing)
File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 253, in _get_data_source
util.del_file(self.paths.instance_link)
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1793, in del_file
raise e
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1790, in del_file
os.unlink(path)
IsADirectoryError: [Errno 21] Is a directory: '/var/lib/cloud/instance'
------------------------------------------------------------
Cloud-init v. 19.4-33-gbb4131a2-0ubuntu1~18.04.1 running 'init-local' at Fri, 01 May 2020 18:10:43 +0000. Up 8.08 seconds.
2020-05-01 18:10:43,999 - util.py[WARNING]: failed stage init-local
failed run of stage init-local
------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 653, in status_wrapper
ret = functor(name, args)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 323, in main_init
init.fetch(existing=existing)
File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 352, in fetch
return self._get_data_source(existing=existing)
File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 253, in _get_data_source
util.del_file(self.paths.instance_link)
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1793, in del_file
raise e
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1790, in del_file
os.unlink(path)
IsADirectoryError: [Errno 21] Is a directory: '/var/lib/cloud/instance'
目前,服务器已经正常运行。
ubuntu@host:~$ sudo cat /etc/netplan/*.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. 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:
eth0:
dhcp4: true
match:
macaddress: 02:9e:ef:ad:39:1a
set-name: eth0
version: 2
ubuntu@host:~$ ls -lah /etc/netplan/
total 20K
drwxr-xr-x 2 root root 4.0K May 18 04:10 .
drwxr-xr-x 117 root root 12K Jun 2 06:32 ..
-rw-r--r-- 1 root root 481 Jun 1 09:51 50-cloud-init.yaml
ubuntu@host:~$ sudo lshw -C network
*-network
description: Ethernet interface
physical id: 1
logical name: eth0
serial: 02:9e:ef:ad:39:1a
capabilities: ethernet physical
configuration: broadcast=yes driver=vif ip=172.31.1.160 link=yes multicast=yes
=========我在其他服务器上执行的解决方案如下所示============
ref. link = https://cloudinit.readthedocs.io/en/latest/topics/faq.html
$ sudo DI_LOG=stderr /usr/lib/cloud-init/ds-identify --force
$ sudo cloud-init clean --logs
$ sudo cloud-init init --local
$ sudo cloud-init init
@heynnema Below the output of cat /etc/netplan/*.yaml
root@ip-172-31-1-135:/# cat /etc/netplan/*.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. 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:
ens5:
dhcp4: true
match:
macaddress: 02:69:72:f4:1e:aa
set-name: ens5
version: 2
答案1
我的理解是 AWS EC2 需要桥接。请尝试这个 .yaml 文件。保持精确的间距、缩进,并且不要使用制表符,因为 netplan 非常挑剔。
笔记:保留当前 .yaml 文件的备份,以防万一。
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. 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:
version: 2
renderer: networkd
ethernets:
eth0:
match:
macaddress: 02:9e:ef:ad:39:1a
set-name: eth0
bridges:
br0:
dhcp4: true
macaddress: 02:9e:ef:ad:39:1a
interfaces:
- eth0
笔记:您可能需要创建/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}
sudo netplan --debug generate
sudo netplan apply
reboot
# 强制的
更新#1:
OP 找到了下面解决该问题的命令......
$ sudo DI_LOG=stderr /usr/lib/cloud-init/ds-identify --force
$ sudo cloud-init clean --logs
$ sudo cloud-init init --local
$ sudo cloud-init init
来源:https://cloudinit.readthedocs.io/en/latest/topics/faq.html