其他分享
首页 > 其他分享> > cloud-init安装与配置

cloud-init安装与配置

作者:互联网

手册: https://cloudinit.readthedocs.io/en/latest/index.html

1. 安装

# dnf install -y cloud-init

2. 配置

# cat /etc/cloud/cloud.cfg
users:
 - default
 - name: rocky
   groups: wheel
   shell: /bin/bash
   lock_passwd: 0
   passwd: $6$MySalt$Ns31ZOCCyA3AXLjaqyVLM2xlzgfKq9X7.4lL1d26p0vbxzIOMWKjyEPkEizmOVQxiA8l5QSMjeEYDWNLrSM74/
   sudo: ALL=(ALL) NOPASSWD:ALL

disable_root: 0
ssh_pwauth:   1

manage_etc_hosts: 0
package_update: 0
package_upgrade: 0

mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
resize_rootfs_tmp: /dev
ssh_deletekeys:   1
ssh_genkeytypes:  ['rsa', 'ecdsa', 'ed25519']
syslog_fix_perms: ~
disable_vmware_customization: false

cloud_init_modules:
 - disk_setup
 - migrator
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - set_hostname
 - update_hostname
 - update_etc_hosts
 - rsyslog
 - users-groups
 - ssh

cloud_config_modules:
 - mounts
 - locale
 - set-passwords
 - rh_subscription
 - yum-add-repo
 - timezone
 - disable-ec2-metadata
 - runcmd

cloud_final_modules:
 - package-update-upgrade-install
 - puppet
 - chef
 - salt-minion
 - mcollective
 - rightscale_userdata
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message
 - power-state-change

system_info:
  default_user:
    name: cloud-user
    lock_passwd: true
    gecos: Cloud User
    groups: [adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

# vim:syntax=yaml
2 - 7 行 : 添加用户rocky,允许sudo管理员权限,设置密码,hash密码生成 python -c 'import crypt; print(crypt.crypt("12345678", "$6$MySalt"))' 
9 - 10 行 : 允许root登录,允许ssh密码认证方式 
12 - 14 行 :  不更新/etc/hosts,不升级安装包
清除日志
# cloud-init clean --logs

检查配置文件
# cloud-init init --local

执行配置
# cloud-init init

3. 日志与数据目录

日志
/var/log/cloud-init.log
/var/log/cloud-init-output.log

数据
# tree /var/lib/cloud/
/var/lib/cloud/
├── data
│   ├── instance-id
│   ├── previous-datasource
│   ├── previous-hostname
│   ├── previous-instance-id
│   ├── python-version
│   ├── result.json
│   ├── set-hostname
│   └── status.json
├── handlers
├── instance -> /var/lib/cloud/instances/ee3549784d09e169b07f3e1118f6d91451cb2d5f
├── instances
│   └── ee3549784d09e169b07f3e1118f6d91451cb2d5f
│       ├── boot-finished
│       ├── cloud-config.txt
│       ├── datasource
│       ├── handlers
│       ├── obj.pkl
│       ├── scripts
│       ├── sem
│       │   ├── config_disk_setup
│       │   ├── config_keys_to_console
│       │   ├── config_locale
│       │   ├── config_mcollective
│       │   ├── config_mounts
│       │   ├── config_package_update_upgrade_install
│       │   ├── config_phone_home
│       │   ├── config_power_state_change
│       │   ├── config_puppet
│       │   ├── config_rh_subscription
│       │   ├── config_rightscale_userdata
│       │   ├── config_rsyslog
│       │   ├── config_runcmd
│       │   ├── config_salt_minion
│       │   ├── config_scripts_per_instance
│       │   ├── config_scripts_user
│       │   ├── config_set_hostname
│       │   ├── config_set_passwords
│       │   ├── config_ssh
│       │   ├── config_ssh_authkey_fingerprints
│       │   ├── config_timezone
│       │   ├── config_users_groups
│       │   ├── config_write_files
│       │   ├── config_yum_add_repo
│       │   ├── consume_data
│       │   └── update_sources
│       ├── user-data.txt
│       ├── user-data.txt.i
│       ├── vendor-data2.txt
│       ├── vendor-data2.txt.i
│       ├── vendor-data.txt
│       └── vendor-data.txt.i
├── scripts
│   ├── per-boot
│   ├── per-instance
│   ├── per-once
│   └── vendor
├── seed
└── sem
    └── config_scripts_per_once.once

15 directories, 45 file

标签:安装,per,init,ssh,scripts,config,cloud
来源: https://www.cnblogs.com/liujitao79/p/16553360.html