Configure a VM using command line in openstack
This
page details about the basic operations in openstack using command
line. This is beginner level tutorial and explains only fundamental
commands for a novice. For more advanced level commands please explore
the links provided in reference section at the bottom of this page. In fact there are various ways to access cloud like though dashboard, command line or via orchestrator etc.
Assumptions:
1) Openstack version used : kilo
2) There are no any VMs running, no network created, no image created.
Basically openstack cloud is being used is after fresh installation
3) Image used for this demonstration is "cirros-3.4"
4) tenant/project used is "admin" So all the configuration will be reflected
for admin tenant only.
2) There are no any VMs running, no network created, no image created.
Basically openstack cloud is being used is after fresh installation
3) Image used for this demonstration is "cirros-3.4"
4) tenant/project used is "admin" So all the configuration will be reflected
for admin tenant only.
1) Source .rc file for admin user
To
use openstack cloud thorough command line, we need to source .rc file,
which is keystone_admin. By sourcing this file, environment variables
are set which are imperative to fire openstack commands.
#source keystone_admin
2) Create image:
Before launching an instance we need to specify the OS type and this has to be created and available.
#glance image-create --name cirros --is-public True --disk-format qcow2
--container-format bare < /root/cirros-0.3.4-x86_64-disk.img
Image creation can be verified using:
#glance image-list
3) Creating flavor:
There might be few flavors already created after fresh installation, like:
How to install openstack using packstack
#nova flavor-list
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1 | m1.tiny | 512 | 1 | 0 | | 1 | 1.0 | True |
| 2 | m1.small | 2048 | 20 | 0 | | 1 | 1.0 | True |
| 3 | m1.medium | 4096 | 40 | 0 | | 2 | 1.0 | True |
| 4 | m1.large | 8192 | 80 | 0 | | 4 | 1.0 | True |
| 5 | m1.xlarge | 16384 | 160 | 0 | | 8 | 1.0 | True |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
Lets create our own:
#nova flavor-create nano 6 256 2 1
where :
nano: is the name of image
6 : is the image id, which can be any integer other than already used
256 : is the amount of ram in MB
2 : is the amount of disk, in GB
1 : is the number of virtual cpu
#nova flavor-list
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1 | m1.tiny | 512 | 1 | 0 | | 1 | 1.0 | True |
| 2 | m1.small | 2048 | 20 | 0 | | 1 | 1.0 | True |
| 3 | m1.medium | 4096 | 40 | 0 | | 2 | 1.0 | True |
| 4 | m1.large | 8192 | 80 | 0 | | 4 | 1.0 | True |
| 5 | m1.xlarge | 16384 | 160 | 0 | | 8 | 1.0 | True |
| 5 | nano | 256 | 2 | 0 | | 1 | 1.0 | True |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
4) Creating network:
There should be at least one network and subnet be there to launch any VM.
#neutron net-create private1
#neutron net-create private2
where:
private1 and private2 are netowrk names.
5) Creating and attaching subnets to both networks:
#neutron subnet-create private1 10.10.10.0/24 --name private1-sub
#neutron subnet-create private2 20.20.20.0/24 --name private2-sub
where:
==> private1 and private2 are the network names which have already been created.
==> private1-sub and private2-sub are subnets attached to networks private1 and
private2 respectively.
6) Launch instance:
I am launching two cirros VMs, one for each subnet:
#nova boot vm1 --flavor nano --image cirros --nic
net-id=729722af-cdb9-4e69-9c38-9d1520e8825e
#nova boot vm2 --flavor nano --image cirros --nic
net-id=eaeed01a-f9dd-489f-bc50-4ccb172de21e
where: net-id: is the id of networks private1 and private2
8) Adding interfaces to router:
Either port or subnets can be added to router interface.
# neutron router-interface-add router1 private1-sub
# neutron router-interface-add router1 private2-sub
7) Creating router:
Since we have created two instances vm1 and vm2 each is assigned different subnet, if they
have to communicate with each other, they router. So lets create one.
# neutron router-create router1
where:
router1 : is the name of router.
9) Adding security rules for ping and remote connection
By
Default "default" security group is created if you install openstack
using packstack. If this security group is used which is by-default if
not specified, it does not allow the VMs to be pingged from outside
neither does is allow VM to ping it to other. Same is the case with
remote connection using ssh.
To make the things functioning we need to add rules for icmp and ssh.
To make the things functioning we need to add rules for icmp and ssh.
#openstack security group rule create default --protocol icmp --dst-port -1:-1
--src-ip 0.0.0.0/0
#openstack security group rule create default --protocol tcp --dst-port 22:22
--src-ip 0.0.0.0/0
10) Verification
To check the VMs status type:
#nova list
Both VMs (vm1 & vm2) should be in 'running' state.
Now open the console of these VMs using dashboard and login. Also you can ping each other to
verify whether router is functioning properly.
11) References:
No comments:
Post a Comment