测试
创建网络
网卡得开启混杂模式,否则无法路由,影响网络连通性。
创建生产者网络(公共网络)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| . admin-openrc
openstack network create --share --external \ --provider-physical-network provider \ --provider-network-type flat provider
openstack subnet create --network provider \ --allocation-pool start=203.0.113.101,end=203.0.113.201 \ --dns-nameserver 8.8.8.8 --gateway 203.0.113.1 \ --subnet-range 203.0.113.0/24 provider
|
创建自服务网络(私有项目网络)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| . demo-openrc
openstack network create selfservice
openstack subnet create --network selfservice \ --dns-nameserver 8.8.8.8 --gateway 172.16.1.1 \ --subnet-range 172.16.1.0/24 selfservice
|
创建路由
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| . demo-openrc
openstack router create router
openstack router add subnet router selfservice
openstack router set router --external-gateway provider
|
验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| . admin-openrc
ip netns
openstack port list --router router
ping -c 4 203.0.113.102
ping -c 4 172.16.1.1
|
创建类型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| . admin-openrc
openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
|
生成和配置密钥对
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| . demo-openrc
ssh-keygen -q -N "" openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
nova keypair-list
|
添加安全组规则
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| . demo-openrc
openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22 default
|
创建实例
确定实例选项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| . demo-openrc
openstack flavor list
openstack image list
openstack security group list
openstack network list
|
公共网络
创建实例,使用 provider
的网络 ID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| openstack server create --flavor m1.nano --image cirros \ --nic net-id=f70c83d3-7626-44fb-8971-eaeefeb6a09f --security-group default \ --key-name mykey provider-instance
openstack server list
|
使用虚拟控制台访问实例
1 2 3 4 5 6 7 8
| openstack console url show provider-instance
|
通过网址连接到容器,默认用户名密码为 cirros
和 gocubsgo
1 2 3 4 5
| ping -c 4 203.0.113.1
ping -c 4 www.baidu.com
|
远程访问实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| ping -c 4 203.0.113.105
ssh cirros@203.0.113.105
|
私有网络
创建实例,使用 selfservice
的网络 ID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| openstack server create --flavor m1.nano --image cirros \ --nic net-id=0cf109d0-183c-4c7e-8466-0ed3188d9179 --security-group default \ --key-name mykey selfservice-instance
openstack server list
|
使用虚拟控制台访问实例
1 2 3 4 5 6 7 8
| openstack console url show selfservice-instance
|
通过网址连接到容器,默认用户名密码为 cirros
和 gocubsgo
1 2 3 4 5
| ping -c 4 172.16.1.1
ping -c 4 www.baidu.com
|
创建浮动 IP ,使内网主机可以通过路由访问外网
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| openstack floating ip create provider
openstack server add floating ip selfservice-instance 203.0.113.103
openstack server list
ping -c 4 203.0.113.103
|
SSH 连接
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| ssh cirros@203.0.113.103
|
块存储
创建卷(需要 cinder 服务支持)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| . demo-openrc
openstack volume create --size 1 volume1
openstack volume list
|
将卷附加到实例
1 2 3 4 5 6 7 8 9 10
| openstack server add volume provider-instance volume1
openstack volume list
|
使用 ssh 连接实例,查看卷(块存储设备)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| ssh cirros@203.0.113.103 ...
sudo fdisk -l
|
参阅