操作场景
Cloudbase-Init是用于Windows操作系统在创建弹性云主机过程执行信息初始化的工具,主要支持以下关键能力:
- Windows云主机主机名、用户名、密码等信息的初始化;
- Windows云主机用户数据的注入以及自动化配置。
操作步骤
下载最新稳定版Cloudbase-Init:
- 64 位Windows操作系统请通过此链接下载:CloudbaseInitSetup_最新稳定版_64位系统版本。
- 32 位Windows操作系统请通过此链接下载:CloudbaseInitSetup_最新稳定版_32位版本系统。
安装Cloudbase-Init
遇下方截图步骤,请按截图配置操作,其它界面默认即可。
- Username: Administrator;
- 勾选Run Cloudbase-Init service as LocalSystem。
配置Cloudbase-Init。
- 打开PowerShell,将以下内容直接复制粘贴并执行。
$content = @'
[DEFAULT]
username=Administrator
groups=Administrators
inject_user_password=true
bsdtar_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\bsdtar.exe
mtools_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\
verbose=true
debug=true
logdir=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\
logfile=cloudbase-init.log
default_log_levels=comtypes=INFO,suds=INFO,iso8601=WARN,requests=WARN
logging_serial_port_settings=COM1,115200,N,8
local_scripts_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\
allow_reboot=true
metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService,cloudbaseinit.metadata.services.httpservice.HttpService
plugins=cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin,cloudbaseinit.plugins.common.networkconfig.NetworkConfigPlugin,cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin,cloudbaseinit.plugins.common.setuserpassword.SetUserPasswordPlugin,cloudbaseinit.plugins.common.localscripts.LocalScriptsPlugin,cloudbaseinit.plugins.common.userdata.UserDataPlugin
netbios_host_name_compatibility=false
activate_windows=true
first_logon_behaviour=no
'@
$content | Out-File -Encoding ASCII -FilePath 'C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf\cloudbase-init.conf'
- 添加自定义脚本,确保 configdrive CD 设备能自动卸载。
$content = @'
# Set the label of the configdrive.
$label = 'config-2'
# Get the list of CD drives and find the one with the specified label.
$cdRom = (New-Object -ComObject 'Shell.Application').Namespace(17).Items() | Where-Object { $_.Name.contains($label) }
# Check if the CD drive with the specified label was found.
if ($cdRom) {
try {
# Eject the CD drive.
$cdRom.InvokeVerb("Eject")
Write-Output "Successfully ejected configdrive CD device: $cdRom"
} catch {
Write-Output "Failed to eject configdrive CD device: $cdRom"
}
} else {
Write-Output "No configdrive CD device found with the label: $label"
}
# Tell cloudbase-init not to reboot now and rerun the plugin on the next boot.
exit 1002
'@
$content | Out-File -Encoding ASCII -FilePath 'C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\eject_configdrive.ps1'
- 配置Cloudbase-Init为自启动。
Set-Service -Name 'cloudbase-init' -StartupType Automatic