openstack-11镜像制作
openstack-11镜像制作
官方文档 https://docs.openstack.org/image-guide/obtain-images.html#centos
手动制作镜像可参考官方文档 https://docs.openstack.org/image-guide/create-images-manually.html
http://cloud.centos.org/centos/7/images/
http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1907.qcow2.xz
文件1907表示2019年7月制作的镜像
wget http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1907.qcow2.xz
xz -d CentOS-7-x86_64-GenericCloud-1907.qcow2.xz
file /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1907.qcow2
/var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1907.qcow2: QEMU QCOW Image (v2), 8589934592 bytes
virt-install --virt-type kvm --name centos7.6-template --ram 1024 --vcpu 2 --pxe --disk path=/var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1907.qcow2 --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
重设密码
yum install libguestfs-tools
virt-customize -a /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1907.qcow2 --root-password password:passwd
或者进入当用户模式更新密码
第一次进入比较慢,主要脚本在/etc/cloud/cloud.cfg,可以关闭一些不需要的东西
vim /etc/cloud/cloud.cfg
users:
- admin
disable_root: 0
ssh_pwauth: 0
mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
resize_rootfs_tmp: /dev
ssh_deletekeys: 0
ssh_genkeytypes: ~
syslog_fix_perms: ~
cloud_init_modules:
# - disk_setup
# - migrator
# - bootcmd
- write-files
- growpart
- resizefs
# - set_hostname
# - update_hostname
# - update_etc_hosts
# - rsyslog
# - users-groups
# - ssh
#cloud_config_modules:
# - mounts
# - locale
# - set-passwords
# - rh_subscription
# - yum-add-repo
# - package-update-upgrade-install
# - timezone
# - puppet
# - chef
# - salt-minion
# - mcollective
# - disable-ec2-metadata
# - runcmd
#cloud_final_modules:
# - rightscale_userdata
# - scripts-per-once
# - scripts-per-boot
# - scripts-per-instance
# - scripts-user
# - ssh-authkey-fingerprints
# - keys-to-console
# - phone-home
# - final-message
# - power-state-change
#system_info:
# default_user:
# name: centos
# lock_passwd: true
# gecos: Cloud User
# groups: [wheel, adm, systemd-journal]
# sudo: ["ALL=(ALL) NOPASSWD:ALL"]
# shell: /bin/bash
# distro: rhel
# paths:
# cloud_dir: /var/lib/cloud
# paths:
# cloud_dir: /var/lib/cloud
# templates_dir: /etc/cloud/templates
# ssh_svcname: sshd
# vim:syntax=yaml
时区
rm -rf /etc/localtime
ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ssh密码认证打开
PasswordAuthentication yes
systemctl restart sshd
免密钥登录
s
sh-keygen
ssh-copy-id
[root@controller1 ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQJolNH4c3QwKLBr//kdOrk25Bc+YnLnk2XeUMLTm4k4oo4Nq/Pjo07tz7/SrXeXU5xjTkyRqerrp1UCIESzZpm7C/nprqriyeBRIzOYnB4TV+iM1EPvxrKtX90KIkzZvys3bAYYKRw/16uiWiVqzVKDD52hVcKdtG5cjAGbaiu+W0jAq3sHqrqQO+fEivPPEXtfx8RsZFzPMmoDq1je/XvDCYuSjzAxM4jYXYtsbQKnouZLaRhFF8QeAEQ/ggLjiV/kTArYuNyMCkUQDt1o/Rx82O1Gr4yQMBUOGgugjufdMXD8c5KPnPZsdzUig1eHUd2uuDUiiM9ljgX/pwdP1r root@controller1
cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQJolNH4c3QwKLBr//kdOrk25Bc+YnLnk2XeUMLTm4k4oo4Nq/Pjo07tz7/SrXeXU5xjTkyRqerrp1UCIESzZpm7C/nprqriyeBRIzOYnB4TV+iM1EPvxrKtX90KIkzZvys3bAYYKRw/16uiWiVqzVKDD52hVcKdtG5cjAGbaiu+W0jAq3sHqrqQO+fEivPPEXtfx8RsZFzPMmoDq1je/XvDCYuSjzAxM4jYXYtsbQKnouZLaRhFF8QeAEQ/ggLjiV/kTArYuNyMCkUQDt1o/Rx82O1Gr4yQMBUOGgugjufdMXD8c5KPnPZsdzUig1eHUd2uuDUiiM9ljgX/pwdP1r root@controller1
安装常用软件包
yum install -y net-tools vim lrzsz tree screen lsof ntpdate telnet acpid
上传镜像
source admin-ocata.sh
[root@controller1 ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| cac9811d-6590-4648-b1a0-6eda2e8e799e | cirros | active |
+--------------------------------------+--------+--------+
[root@controller1 ~]# openstack image create "centos7.6" --file CentOS-7-x86_64-GenericCloud-1907.qcow2 --disk-format qcow2 --container-format bare --public
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | 36ddd39494f1178b083306fe78ff67a8 |
| container_format | bare |
| created_at | 2019-09-17T07:31:59Z |
| disk_format | qcow2 |
| file | /v2/images/f53e0dd6-b50e-4e7e-aee2-eeefcb89ed65/file |
| id | f53e0dd6-b50e-4e7e-aee2-eeefcb89ed65 |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7.6 |
| owner | 14c7c0b953754e0d9f30d4973e3e369d |
| protected | False |
| schema | /v2/schemas/image |
| size | 1033109504 |
| status | active |
| tags | |
| updated_at | 2019-09-17T07:33:40Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
[root@controller1 ~]# openstack image list
+--------------------------------------+-----------+--------+
| ID | Name | Status |
+--------------------------------------+-----------+--------+
| f53e0dd6-b50e-4e7e-aee2-eeefcb89ed65 | centos7.6 | active |
| cac9811d-6590-4648-b1a0-6eda2e8e799e | cirros | active |
+--------------------------------------+-----------+--------+
镜像上传后就可以创建实例