ECS怎样安装 cloud-init-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

ECS怎样安装 cloud-init

boxti 2017-10-18 14:02:59 1754

在导入镜像时,为了保证导入的镜像 hostname、NTP 和 Yum 源配置成功,建议您先在实例上安装 cloud-init。目前 cloud-init 支持的系统包括:CentOS、Debian、Fedora、FreeBSD、Gentoo、RHEL(Red Hat Enterprise Linux)、SLES(SUSE Linux Enterprise Server)和 Ubuntu。
本文介绍了如何安装 cloud-init。

前提条件


您的实例中应该已经安装了:

  • git:用于下载 cloud-init 源码包。

    安装命令:yum install git。

  • python2.7:是 cloud-init 运行和安装的基础。

    安装命令:yum install python。

  • pip:用于安装一些 python2.7 里缺少但是 cloud-init 依赖的库。

    安装命令:yum install python-pip。

由于不同系统包管理器不一样,这里只列举了 yum 方式。对于 zypper 或者 apt-get 的包管理器安装方式类似。

操作步骤


您可以按以下步骤安装 cloud-init。

  1. 执行以下命令从 cloud-init 官网下载 cloud-init 源码包。[backcolor=transparent]git clone https[backcolor=transparent]:[backcolor=transparent]//git.launchpad.net/cloud-init

执行以下命令进入 cloud-init 目录。
  1. [backcolor=transparent]cd cloud[backcolor=transparent]-[backcolor=transparent]init

运行以下命令安装 cloud-init 的安装文件 setup.py。
  1. [backcolor=transparent]python setup[backcolor=transparent].[backcolor=transparent]py install

安装过程中,如果出现以下信息,表示 Python 缺少 six 和 oauthlib 库。您可以使用 pip 安装 six 库:pip install six。
  1. [backcolor=transparent][[backcolor=transparent]root@iXXXXXX cloud[backcolor=transparent]-[backcolor=transparent]init[backcolor=transparent]]#[backcolor=transparent] python setup[backcolor=transparent].[backcolor=transparent]py install
  2. [backcolor=transparent]Traceback[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]most recent call [backcolor=transparent]last[backcolor=transparent]):
  3. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"setup.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]127[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  4. [backcolor=transparent] glob[backcolor=transparent]([backcolor=transparent]'systemd/*.target'[backcolor=transparent]))[backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] is_f[backcolor=transparent]([backcolor=transparent]f[backcolor=transparent])],
  5. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"setup.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]114[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] render_tmpl
  6. [backcolor=transparent] tiny_p[backcolor=transparent]([[backcolor=transparent]sys[backcolor=transparent].[backcolor=transparent]executable[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'./tools/render-cloudcfg'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]template[backcolor=transparent],[backcolor=transparent] fpath[backcolor=transparent]])
  7. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"setup.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]45[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] tiny_p
  8. [backcolor=transparent] [backcolor=transparent]([backcolor=transparent]cmd[backcolor=transparent],[backcolor=transparent] ret[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]out[backcolor=transparent],[backcolor=transparent] err[backcolor=transparent]))
  9. [backcolor=transparent]RuntimeError[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]Failed[backcolor=transparent] running [backcolor=transparent][[backcolor=transparent]'/usr/bin/python'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'./tools/render-cloudcfg'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'systemd/cloud-config.service.tmpl'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'tmpXX25hU/cloud-config.service'[backcolor=transparent]][backcolor=transparent] [backcolor=transparent][[backcolor=transparent]rc[backcolor=transparent]=[backcolor=transparent]1[backcolor=transparent]][backcolor=transparent] [backcolor=transparent](,[backcolor=transparent] [backcolor=transparent]Traceback[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]most recent call [backcolor=transparent]last[backcolor=transparent]):
  10. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"./tools/render-cloudcfg"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]10[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  11. [backcolor=transparent] [backcolor=transparent]from[backcolor=transparent] cloudinit [backcolor=transparent]import[backcolor=transparent] templater
  12. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"/root/cloud-init/cloudinit/templater.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]29[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  13. [backcolor=transparent] [backcolor=transparent]from[backcolor=transparent] cloudinit [backcolor=transparent]import[backcolor=transparent] log [backcolor=transparent]as[backcolor=transparent] logging
  14. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"/root/cloud-init/cloudinit/log.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]19[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  15. [backcolor=transparent] [backcolor=transparent]import[backcolor=transparent] six
  16. [backcolor=transparent]ImportError[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]No[backcolor=transparent] [backcolor=transparent]module[backcolor=transparent] named six
  17. [backcolor=transparent])

安装过程中,如果出现以下信息,表示 Python 缺少 oauthlib 库。您可以使用 pip 安装 oauthlib 库:pip install oauthlib。
  1. [backcolor=transparent][[backcolor=transparent]root@iXXXXXX cloud[backcolor=transparent]-[backcolor=transparent]init[backcolor=transparent]]#[backcolor=transparent] python setup[backcolor=transparent].[backcolor=transparent]py install
  2. [backcolor=transparent]Traceback[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]most recent call [backcolor=transparent]last[backcolor=transparent]):
  3. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"setup.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]127[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  4. [backcolor=transparent] glob[backcolor=transparent]([backcolor=transparent]'systemd/*.target'[backcolor=transparent]))[backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] is_f[backcolor=transparent]([backcolor=transparent]f[backcolor=transparent])],
  5. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"setup.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]114[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] render_tmpl
  6. [backcolor=transparent] tiny_p[backcolor=transparent]([[backcolor=transparent]sys[backcolor=transparent].[backcolor=transparent]executable[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'./tools/render-cloudcfg'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]template[backcolor=transparent],[backcolor=transparent] fpath[backcolor=transparent]])
  7. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"setup.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]45[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] tiny_p
  8. [backcolor=transparent] [backcolor=transparent]([backcolor=transparent]cmd[backcolor=transparent],[backcolor=transparent] ret[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]out[backcolor=transparent],[backcolor=transparent] err[backcolor=transparent]))
  9. [backcolor=transparent]RuntimeError[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]Failed[backcolor=transparent] running [backcolor=transparent][[backcolor=transparent]'/usr/bin/python'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'./tools/render-cloudcfg'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'systemd/cloud-config.service.tmpl'[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]'tmpUrhrOM/cloud-config.service'[backcolor=transparent]][backcolor=transparent] [backcolor=transparent][[backcolor=transparent]rc[backcolor=transparent]=[backcolor=transparent]1[backcolor=transparent]][backcolor=transparent] [backcolor=transparent](,[backcolor=transparent] [backcolor=transparent]Traceback[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]most recent call [backcolor=transparent]last[backcolor=transparent]):
  10. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"./tools/render-cloudcfg"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]10[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  11. [backcolor=transparent] [backcolor=transparent]from[backcolor=transparent] cloudinit [backcolor=transparent]import[backcolor=transparent] templater
  12. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"/root/cloud-init/cloudinit/templater.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]31[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  13. [backcolor=transparent] [backcolor=transparent]from[backcolor=transparent] cloudinit [backcolor=transparent]import[backcolor=transparent] util
  14. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"/root/cloud-init/cloudinit/util.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]48[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  15. [backcolor=transparent] [backcolor=transparent]from[backcolor=transparent] cloudinit [backcolor=transparent]import[backcolor=transparent] url_helper
  16. [backcolor=transparent]File[backcolor=transparent] [backcolor=transparent]"/root/cloud-init/cloudinit/url_helper.py"[backcolor=transparent],[backcolor=transparent] line [backcolor=transparent]20[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]in[backcolor=transparent] [backcolor=transparent]<module>
  17. [backcolor=transparent] [backcolor=transparent]import[backcolor=transparent] oauthlib[backcolor=transparent].[backcolor=transparent]oauth1 [backcolor=transparent]as[backcolor=transparent] oauth1
  18. [backcolor=transparent]ImportError[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]No[backcolor=transparent] [backcolor=transparent]module[backcolor=transparent] named oauthlib[backcolor=transparent].[backcolor=transparent]oauth1
  19. [backcolor=transparent])

[backcolor=transparent]注意:不同系统缺少的库可能不同,您都可以通过 pip 安装,安装完之后再次执行 python setup.py install。

至此,您已经完成了 cloud-init 安装。
弹性计算 Ubuntu Unix Linux 开发工具 git Python
分享到
取消 提交回答
全部回答(0)
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题