Centos官网qcow2镜像修改root账号密码,开启ssh等
wget http://172.16.20.10/vmtemplate/KVM/wangrui/Debian/debian-10.2.0-openstack-amd64.qcow2
[debian-10.2-cloud]
name=Debian 10.2.0 (Buster) Cloud
osinfo=debian10
arch=x86_64
file=debian-10.2.0-openstack-amd64.qcow2
checksum[sha512]=296ad8345cb49e52464a0cb8bf4365eb0b9e4220c47ebdd73d134d51effc756d5554aee15027fffd038fef4ad5fa984c94208bce60572d58b2ab26f74bb2a5de
format=qcow2
size=566434304
revision=20191116
notes=Debian 10.2.0 (Buster).
This is a Debian installation, suited for running as OpenStack guest.
使用openssl passwd -1?123456生成加密的密码:-1表示使用MD5算法对密码123456进行加密
[root@support01 ~]# openssl passwd -1 123456
$1$HDUWloxk$IZuLRX39Oa31T4YzCrCHL1
使用guestfish命令修改root账户密码,开启ssh远程登录
guestfish --rw -a debian-10.2.0-openstack-amd64.qcow2
进入交互命令界面依次执行run、list-filesystems、mount等指令
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: 'help' for help on commands
????? 'man' to read the manual
????? 'quit' to quit the shell
><fs> run
><fs> list-filesystems
/dev/sda1: ext4
><fs> mount /dev/sda1 ?/
><fs>
><fs> vi /etc/shadow
root:*:18216:0:99999:7:::
daemon:*:18216:0:99999:7:::
bin:*:18216:0:99999:7:::
sys:*:18216:0:99999:7:::
sync:*:18216:0:99999:7:::
games:*:18216:0:99999:7:::
man:*:18216:0:99999:7:::
lp:*:18216:0:99999:7:::
mail:*:18216:0:99999:7:::
news:*:18216:0:99999:7:::
uucp:*:18216:0:99999:7:::
proxy:*:18216:0:99999:7:::
www-data:*:18216:0:99999:7:::
backup:*:18216:0:99999:7:::
list:*:18216:0:99999:7:::
irc:*:18216:0:99999:7:::
gnats:*:18216:0:99999:7:::
nobody:*:18216:0:99999:7:::
_apt:*:18216:0:99999:7:::
systemd-timesync:*:18216:0:99999:7:::
systemd-network:*:18216:0:99999:7:::
systemd-resolve:*:18216:0:99999:7:::
messagebus:*:18216:0:99999:7:::
unscd:*:18216:0:99999:7:::
ntp:*:18216:0:99999:7:::
sshd:*:18216:0:99999:7:::
将root:后面的第一个*替换为第二步加密之后的密码
替换后第一行为/etc/shadow第一行为
root:$1$HDUWloxk$IZuLRX39Oa31T4YzCrCHL1:18216:0:99999:7:::
编辑/etc/ssh/sshd_config,
><fs> vi /etc/ssh/sshd_config
第32行
#PermitRootLogin prohibit-password
释放掉注释,并修改值为yes,调整完之后第32行为
PermitRootLogin yes
第56行
#PasswordAuthentication yes
释放掉注释,调整完之后第56行为
PasswordAuthentication yes
编辑/root/.bashrc,开启ssh语法高亮以及内置命令别名等,1、3、4、8、15行为说明注释,除此之外释放所有注释
><fs> vi /root/.bashrc
编辑之前内容为:
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "`dircolors`"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
编辑之后内容为:
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
最后执行quit或exit命令退出guestfish,将qcow2镜像文件注册到openstack,投递虚拟机实例即可
参考链接:
https://docs.openstack.org/image-guide/modify-images.html#guestfish
https://blog.51cto.com/superzhangqiang/1705678
https://blog.csdn.net/weixin_42551369/article/details/88946622
http://www.chenshake.com/openstack-mirror-and-password/?
在使用Linux系统镜像时,如果不使用密钥登录,可以在创建实例的时候使用脚本配置好密码,第三四行为自己需要修改的密码,两行必须相同。脚本如下:
#!/bin/bash
passwd root<<EOF
admin123
admin123
EOF
注意下面的"配置驱动"复选框请勾上,否则可能会配置后不生效。
?
修改镜像密码?方案2
virt-customize命令行工具由libguestfs-tools包提供,可用于在各种Linux发行版上安装, Virt-customize可以通过安装软件包,编辑配置文件等来自定义虚拟机(磁盘映像),它通过修改guest虚拟机或磁盘映像来实现此目的,它适用于raw和qcow2镜像格式
[root@localhost kvm]# virt-customize -a disk/CentOS-7-x86_64-GenericCloud-1511.qcow2 --root-password password:123456[?? 0.0] Examining the guest ...[? 15.5] Setting a random seed[? 15.5] Setting passwords[? 16.4] Finishing off
[root@localhost kvm]# virt-customize -a disk/CentOS-7-x86_64-GenericCloud-1511.qcow2 --root-password random[?? 0.0] Examining the guest ...[?? 1.8] Setting a random seed[?? 1.8] Setting passwordsvirt-customize: Setting random password of root to a2QVjEg6LoYoLW6a[?? 2.6] Finishing off
[root@localhost kvm]# virt-customize -a disk/CentOS-7-x86_64-GenericCloud-1511.qcow2 --password tao:password:taoyuhang[?? 0.0] Examining the guest ...[?? 2.1] Setting a random seed[?? 2.2] Setting passwords[?? 2.9] Finishing off
编辑nova.conf配置文件
[root@controller ~]# vim /etc/nova/nova.conf inject_password=true
启动实例时,在配置处输入自定义脚本直接输入修改密码命令
#!/bin/bashecho 'password'|passwd --stdin root
记得勾选Configuration Drive
官网:https://www.centos.org/download/
(1)兼容性选择
(2)操作系统选择centos7
(3)给虚拟机命名为OpenStack
(4)处理器和内核选择
(5)虚拟机内存
(6)网络类型选择nat地址转换
(7)控制器等按照推荐使用
(8)创建一个新的磁盘存放
(9)指定磁盘容量
(10)选择磁盘文件存放位置
(1)进行虚拟机编辑
(1-1)勾选虚拟化引擎
(1-2)选择CD/DVD,使用下载好的centos7镜像文件,根据自己兴趣可以移除声卡和打印机
(2)安装虚拟机
(2-1)选择install centos7安装
(2-2)选择语言为中文简体
(2-3)设置网络和主机名
(2-3-1)打开以太网连接
(2-3-2)点击配置,设置dns解析
多个dns中间使用","隔开
(2-4)取消勾选kdump
(2-5)开始安装
(2-5-1)设置ROOT密码
(2-5-2)创建用户(可以创建也可以不创建)
(1)禁用防火墙和SELinux
(1-1)禁用防火墙
[root@localhost ~]# systemctl stop firewalld 停用防火墙
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# yum -y install vim 安装vim编辑器
(1-2)配置文件将防火墙永久关闭
通过修改/etc/selinux/config,将“SELINUX”的值设置为“disable”,重启系统。
[root@localhost ~]# vim /etc/selinux/config 编辑配置文件
[root@localhost ~]# reboot 重启系统
(2)停用NetworkManager服务
CentOS 7 网络默认由NetworkManager(网络管理器)负责管理,但是 NetworkManager与OpenStack网络组件 Neutron 有冲突,应停用它,改用传统的网络服务 network来管理网络。
(2-1)停用NetworkManager
[root@localhost ~]# systemctl stop NetworkManager 停用NetworkManager
[root@localhost ~]# systemctl disable NetworkManager
(2-2)使用network管理网络
[root@localhost ~]# systemctl start network 开启network服务
[root@localhost ~]# systemctl enable network
(3)修改虚拟机IP地址
(3-1)通过修改/etc/sysconfig/network-scripts/ifcfg-ens33更改网卡的IP地址参数。
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO="static" 将网络地址获取设置为静态
DNS1="61.139.2.69" dns服务器地址
DNS2="8.8.8.8"
IPADDR="192.168.80.152" IP地址
NETMASK="255.255.255.0" 子网掩码
GATEWAY="192.168.80.2" 默认网关,有nat地址转换的默认网关为“xxx.xxx.xxx.2”
(3-2)重启network服务
[root@localhost ~]# systemctl restart network
(4)修改主机名
[root@localhost ~]# hostnamectl set-hostname lincan
root@localhost ~]# vim /etc/hosts
192.168.80.128 lincan lincan.localdomain
更改主机名,就必须将新的主机名追加到/etc/hosts配置文件中,否则,在使用 RDO 安装 OpenStack的过程中启动 rabbitmq-server 服务时会失败,从而导致安装不成功。
(5)更改编译语言
如果安装的CentOS7是非英语版本,那么需要在/etc/environment配置文件中添加以下定义。
[root@lincan ~]# vim /etc/environment
LANG=en_US.utf-8
LC_ALL=en_US.utf-8
(6)设置时间同步
(6-1)安装时间同步器
整个OpenStack环境中所有节点的时间必须是同步的。在CentOS7中一般使用时间同步软件Chrony;如果没有安装,就执行以下命令进行安装。
[root@lincan ~]# yum -y install chrony
(6-2)添加时间服务器
可以在/etc/chrony.conf配置文件中增加国内的NTP服务器地址如阿里云。
[root@lincan ~]# vim /etc/chrony.conf
server ntp1.aliyun.com iburst
(6-3)检查系统时间
执行timedatectl命令查看时间。若发现本地时间不对,解决的方法是将时区设置为国内的,可以执行以下命令设置时区为上海。
#timedatectl set-timezone "Asia/Shanghai"
[root@lincan ~]# timedatectl
(7)安装所需数据库
执行以下命令以设置OpenStack库(支持Train版本)。
#yum -y update
#yum -y install centos-release-openstack-train
(7-1)更新数据库
[root@lincan ~]# yum -y update
(7-2)安装train版本
[root@lincan ~]# yum -y install centos-release-openstack-train
(8)安装packstack
执行以下命令安装 openstack-packstack及其依赖包。
(8-1)更新数据库
[root@lincan ~]# yum -y update
(8-2)安装 openstack-packstack及其依赖包
[root@lincan ~]# yum -y install openstack-packstack
(9)安装packstack安器
Packstack 是 RDO的OpenStack 安装工具,用于取代手动设置 OpenStack Packstack 基于 Puppet 工具,通过Puppet 部署 OpenStack各组件。Puppet是一种 Linux、 UNIX和Windows平台的集中配置管理系统,使用自有的Puppet描述语言,可管理配置文件、用户、任务、软件包、系统服务等。
Packstack安装器的基本用法如下:packstack [选项] [--help]
1.--gen-answer-file=GEN_ANSWER_FILE:产生应答文件模板。
2.--answer-file=ANSWER_FILE:依据应答文件的配置信息以非交互模式运行该工具
3.--install-hosts=INSTALL_HOSTS:在一组主机上进行批量安装,主机列表以逗号分隔。
4.--allinone:将所有功能集中安装在单一主机上。
(9-1)将所有功能集中安装在单一主机上。
[root@lincan ~]# packstack --allinone
安装过程出现问题
192.168.80.152_controller.pp: [ ERROR ]
Applying Puppet manifests [ ERROR ]
ERROR : Error appeared during Puppet run: 192.168.80.152_controller.pp
Notice: /Stage[main]/Nova::Db::Sync/Exec[nova-db-sync]/returns: Error: (pymysql.err.OperationalError) (1045, u"Access denied for user 'nova'@'lincan' (using password: YES)") (Background on this error at: http://sqlalche.me/e/e3q8)
You will find full trace in log /var/tmp/packstack/20230221-101322-6tiImI/manifests/192.168.80.152_controller.pp.log
Please check log file /var/tmp/packstack/20230221-101322-6tiImI/openstack-setup.log for more information
Additional information:
* Parameter CONFIG_NEUTRON_L2_AGENT: You have chosen OVN Neutron backend. Note that this backend does not support the VPNaaS or FWaaS services. Geneve will be used as the encapsulation method for tenant networks
* A new answerfile was created in: /root/packstack-answers-20230221-101325.txt
* Time synchronization installation was skipped. Please note that unsynchronized time on server instances might be problem for some OpenStack components.
* File /root/keystonerc_admin has been created on OpenStack client host 192.168.80.152. To use the command line tools you need to source the file.
* To access the OpenStack Dashboard browse to http://192.168.80.152/dashboard .
Please, find your login credentials stored in the keystonerc_admin in your home directory.
You have new mail in /var/spool/mail/root
解决问题:win10系统版本更新16.2.4
win11系统更新17.0.0
安装成功
(9-2)运行Packstack安装OpenStack
查看openstack主要组件版本号:
#nova-manage --version
[root@lincan ~]# nova-manage --version
(10)登入OpenStack
用户名demo或admin
查看密码