项目实训一
【实训标题】
使用命令行创建Fedora虚拟机实例并注入用户暗码
【实训目标】
(1)掌握命令行界面的虚拟机实例根本操作。
(2)掌握用户数据注入方法。
【实训预备】
(1)复习命令行用户数据注入方法。
(2)预备好Fedora操作系统镜像。
【实训内容】
下面给出详细的参考步骤。
(1)在OpenStack主机上进入命令行界面。
(2)加载demo用户的情况脚本。
[root@node-a ~]# source keystonerc_demo
(3)查看实例创建的条件条件,包罗可用的实例类型、镜像、网络、安全组及其规则、密钥对。
① 查看实例类型
② 查看当前镜像
③ 查看当前网络
④ 查看当前安全组及其规则
⑤ 查看当前密钥对
(4)预备一个用户数据文本文件(命名为my_user_data.txt)
如果没有nano命令,则执行如下命令安装
[root@node-a ~(keystone_demo)]# yum -y install nano
[root@node-a ~(keystone_demo)]# nano my_user_data.txt
并在其中参加注入root和fedaora用户暗码的cloud-config指令,注意解释需单独一行,暗码反面不要有多余的空格。
- #cloud-config
- chpasswd:
- list: |
- root:abc123
- fedora:abc123
- expire: false
- ssh_pwauth: true
复制代码
(5)执行openstack server create命令,基于Fedora官方操作系统镜像创建一个虚拟机实例,使用--user-data选项传入该脚本文件,使用--config-drive选项来启用配置驱动器(将其值设为True)。
[root@node-a ~(keystone_demo)]# openstack server create --config-drive true --image fedora --flavor 2 --key-name demo-key --user-data ./my_user_data.txt fedoraVM2
+-----------------------------+-----------------------------------------------+
| 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 | FLu4HSGeLDtp |
| config_drive | True |
| created | 2021-08-29T03:21:39Z |
| flavor | m1.small (2) |
| hostId | |
| id | b51b252c-6349-4452-8cc4-8f584ec9a143 |
| image | fedora (d967cfbb-b936-4256-93d6-faa89d650ab7) |
| key_name | demo-key |
| name | fedoraVM2 |
| progress | 0 |
| project_id | f4e6c7f3791f4d5daf9cfb467298aafc |
| properties | |
| security_groups | name='default' |
| status | BUILD |
| updated | 2021-08-29T03:21:39Z |
| user_id | 97e37e69c8ec4f51b22e87c2e885f38d |
| volumes_attached | |
+-----------------------------+-----------------------------------------------+
稍等片刻,再查看新建实例的状态
[root@node-a ~(keystone_demo)]# openstack server list
+--------------------------------------+------------+---------+------------------------------------+--------+----------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+------------+---------+------------------------------------+--------+----------+
| b51b252c-6349-4452-8cc4-8f584ec9a143 | fedoraVM2 | ACTIVE | private=10.0.0.175 | fedora | m1.small |
| 303a6d60-4286-4b52-b6af-c1b0577bdf7e | Cirros_VM1 | SHUTOFF | private=10.0.0.90 | cirros | m1.tiny |
| 52bbe889-c453-407c-aa90-0c26e69b68be | Fedora-VM | SHUTOFF | private=10.0.0.194, 192.168.199.58 | | m1.small |
| 5c5f63e4-c659-40bc-ae0c-6789fad1b923 | Cirros-VM | SHUTOFF | private=10.0.0.60, 192.168.199.59 | | m1.tiny |
(6)完成实例创建之后,通过SSH登录该实例进行测试
起首需要为该实例分配一个浮动IP地址,以便从外部访问该实例。可以登录到图形界面操作,这里示范命令行操作
① 从地址池中获取一个闲置的浮动IP地址
- [root@node-a ~(keystone_demo)]# openstack floating ip create public
- +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | Field | Value |
- +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | created_at | 2021-08-29T03:44:36Z |
- | description | |
- | dns_domain | None |
- | dns_name | None |
- | fixed_ip_address | None |
- | floating_ip_address | 192.168.199.44 |
- | floating_network_id | a5b2a921-a189-4372-a99a-c9a481c7d6c2 |
- | id | 5ce9504a-bccf-47b3-8360-cc3d185d73ee |
- | location | Munch({'project': Munch({'domain_name': 'Default', 'domain_id': None, 'name': 'demo', 'id': u'f4e6c7f3791f4d5daf9cfb467298aafc'}), 'cloud': '', 'region_name': '', 'zone': None}) |
- | name | 192.168.199.44 |
- | port_details | None |
- | port_id | None |
- | project_id | f4e6c7f3791f4d5daf9cfb467298aafc |
- | qos_policy_id | None |
- | revision_number | 0 |
- | router_id | None |
- | status | DOWN |
- | subnet_id | None |
- | tags | [] |
- | updated_at | 2021-08-29T03:44:36Z |
- +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
复制代码
② 将该IP地址绑定到新建的Fedora实例
[root@node-a ~(keystone_demo)]# openstack server add floating ip fedoraVM2 192.168.233.93
③ 查看当前的实例列表,可以发现浮动IP地址绑定成功
- [root@node-a ~(keystone_demo)]# openstack server list
- +--------------------------------------+------------+---------+------------------------------------+--------+----------+
- | ID | Name | Status | Networks | Image | Flavor |
- +--------------------------------------+------------+---------+------------------------------------+--------+----------+
- | b51b252c-6349-4452-8cc4-8f584ec9a143 | fedoraVM2 | ACTIVE | private=10.0.0.175, 192.168.199.44 | fedora | m1.small |
- | 303a6d60-4286-4b52-b6af-c1b0577bdf7e | Cirros_VM1 | SHUTOFF | private=10.0.0.90 | cirros | m1.tiny |
- | 52bbe889-c453-407c-aa90-0c26e69b68be | Fedora-VM | SHUTOFF | private=10.0.0.194, 192.168.199.58 | | m1.small |
- | 5c5f63e4-c659-40bc-ae0c-6789fad1b923 | Cirros-VM | SHUTOFF | private=10.0.0.60, 192.168.199.59 | | m1.tiny |
- +--------------------------------------+------------+---------+------------------------------------+--------+----------+
复制代码
④ 测试SSH暗码登录
- [root@node-a ~]# ssh fedora@192.168.233.93
- The authenticity of host '192.168.199.87 (192.168.199.44)' can't be established.
- ECDSA key fingerprint is SHA256:f/rI4UsneTZD/1B4S3GmxsbMJRVa/HK7hsvuHipExAg.
- ECDSA key fingerprint is MD5:0d:35:2f:03:30:26:f3:6b:6a:59:52:c0:d9:16:83:5c.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added '192.168.199.44' (ECDSA) to the list of known hosts.
- fedora@192.168.199.44's password:
- $ exit 4
- Connection to 192.168.199.44 closed.
复制代码 注意当前虚拟机实例中的SSH配置不支持root账户SSH暗码登录,这里只能用fedora账户测试SSH暗码登录。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |