Cloud-Init操作类 本节为您介绍镜像服务常见的cloudinit操作类问题。 安装CloudInit FAQ Cloudinit能做什么 cloudinit是一款用于初始化云主机的工具,它拥有丰富的模块,能够为云主机提供的能力有:初始化密码、扩容根分区、设置主机名、注入公钥、执行自定义脚本等等,功能十分强大。 安装cloudinit 检查是否已经安装CloudInit工具。 不同的操作系统,命令不同,以centos为例,执行以下命令查看系统是否已经安装cloudinit: plaintext rpm qa grep cloudinit 安装cloudinit 无明确版本要求,建议安装系统源上的版本(若采用旧有编译安装,则建议在大更改时重做为系统源版本)。 采用以下命令安装: plaintext yum install cloudinit cloudutilsgrowpart y 配置cloudinit 默认的cloud.cfg配置文件/etc/cloud/cloud.cfg修改如下(不同操作系统会有不同,根据实际情况来定需要设置的值): 1. 确定参数值如下:true/True/1,false/False/0 均可。 plaintext disableroot: false sshpwauth: true sshdeletekeys: false preservehostname: false 若 cloudinit 版本 > 21.1(参考 cloudinit v), 在配置文件中,preserverhostname: false 另起一行(或保证缩进同级即可),加上: plaintext Preferfqdnoverhostname: true 若cloudinit 版本 < 21.1, 修改 cloudinit python 包源码 cloudinit/distros/ init .py,将: plaintext defselecthostname (self,hostname,fqdn) : Prefer the short hostname over the long