腾讯云安装cloud-init服务步骤
使用自定义镜像时,为保证运行该镜像的实例能成功完成初始化配置,建议用户在服务器上安装cloud-init服务。
目前仅Linux腾讯云服务器支持安装cloud-init服务。
前提条件
要安装cloud-init的腾讯云服务器必须可以正常访问外网。登录服务器的账户必须是root用户。对于Ubuntu系统,需要换至root帐号。
操作步骤
准备工作检查镜像中是否已包含cloud-init服务。如果是,卸载原有的cloud-init服务。对于CentOS操作系统,使用以下命令:
rpm -e cloud-initrm -rf /etc/conf/cloud/*rm -rf /var/lib/cloud/*
对于Ubuntu操作系统,使用以下命令:
apt-get purge cloud-init
对于Debian操作系统,使用以下命令:
rm /usr/bin/cloud-init*
检查镜像环境的Python解释器版本,如果为Python2.6及以下版本,需要安装下列依赖组件:
requests:执行pip install 'requests<2.20.0'命令安装requests 2.20.0版本以下的版本。jsonschema:执行pip install 'jsonschema<=2.5.1'命令安装jsonschema 2.5.1版本以下的版本。setuptools:执行pip install setuptools==36.7.0命令安装setuptools 37版本以下的版本。获取cloud-init源码包。
安装cloud-init服务
解压 cloud-init 安装包。
tar -zxvf cloud-init-18.3.tar.gz
进入 cloud-init 安装包目录cloud-init-18.3。
cd cloud-init-18.3
安装 python-pip。
apt-get/yum install python-pip -y
安装依赖包。
pip install -r requirements.txt
安装 cryptography。
pip install cryptography # Python 2.7 执行此命令pip install 'cryptography<=1.3.1' # Python 2.6 执行此命令
安装 cloud-init。
python setup.py buildpython setup.py install --init-system systemd # systemd 自启动管理服务,执行此命令python setup.py install --init-system sysvinit # sysvinit 自启动管理服务,执行此命令python setup.py install --init-system upstart # upstart 自启动管理服务(ubuntu 14使用),执行此命令.
设置cloud-init服务开机自启动
如果操作系统使用 sysvinit 自启动管理服务,使用以下命令:
chkconfig --add cloud-init-localchkconfig --add cloud-initchkconfig --add cloud-configchkconfig --add cloud-finalchkconfig cloud-init-local onchkconfig cloud-init onchkconfig cloud-config onchkconfig cloud-final on
如果操作系统使用 systemd 自启动管理服务,具体操作步骤如下所示。
对于Ubuntu和Debian操作系统,执行以下命令:
ln -s /usr/local/bin/cloud-init* /usr/bin/
所有操作系统都需执行以下命令:
systemctl enable cloud-init-local.servicesystemctl start cloud-init-local.servicesystemctl enable cloud-init.servicesystemctl start cloud-init.servicesystemctl enable cloud-config.servicesystemctl start cloud-config.servicesystemctl enable cloud-final.servicesystemctl start cloud-final.servicesystemctl status cloud-init-local.servicesystemctl status cloud-init.servicesystemctl status cloud-config.servicesystemctl status cloud-final.service
对于CentOS和Fedora操作系统,执行以下命令:
ln -s /usr/lib/systemd/system/cloud-config.target /usr/lib/systemd/system/multi-user.target.wants/cloud-config.target
对于Ubuntu和Debian操作系统,执行以下命令:
ln -s /lib/systemd/system/cloud-config.target /lib/systemd/system/multi-user.target.wants/cloud-config.target
如果操作系统使用 upstart 自启动管理服务,对于Ubuntu和Debian操作系统,使用以下命令:
ln -s /usr/local/bin/cloud-init* /usr/bin/