概要:
在新建虛擬機的過程中,可以對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-----------