openstack 修改实例密码
概要:
在新建虚拟机的过程中,可以对root密码进行初始化。这样可以保障虚拟机的安全,同时也可以给用户自定义root密码的机会。
步骤:
修改控制节点的nova配置项:
首先修改nova的配置文件。文件位置 /etc/nova/nova.conf
将inject_password改为True
[libvirt]
# There is no agent needed within the image to do this. If *libguestfs* is
# available on the host, it will be used. Otherwise *nbd* is used. Thefile
# system of the image will be mounted and the admin password, which isprovided
# in the REST API call will be injected as password for the root user. Ifno
# root user is available, the instance won't be launched and an error isthrown.
# Be aware that the injection is *not* possible when the instance getslaunched
# from a volume.
#
# Possible values:
#
# * True: Allows the injection.
# * False (default): Disallows the injection. Any via the REST API provided
# admin password will be silently ignored.
#
# Related options:
#
# * ``inject_partition``: That option will decide about the discovery andusage
# of the file system. It also candisable the injection at all.
# (boolean value)
inject_password=true
编辑/etc/openstack-dashboard/local_settings,修改如下配置参数:
-
OPENSTACK_HYPERVISOR_FEATURES = {
-
...
-
'can_set_password': True,
-
}
重启nova服务:
systemctl restart openstack-nova-*
然后在创建虚拟机的过程注入脚本
如下:
#!/bin/sh
passwd root<<EOF
huangyi
huangyi
EOF
huangyi替换成你的密码
注意下面的配置驱动一定要勾上,不然虚拟机初始化root密码会失败的。
成功失败说明:
其次,按照上述步骤操作,根据我多次测试的结果,镜像是ubuntu系统的基本上创建成功了,就能成功注入密码。而centos系统则需要过一段时间才能生效(我测试的时间大概是5-15分钟期间)。
Ubuntu进入界面如下说明注入失败:
注入成功:
差别在于,成功的话,箭头指的字符串应该是 "你的虚拟机名称 login"。
centos的虚拟机刚进入界面都是如下所示(注意应该等待一段时间后再进入控制台):
输入root和你设置的密码,如果注入成功会成功跳转到类似如下的界面,说明centos也已经注入成功:
如果仍然不行,请先退出控制台,过段时间再进去。
自制镜像满足设置root密码的要求:
自制镜像操作系统的时候必须安装cloud-init软件,方可注入root密码。
ubuntu如下:
centos:
改为yum
---------文章写自:HyHarden---------
--------博客地址:http://blog.csdn.net/qq_25722767-----------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】