麒麟系统V10-sp1安装cloud-init

翁凯定
2023-12-01

V10-sp1离线源码编译安装cloud-init-18.5

cloud-init源码下载地址:https://launchpad.net/cloud-init/+download

参考:https://cloud.tencent.com/document/product/213/12587

1.准备

1.1 上传cloud-init源码包

# mkdir /usr/local/sources
将cloud-init-18.5.tar.gz上传到/usr/local/sources目录下

1.2 上传依赖包

# 上传依赖包到/tmp下
# ls /tmp/cloud-init-soft.tar.bz2

1.3 配置本地yum源安装依赖

# mv kylin_x86_64.repo kylin_x86_64.repo.bak
# tar -xf /tmp/cloud-init-soft.tar.bz2 -C /media/
# yum-config-manager --add-repo=file:///media/cloud-init-soft/
# echo "gpgcheck=0" >> media_cloud-init-soft_.repo
# yum clean all && yum list 
# yum -y install python*  #一定要把本机自带的repo备份移走,用上面我们自己创建的!

2.安装并配置cloud-init

2.1 解压源码包并安装

# cd /usr/local/sources/ && tar -xf cloud-init-18.5.tar.gz
# cd cloud-init-18.5/
# python setup.py build #输出如下:
.....
running build_scripts
creating build/scripts-2.7
copying tools/cloud-init-per -> build/scripts-2.7

# python setup.py install --init-system systemd #输出如下:
......
Using /usr/lib/python2.7/site-packages
Finished processing dependencies for cloud-init==18.5

2.2 修改参数

  • /lib/systemd/system/cloud-init-local.service文件内容替换为如下:

    [Unit]
    Description=Initial cloud-init job (pre-networking)
    Wants=network-pre.target
    After=systemd-remount-fs.service
    Before=NetworkManager.service
    Before=network-pre.target
    Before=shutdown.target
    Conflicts=shutdown.target
    RequiresMountsFor=/var/lib/cloud
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/cloud-init init --local
    ExecStart=/bin/touch /run/cloud-init/network-config-ready
    RemainAfterExit=yes
    TimeoutSec=0
    
    # Output needs to appear in instance console output
    StandardOutput=journal+console
    
    [Install]
    WantedBy=cloud-init.target
    
  • /lib/systemd/system/cloud-init.service文件内容替换为如下:

    [Unit]
    Description=Initial cloud-init job (metadata service crawler)
    Wants=cloud-init-local.service
    Wants=sshd-keygen.service
    Wants=sshd.service
    After=cloud-init-local.service
    After=systemd-networkd-wait-online.service
    After=networking.service
    After=systemd-hostnamed.service
    Before=network-online.target
    Before=sshd-keygen.service
    Before=sshd.service
    Before=systemd-user-sessions.service
    Conflicts=shutdown.target
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/cloud-init init
    RemainAfterExit=yes
    TimeoutSec=0
    
    # Output needs to appear in instance console output
    StandardOutput=journal+console
    
    [Install]
    WantedBy=cloud-init.target
    
    

2.3 启动服务设置开机自启

# systemctl daemon-reload
# export LC_ALL=C
# 启动并开机自启
# systemctl enable cloud-init-local.service
# systemctl start cloud-init-local.service
# systemctl enable cloud-init.service
# systemctl start cloud-init.service
# systemctl enable cloud-config.service
# systemctl start cloud-config.service
# systemctl enable cloud-final.service
# systemctl start cloud-final.service
# 查看状态
# systemctl status cloud-init-local.service
# systemctl status cloud-init.service
# systemctl status cloud-config.service
# systemctl status cloud-final.service

2.4 查看版本

[root@v10-sp1-0518-2 ~]# cloud-init -v
/usr/bin/cloud-init 18.5

 类似资料: