标签:agent restart nova upd ssh Fix glance idle one
1.虚拟机创建时设置密码
计算节点安装以下软件包
yum install libguestfs python-libguestfs libguestfs-tools-c
配置计算节点nova配置文件/etc/nova/nova.conf,添加如下选项
[libvirt]
inject_password=true
inject_key=true
inject_partition=-1
重启计算节点的nova服务
systemctl restart openstack-nova-compute libvirtd
user data 也可以是 cloud-init 支持的一个 yaml 结构文件,所以还可以通过如下方式改密码
# cat ./cloud-config.txt
#cloud-config
chpasswd:
list: |
root:123456
expire: False
创建虚拟机并设置密码的命令如下
nova boot --user-data ./cloud-config.txt --image ... 或者openstack server create --user-data ./cloud-config.txt --image ...
示范如下
openstack server create --flavor 1c2g --user-data ./cloud-config.txt --availability-zone nova --image 75398b9c-5cd6-4936-a093-eba02984f7f0 \
--nic net-id=5ac5c948-909f-47ff-beba-a2ffaf917c5f,v4-fixed-ip=172.16.99.134 \
--nic net-id=85ae5035-203b-4ef7-b65c-397f80b5a8af,v4-fixed-ip=172.16.100.34 \
--security-group 5bb5f2b1-9210-470f-a4a7-2715220b2920 tomcat-vm4
2.虚拟机启动后修改密码
如果需要nova set-password起作用,需要image中装有qemu-guest-agent,另外需要设置meta中的 hw_qemu_guest_agent为yes
2.1首先需要在openstack镜像中增加metadata信息:hw_qemu_guest_agent=yes,命令如下:
# glance image-update 75398b9c-5cd6-4936-a093-eba02984f7f0 --property hw_qemu_guest_agent=yes
+---------------------+--------------------------------------------------------------------+
| Property | Value |
+---------------------+--------------------------------------------------------------------+
| checksum | fc345c82d1f2f28c63a1be8b386a15e4 |
| container_format | bare |
| created_at | 2020-02-19T08:45:40Z |
| direct_url | file:///var/lib/glance/images/75398b9c-5cd6-4936-a093-eba02984f7f0 |
| disk_format | raw |
| hw_qemu_guest_agent | yes |
| id | 75398b9c-5cd6-4936-a093-eba02984f7f0 |
| min_disk | 0 |
| min_ram | 0 |
| name | CentOS 7.6 64位 |
| owner | 75aed7016c86445198356e78dddde4ba |
| protected | False |
| size | 5368709120 |
| status | active |
| tags | [] |
| updated_at | 2020-02-20T05:05:58Z |
| virtual_size | None |
| visibility | public |
+---------------------+--------------------------------------------------------------------+
其中75398b9c-5cd6-4936-a093-eba02984f7f0为镜像ID
修改启动后的虚拟机密码为123456
# nova set-password 550e9a70-8064-4180-8bab-502ee15e6647 或者 openstack server set --root-password 550e9a70-8064-4180-8bab-502ee15e6647
其中550e9a70-8064-4180-8bab-502ee15e6647为虚拟机ID
# nova help set-password
usage: nova set-password <server>
Change the admin password for a server.
Positional arguments:
<server> Name or ID of server.
测试密码是否修改成功
# sshpass -p ‘123456‘ ssh root@172.16.99.134 w
13:28:54 up 14 min, 1 user, load average: 0.04, 0.08, 0.13
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.30.1.103 13:20 8:28 0.03s 0.03s -bash
在openstack horizon中重建实例时支持设置密码,同样可以生效了。
扩展1:给单个云主机中增加metadata信息:hw_qemu_guest_agent=yes,命令如下:
nova meta 550e9a70-8064-4180-8bab-502ee15e6647 set hw_qemu_guest_agent=yes
扩展2:
上传镜像前修改密码
virt-customize -a /tmp/CentOS7.6_x86_64.raw --root-password password:123456
上传镜像
openstack image create "CentOS 7.6 64位 V2" --file /tmp/CentOS7.6_x86_64.raw --disk-format raw --container-format bare --public
如何修改openstack虚拟机密码
标签:agent restart nova upd ssh Fix glance idle one
原文地址:https://www.cnblogs.com/dexter-wang/p/12337055.html