OpenStack常用命令整理(mitaka)
OpenStack官网 (opens new window)
openStack是一个 SOA架构,他的组件有(mitaka版): keystone认证服务,glance镜像服务,nova计算服务,neutron网络服务,cinder存储服务,horizon web界面
ubuntu-22.04-jammy下载链接 (opens new window)
# 常用命令笔记
用于命令行认证变量参数:admin-oppenrc
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=ADMIN_PASS
export OS_AUTH_URL=http://keystone_IP:35357/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
2
3
4
5
6
7
8
- 端口说明
端口 | 服务 |
---|---|
0.0.0.0:6080 | 1125/nova-novncproxy |
0.0.0.0:8774 | 1106/nova-api |
0.0.0.0:8775 | 1106/nova-api-metadata |
0.0.0.0:9292 | 1108/glance-api |
0.0.0.0:9191 | 1143/glance-registry |
0.0.0.0:5000 | 1183/keystone 非admin端口 |
0.0.0.0:35357 | 1183/keystone admin |
0.0.0.0:4369 | 1/rabbitmq |
:::5672 | 1112/rabbitmq 对外提供服务 |
0.0.0.0:25672 | 1112/rabbitmq(集群之间通讯) |
0.0.0.0:9696 | 1114/neutron-server |
0.0.0.0:80 | 1183/httpd |
192.168.108.10:3306 | 1322/mysqld |
192.168.108.10:11211 | 1111/memcached |
# openStacks常用查看服务命令
加载认证变量参数:source admin-openrc
- 查看keystone是否正常
openstack token issue
- 检查nova
openstack compute service list
- 查看neutron,keystone,glance,nova 服务是否正常
openstack service list
- 查看接口信息
不能有重叠,如果有重叠,登录数据库删除数据:
select * from keystone.service;
openstack catalog list
openstack endpoint list
- 手动上传glance镜像
openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --public
- 镜像修改默认密码
apt install -y libguestfs-tools
export LIBGUESTFS_BACKEND=direct
#chown qemu.qemu CentOS-7-x86_64-GenericCloud-2009.qcow2 #centos 系统需要执行
virt-customize -a CentOS-7-x86_64-GenericCloud-2009.qcow2 --root-password password:asdfqwer1234
openstack image create "centos7.9_2009" --file CentOS-7-x86_64-GenericCloud-2009.qcow2 --disk-format qcow2 --container-format bare --public
2
3
4
5
6
- 查看glance镜像
镜像操作记录:
select * from glance.images;
openstack image list
- 查看neutron信息
查看数据库数据:
select * from neutron.agents;
neutron agent-list
- 查看计算节点nova是否正常
nova hypervisor-list
- 查看cinder服务
查看数据库数据:
select * from cinder.services;
cinder service-list
- 创建 provider网络
neutron net-create --shared --provider:physical_network provider --provider:network_type flat provider
#neutron subnet-create --name provider --allocation-pool start=START_IP_ADDRESS,end=END_IP_ADDRESS --dns-nameserver DNS_RESOLVER --gateway PROVIDER_NETWORK_GATEWAY provider PROVIDER_NETWORK_CIDR
neutron subnet-create --name provider --allocation-pool start=192.168.0.200,end=192.168.0.240 --dns-nameserver 114.114.114.114 --gateway 192.168.0.1 provider 192.168.0.0/24
2
3
- 删除 provider 网络: provider
neutron subnet-delete --name provider
- 创建 self 私有网络
neutron net-create selfservice
neutron subnet-create --name selfservice --dns-nameserver 114.114.114.114 --gateway 172.16.1.1 selfservice 172.16.1.0/24
#需要先用provider 网络,关联
neutron net-update provider --router:external
neutron router-create router
neutron router-interface-add router selfservice
neutron router-gateway-set router provider
2
3
4
5
6
7
8
9
10
11
12
13
- 查看网络
openstack network list
- 查看有哪些安全组
openstack security group list
- 创建安全组规则在default规则里
允许ping:openstack security group rule create --proto icmp default
放开22:openstack security group rule create --proto tcp --dst-port 22 default
- 创建云主机的实例类型
openstack flavor create --id test-c2-2G-5G --vcpus 2 --ram 2048 --disk 5 n1.nano
注意:在我这里配置了gpu,需要硬件支持才能创建
openstack flavor create --id c2-4G-20G --vcpus 2 --ram 4096 --disk 20 --public --property "pci_passthrough:alias"="nvidia1050vga:1,nvidia1050aud:1
添加元数据
openstack flavor set test-c2-4G-20G --property "pci_passthrough:alias"="nvidia1050vga:1,nvidia1050aud:1"
查看:openstack flavor list
- 显卡驱动隐藏hypervisor id
openstack image set [IMG-UUID] --property img_hide_hypervisor_id=true
- 创建实例
openstack server create --flavor test-c2-4G-20G --image ubuntu2204 --security-group 49d45943-a9f8-4b87-ba40-b9ff4340ab57 --nic net-id=977b2ea4-d178-41fd-999c-5e0472b71bf2 Ubuntu-2204GPU
- 查看实例启动情况
openstack server list
- 查看实例信息
openstack resource provider allocation show
5294f726-33d5-472a-bef1-9e19bb41626d
- 创建密钥对,用于宿主机与虚拟机连接
ssh-keygen -q -N "" -f ~/.ssh/id_rsa
openstack keypair create --public-key ~/.ssh/id_rsa.pub host_dashboard
- 添加IP
ifconfig eth1 172.16.0.11/24 up
,需要有配置
虚拟机console界面日志: /var/lib/nova/instances/8fcc41bc-25ab-4f5d-b319-ab83929605eb/console.log
计算节点glances镜像缓存路径:/var/lib/nova/instances/_base/
- ubuntu2204创建实例-配置
创建实例默认无法密码登录
#!/bin/bash
echo "UseDNS no" >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
echo "PubkeyAcceptedAlgorithms=+ssh-rsa" >> /etc/ssh/sshd_config
sed -i 's#PasswordAuthentication no#PasswordAuthentication yes#g' /etc/ssh/sshd_config.d/60-cloudimg-settings.conf
service ssh restart
2
3
4
5
6