如果您有通过已有镜像配置云服务器 ECS 的需求,您可以在阿里云云平台通过导入镜像功能完成配置。在导入 Linux 类型镜像时,为了保证导入的镜像 hostname、NTP 和 Yum 源配置成功,建议您预先在源服务器、虚拟机或者云主机上安装 cloud-init。
目前,支持安装 cloud-init 的 Linux 发行版包括:
您的源服务器、虚拟机或者云主机必须安装以下软件。
git:用于下载 cloud-init 源码包。
yum 安装方式:
yum install git
。
python2.7:是 cloud-init 运行和安装的基础。
yum 安装方式:
yum install python
。
pip:用于安装一些 python2.7 里缺少但是 cloud-init 依赖的库。
yum 安装方式:
yum install python-pip
。
此处列举了 yum
安装方式。zypper
或者 apt-get
的包管理器安装方式与 yum
安装方式类似。
您可以按以下步骤安装 cloud-init:
远程连接到待导入镜像的源服务器、虚拟机或者云主机。如果您的云主机是 ECS 实例,请参阅 远程连接到 Linux 实例。
运行 git clone https://git.launchpad.net/cloud-init
从 cloud-init 官网下载 cloud-init 源码包。
运行 cd cloud-init
进入 cloud-init 目录。
运行 python setup.py install
安装 cloud-init 的安装文件 setup.py。
运行 vi /etc/cloud/cloud.cfg
修改配置文件 cloud.cfg。
将 cloud_init_modules
之前的配置修改成如下:
# Example datasource config
# The top level settings are used as module
# and system configuration.
# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
- default
user:
name: root
lock_passwd: False
# If this is set, 'root' will not be able to ssh in and they
# will get a message to login instead as the above $user
disable_root: false
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false
syslog_fix_perms: root:root
datasource_list: [ AliYun ]
# Example datasource config
datasource:
AliYun:
support_xen: false
timeout: 5 # (defaults to 50 seconds)
max_wait: 60 # (defaults to 120 seconds)
# metadata_urls: [ 'blah.com' ]
# The modules that run in the 'init' stage
cloud_init_modules:
注意:
不同系统缺少的库可能不同,您都可以通过 pip 安装,安装完之后再次执行python setup.py install
。
安装过程中,如果出现以下信息,表示 Python 缺少 six 库。您可以使用 pip 安装 six 库:pip install six
。
File "/root/cloud-init/cloudinit/log.py", line 19, in <module>
import six
ImportError: No module named six
)
安装过程中,如果出现以下信息,表示 Python 缺少 oauthlib 库。您可以使用 pip 安装 oauthlib 库:pip install oauthlib
。
File "/root/cloud-init/cloudinit/url_helper.py", line 20, in <module>
import oauthlib.oauth1 as oauth1
ImportError: No module named oauthlib.oauth1
)
如果安装报错时,没有明确缺少的依赖库,可以根据 cloud-init 的 requirements.txt 文件里显示的库,并使用 pip install -r requirements.txt
方式安装所有依赖库。
您可以 在控制台上导入镜像。
在文档使用中是否遇到以下问题
更多建议
匿名提交