OpenStack命令行速查表
在本文中,将介绍一些基本的" OpenStack命令行速查表"。
身份
列出已安装的用户
openstack user list
显示提供的用户属性
openstack user show <username>
创建一个用户" Willian",其密码为" redhat",电子邮件为" [email protected]",并且是"生产"项目的一部分
openstack user create --project Production --email [email protected] --password redhat --enable William
为用户" William"分配管理员角色
openstack role add --user William --project Production admin
检查分配给用户" William"的角色
openstack role assignment list --user William --project Production openstack role assignment list --user William --project Production --names
启用或者禁用用户" William"
openstack user set --disable William openstack user set --enable William
Flavor
使用1个vcpu,1 GB RAM,10 GB磁盘创建名为" m1.petite"的Flavor,并且不得公开访问
openstack flavor create --id auto --vcpus 1 --ram 1024 --disk 10 --private m1.petite
将Flavor m1.petite
分配给Engineering
项目
openstack flavor set --project Engineering m1.petite
安全组
创建名为" ssh"的安全组
openstack security group create ssh
在" ssh"安全组中添加允许ssh和icmp的规则
openstack security group rule create --ingress --protocol tcp --dst-port 22 ssh openstack security group rule create --ingress --protocol tcp --protocol icmp ssh
密钥对
在主文件夹中创建名称为" webkey"的密钥对
openstack keypair create webkey > ~/webkey.pem
Glance镜像
使用/tmp
中可用的osp-small.qcow2
文件创建Glance镜像'webimage'。
openstack image create --disk-format qcow2 --file /tmp/osp-small.qcow2 webimage
Neutron(网络)
在"工程"项目下创建一个"公共"和"私有"网络
openstack network create --external --provider-network-type flat --provider-physical-network datacentre --project Engineering --enable --no-share public openstack network create --internal --project Engineering --enable --no-share private
创建具有子网172.25.250.20/24的外部网络,网关为172.25.250.254,以及172.25.250.100-150之间的分配池
openstack subnet create --network public --no-dhcp --project Engineering --subnet-range 172.25.250.0/24 --gateway 172.25.250.254 --allocation-pool start=172.25.250.100,end=172.25.250.150 external
创建子网范围为" 192.168.1.0/24"的"内部"网络
openstack subnet create --network private --project Engineering --subnet-range 192.168.1.0/24 internal
创建和配置名称为" Router1"的路由器
openstack router add subnet Router1 internal neutron router-gateway-set Router1 public
服务器(实例)
使用flavor m1.petite创建一个实例/服务器,密钥为webkey,安全组为ssh和Router1网络。
openstack server create --image webimage --flavor m1.petite --key-name webkey --security-group ssh --nic net-id=private webserver
为实例创建一个浮动IP
openstack ip floating create public
将浮动IP分配给webserver
实例
openstack ip floating add 172.25.250.100 webserver
块存储
创建一个名为" storage"的" 2GB"块存储卷。
openstack volume create --size 2 --project Engineering storage
将存储作为/dev/sdb
添加到webserver
实例。
openstack server add volume --device /dev/sdb webserver storage
快照
在创建快照之前,将卷从webserver
实例中分离
openstack server remove volume webserver storage
这里的" strgsnap"是快照名称," storage"是添加卷的名称
openstack snapshot create --name strgsnap storage
拍摄快照后将卷添加到webserver
openstack server add volume --device /dev/sdb webserver storage
guestfish
使用" guestfish"编辑图像
yum install -y libguestfs-tools-c
这里的osd-webserver.qcow2是我们将编辑的图像
$guestfish -i --network -a /root/osd-webserver.qcow2 ><fs> command "yum -y install httpd" ><fs> command "systemctl enable httpd" ><fs> command "systemctl is-enabled httpd" enabled ><fs> command "touch /var/www/html/index.html" ><fs> edit /var/www/html/index.html ><fs> command "ls -l /var/www/html/index.html" -rw-r--r-- 1 root root 20 Oct 18 16:14 /var/www/html/index.html ><fs> command "sudo useradd Sheila" ><fs> command "sudo grep Sheila /etc/shadow" ><fs> selinux-relabel /etc/selinux/targeted/contexts/files/file_contexts / ><fs> exit
上面我们安装了httpd,启用了服务,创建了一个没有密码的用户Sheila,创建了一个虚拟的index.html文件,并更新了selinux上下文,这是最重要的部分。
没有此功能,镜像将无法工作。