Openstack 应用 5:Openstack 启动 CentOS GenericCloud 实例(镜像制作/镜像创建/实例启动)
五:启动一个 CentOS GenericCloud 实例5.1:制作 GenericCloud-1511 镜像5.1.1:下载官方磁盘文件并解压[root@node252 src]# xz -d CentOS-7-x86_64-GenericCloud-1511.qcow2.xz[root@node252 src]# mv CentOS-7-x86_64-GenericCloud-1511.qc
·
五:启动一个 CentOS GenericCloud 实例
5.1:制作 GenericCloud-1511 镜像
5.1.1:下载官方磁盘文件并解压
[root@node252 src]# xz -d CentOS-7-x86_64-GenericCloud-1511.qcow2.xz
[root@node252 src]# mv CentOS-7-x86_64-GenericCloud-1511.qcow2 /var/lib/libvirt/images/
5.1.2:创建 KVM 虚拟机
[root@node252 ~]# virt-install --virt-type kvm --name CentOS-GenericCloud-7.2 \
--ram 1024 \
--cdrom=/usr/local/src/CentOS-7.2-x86_64-Minimal-1511.iso \
--disk path=/var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1511.qcow2 \
--network bridge=br0 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole
这里指定哪个镜像不重要,主要是从 CentOS-7-x86_64-GenericCloud-1511.qcow2 这个磁盘文件启动虚拟机。
5.1.3:打开虚拟机管理终端并强制关机
5.1.4:重设 root 密码
- 安装 libguestfs-tools:
[root@node252 ~]# yum install libguestfs-tools -y
- 修改 root 密码为 123456:
[root@node252 ~]# vsirt-customize -a /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1511.qcow2 --root-password password:123456
[ 0.0] Examining the guest ...
virt-customize: symbol lookup error: /lib64/libguestfs.so.0: undefined symbol: json_string_length
[root@node252 ~]# yum update
[root@node252 src]# virt-customize -a /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1511.qcow2 --root-password password:123456
[ 0.0] Examining the guest ...
[ 9.7] Setting a random seed
[ 9.8] Setting passwords
[ 12.7] Finishing off
开机状态下重设密码未成功,重新创建虚拟机强制关机后重设成功。
- 验证 root 登录:
- 验证 ssh 登录
[root@node252 src]# ssh 192.168.1.57
The authenticity of host '192.168.1.57 (192.168.1.57)' can't be established.
ECDSA key fingerprint is SHA256:+4aN0AyrkRRI3ZHYt6QAN0FH9A8CU4o+uLCtqtyjCGU.
ECDSA key fingerprint is MD5:b5:f5:bf:8e:3b:9a:c7:e4:04:05:a6:99:91:77:a3:88.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.57' (ECDSA) to the list of known hosts.
root@192.168.1.57's password:
Last login: Tue Nov 17 14:29:44 2020
[root@localhost ~]#
5.1.5:系统初始化操作
参见《CentOS 系统初始化》
5.1.6:添加一块内网网卡
5.1.7:配置免密登录
- 添加 KVM 制作主机和 Openstack 控制端的公钥到虚拟机中:
[root@localhost ~]# ssh-keygen
[root@localhost ~]# vim /root/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDgOIvlUt2rH0ebKPl3/SNvxkUXZtSPig3svl5QOWCix4pTqJLUsNs1YaEhJGsycjO2+mNyUTFuvKOTRdV5ObE/Zb9BTHw/jyBwScdUTLQkoc89vGI9qNvFez+PMcMq0He
qT1xTR1T8CvOopiPuPkDqAZtDm94MzsdvPs+C+CqKwPIozcPxAams4S01HxXymtAraQXmeSK1pPzvgR68CcJaoz/L5goSTLVW52RwMlFDU1MpuBWzQvf4F4KG9IjZTadQOFd9Do1AepxX+ylIBfzJMJ+P0Bk0Yirz5zfeAc
N6u10/IuHOPfJbiItoUtSn3+Fs+CHJ4CLmmNpe0FBgbICb root@node252.yqc.com
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDU8vkeSMrqDiT+M+7ztv6jitFYb12Z7epDHFHirJ+3JLUCAwhjcu+ztaUfDOcdjoNYZeESWZRdIPNlxnJz1acfnH3fNFHODZChWpJWRLAr1oluGO675Rm1lidyL/FqH3d
/rAqv1UnWrVYbuFNJpm+YStpXFEaMjXWDEPai24QRVdDhOgmIDEKFIWGqSG1A4Hs6iaSS14R6XbHObh9ZZuk2eh3lDpyTo5q4mzoVFbUHiCmQec5ymGTJFPS+MiqJq4MFB7xFetWWa/H2kRQ1CnC2vYCiow3W61kRMkWqVn
VhFHLXzqUavjF1Rtt1yVmw0mZKdKw0UnIO42aQzeWVgAnN root@node101.yqc.com
- 更改文件权限:
[root@localhost ~]# chmod 600 /root/.ssh/authorized_keys
- 验证免密登录:
[root@node252 ~]# ssh 192.168.1.57
Last login: Tue Nov 17 14:32:18 2020 from 192.168.1.252
[root@localhost ~]#
[root@node101 ~]# ssh 192.168.1.57
The authenticity of host '192.168.1.57 (192.168.1.57)' can't be established.
ECDSA key fingerprint is b5:f5:bf:8e:3b:9a:c7:e4:04:05:a6:99:91:77:a3:88.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.57' (ECDSA) to the list of known hosts.
Last login: Tue Nov 17 14:46:57 2020 from 192.168.1.252
[root@localhost ~]#
5.1.8:关机并拷贝磁盘文件至 Openstack 控制端
[root@node252 ~]# scp /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1511.qcow2 node101:/root/
5.2:创建镜像
- 导入 admin 凭证:
[root@node101 ~]# source admin-ocata.sh
- 创建名为 GenericCloud-1511 的镜像:
[root@node101 ~]# openstack image create "GenericCloud-1511" --file /root/CentOS-7-x86_64-GenericCloud-1511.qcow2 --disk-format qcow2 --container-format bare --public
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | 042e6aa4494e8b3bfd5ab662b27e57ec |
| container_format | bare |
| created_at | 2020-11-17T22:59:44Z |
| disk_format | qcow2 |
| file | /v2/images/00ca8a54-f2a3-435c-a9b1-b74c72b1b1f9/file |
| id | 00ca8a54-f2a3-435c-a9b1-b74c72b1b1f9 |
| min_disk | 0 |
| min_ram | 0 |
| name | GenericCloud-1511 |
| owner | acac1eb6c81540429c3323084bed23d9 |
| protected | False |
| schema | /v2/schemas/image |
| size | 1677197312 |
| status | active |
| tags | |
| updated_at | 2020-11-17T23:01:19Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
- 验证镜像:
[root@node101 ~]# openstack image list
+--------------------------------------+-------------------+--------+
| ID | Name | Status |
+--------------------------------------+-------------------+--------+
| f4316053-2df5-41b2-9ae4-61fbed684b96 | CentOS-7.2 | active |
| 00ca8a54-f2a3-435c-a9b1-b74c72b1b1f9 | GenericCloud-1511 | active |
| e2f766f6-5e57-474f-96cf-34fd4e9e5002 | WinServer-2008-R2 | active |
| 960434ae-56e7-49a2-8388-db376ac2a406 | cirros1 | active |
| 3168eab6-7ccd-4379-addd-b92266bc6f51 | cirros2 | active |
| 54461727-4f32-4cb9-8510-3ce5d66d39cb | cirros3 | active |
+--------------------------------------+-------------------+--------+
5.3:确认实例可用资源
- 导入 demo 凭证:
[root@node101 ~]# source demo-ocata.sh
- 列出可用虚拟机类型:
[root@node101 ~]# openstack flavor list
+--------------------------------------+-----------+------+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+-----------+------+------+-----------+-------+-----------+
| 0cc027fe-58e7-4548-ac4e-2c8e3b8bbd36 | 1c-1g-10G | 1024 | 10 | 0 | 1 | True |
| 1 | 2c-2g-20G | 2048 | 20 | 0 | 2 | True |
| 2 | 2c-2g-50G | 2048 | 50 | 0 | 2 | True |
+--------------------------------------+-----------+------+------+-----------+-------+-----------+
- 列出可用镜像:
[root@node101 ~]# openstack image list
+--------------------------------------+-------------------+--------+
| ID | Name | Status |
+--------------------------------------+-------------------+--------+
| f4316053-2df5-41b2-9ae4-61fbed684b96 | CentOS-7.2 | active |
| 00ca8a54-f2a3-435c-a9b1-b74c72b1b1f9 | GenericCloud-1511 | active |
| e2f766f6-5e57-474f-96cf-34fd4e9e5002 | WinServer-2008-R2 | active |
| 960434ae-56e7-49a2-8388-db376ac2a406 | cirros1 | active |
| 3168eab6-7ccd-4379-addd-b92266bc6f51 | cirros2 | active |
| 54461727-4f32-4cb9-8510-3ce5d66d39cb | cirros3 | active |
+--------------------------------------+-------------------+--------+
- 列出可用网络:
[root@node101 ~]# openstack network list
+--------------------------------------+--------------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+--------------+--------------------------------------+
| 5b845b84-5aa6-4b1b-b282-dc3694bdc82a | self-net | ced26a73-966c-40c6-8cab-71e683143f34 |
| 7356155c-9e74-463f-a93a-73f625640e8f | external-net | 9c339f48-a067-4c3b-bc70-11cd33f162ec |
| f2e6619e-c7dd-445c-91a6-024f34e37719 | test-net | c62894a0-602b-44d6-b31b-1b919eeb9742 |
+--------------------------------------+--------------+--------------------------------------+
- 列出可用安全组:
[root@node101 ~]# openstack security group list
+--------------------------------------+---------+------------------------+----------------------------------+
| ID | Name | Description | Project |
+--------------------------------------+---------+------------------------+----------------------------------+
| 62d98b23-3efe-4b4f-8de1-2f62f1df9d55 | default | Default security group | 9a94f1a1e271459580613778bf7c3392 |
+--------------------------------------+---------+------------------------+----------------------------------+
- 列出可用密钥对:
[root@node101 ~]# openstack keypair list
+----------+-------------------------------------------------+
| Name | Fingerprint |
+----------+-------------------------------------------------+
| demo-key | 3e:39:7a:d1:43:ad:4c:4a:7b:19:5e:fe:bc:d3:27:86 |
+----------+-------------------------------------------------+
5.4:启动实例(提供者网络)
5.4.1:创建实例
采用命令行方式创建。
- 创建一个名为 GenericCloud-1511-test 的云主机,2块网卡,分别使用 external-net 连接外网,test-net 连接内网:
[root@node101 ~]# openstack server create --flavor 1c-1g-10G --image GenericCloud-1511 \
--nic net-id=7356155c-9e74-463f-a93a-73f625640e8f --nic net-id=f2e6619e-c7dd-445c-91a6-024f34e37719 \
--security-group default \
--key-name demo-key GenericCloud-1511-test
+-----------------------------+----------------------------------------------------------+
| Field | Value |
+-----------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-STS:power_state | NOSTATE |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | None |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | |
| adminPass | CJ9SYzniM3vD |
| config_drive | |
| created | 2020-11-17T23:13:52Z |
| flavor | 1c-1g-10G (0cc027fe-58e7-4548-ac4e-2c8e3b8bbd36) |
| hostId | |
| id | aade2cc7-c251-4871-a4a3-f30c8ab9043f |
| image | GenericCloud-1511 (00ca8a54-f2a3-435c-a9b1-b74c72b1b1f9) |
| key_name | demo-key |
| name | GenericCloud-1511-test |
| progress | 0 |
| project_id | 9a94f1a1e271459580613778bf7c3392 |
| properties | |
| security_groups | name='default' |
| status | BUILD |
| updated | 2020-11-17T23:13:52Z |
| user_id | 69e61c6f12594c768bb39efb4e865a9b |
| volumes_attached | |
+-----------------------------+----------------------------------------------------------+
5.4.2:修改实例 IP 地址
将实例的 IP 地址修改为 Openstack 分配的 IP 地址(172.16.1.222 和 192.168.1.230)。
- eth0 外网网卡:
[root@genericcloud-1511-test ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="192.168.1.223"
PREFIX="24"
GATEWAY="192.168.1.1"
DNS1="192.168.1.254"
- 验证外网通信:
[root@genericcloud-1511-test ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11: icmp_seq=1 ttl=52 time=42.5 ms
64 bytes from 180.101.49.11: icmp_seq=2 ttl=52 time=42.7 ms
64 bytes from 180.101.49.11: icmp_seq=3 ttl=52 time=45.6 ms
- eth1 内网网卡:
[root@genericcloud-1511-test ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="172.16.1.227"
PREFIX="24"
DNS1="172.16.1.253"
- 验证内网通信:
[root@genericcloud-1511-test ~]# ping 172.16.1.101
PING 172.16.1.101 (172.16.1.101) 56(84) bytes of data.
64 bytes from 172.16.1.101: icmp_seq=1 ttl=64 time=0.566 ms
64 bytes from 172.16.1.101: icmp_seq=2 ttl=64 time=0.412 ms
64 bytes from 172.16.1.101: icmp_seq=3 ttl=64 time=0.768 ms
更多推荐
已为社区贡献6条内容
所有评论(0)