Difference between revisions of "OpenStack: Deploying Instances using the command line"
Jump to navigation
Jump to search
(Created page with "<syntaxhighlight> [root@server2-a ~(keystone_admin)]$ source keystonerc_myuser [root@server2-a ~(keystone_myuser)]$ cp /etc/issue /tmp/ [root@server2-a ~(keystone_myuser)]$ echo "Instal...") |
|||
| Line 1: | Line 1: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
| − | [root@server2-a ~(keystone_admin)]$ source keystonerc_myuser | + | [root@server2-a ~(keystone_admin)]$ source keystonerc_myuser |
| + | </syntaxhighlight> | ||
| + | |||
| + | * Create a file which well inject later: | ||
| + | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ cp /etc/issue /tmp/ | [root@server2-a ~(keystone_myuser)]$ cp /etc/issue /tmp/ | ||
[root@server2-a ~(keystone_myuser)]$ echo "Installed using nova command-line" >> /tmp/issue | [root@server2-a ~(keystone_myuser)]$ echo "Installed using nova command-line" >> /tmp/issue | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * Create a key-pair: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ nova keypair-add key1 > /root/key1 | [root@server2-a ~(keystone_myuser)]$ nova keypair-add key1 > /root/key1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * Create a security group to allow SSH access: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ nova secgroup-create mysecgroup "SSH" | [root@server2-a ~(keystone_myuser)]$ nova secgroup-create mysecgroup "SSH" | ||
| Line 18: | Line 24: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * Add a rule to allow SSH access to that security group: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ nova secgroup-add-rule mysecgroup tcp 22 22 0.0.0.0/0 | [root@server2-a ~(keystone_myuser)]$ nova secgroup-add-rule mysecgroup tcp 22 22 0.0.0.0/0 | ||
| Line 27: | Line 34: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * List available images (<code>glance image-list</code> would do this too): | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ nova image-list | [root@server2-a ~(keystone_myuser)]$ nova image-list | ||
| Line 36: | Line 44: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * List the available flavours: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ nova flavor-list | [root@server2-a ~(keystone_myuser)]$ nova flavor-list | ||
| Line 49: | Line 58: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * List available networks (private & public): | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ neutron net-list | [root@server2-a ~(keystone_myuser)]$ neutron net-list | ||
| Line 59: | Line 69: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * Boot an instance using information from above: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ nova boot --flavor m1.small --image small --key-name key1 --security-groups mysecgroup --nic net-id=6077b8ec-6564-49d4-a476-181b2b916ba9 --file /etc/issue=/tmp/issue test | [root@server2-a ~(keystone_myuser)]$ nova boot --flavor m1.small --image small --key-name key1 --security-groups mysecgroup --nic net-id=6077b8ec-6564-49d4-a476-181b2b916ba9 --file /etc/issue=/tmp/issue test | ||
| Line 93: | Line 104: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * After a while, do a '''<code>nova list</code>''' to see the state of the instance: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ nova list | [root@server2-a ~(keystone_myuser)]$ nova list | ||
| Line 102: | Line 114: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * Get the UID of the private port: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ neutron port-list | grep 172.25.102.26 | cut -f 2 -d "|" | [root@server2-a ~(keystone_myuser)]$ neutron port-list | grep 172.25.102.26 | cut -f 2 -d "|" | ||
| Line 107: | Line 120: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * Get the UID of the floating IP: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ neutron floatingip-list | grep 172.25.2.26 | cut -f 2 -d "|" | [root@server2-a ~(keystone_myuser)]$ neutron floatingip-list | grep 172.25.2.26 | cut -f 2 -d "|" | ||
| Line 112: | Line 126: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | * Associate the floating IP (UID) to the private port (UID) | ||
<syntaxhighlight> | <syntaxhighlight> | ||
[root@server2-a ~(keystone_myuser)]$ neutron floatingip-associate 787c484c-1497-4b6d-a0ac-617d5cce4e06 4fd4d340-6cff-4292-b0a3-6ceba7a30404 | [root@server2-a ~(keystone_myuser)]$ neutron floatingip-associate 787c484c-1497-4b6d-a0ac-617d5cce4e06 4fd4d340-6cff-4292-b0a3-6ceba7a30404 | ||
Latest revision as of 10:41, 29 April 2015
[root@server2-a ~(keystone_admin)]$ source keystonerc_myuser- Create a file which well inject later:
[root@server2-a ~(keystone_myuser)]$ cp /etc/issue /tmp/
[root@server2-a ~(keystone_myuser)]$ echo "Installed using nova command-line" >> /tmp/issue- Create a key-pair:
[root@server2-a ~(keystone_myuser)]$ nova keypair-add key1 > /root/key1- Create a security group to allow SSH access:
[root@server2-a ~(keystone_myuser)]$ nova secgroup-create mysecgroup "SSH"
+--------------------------------------+------------+-------------+
| Id | Name | Description |
+--------------------------------------+------------+-------------+
| 12707876-e557-47da-a767-7bb9e4d6b2e2 | mysecgroup | SSH |
+--------------------------------------+------------+-------------+- Add a rule to allow SSH access to that security group:
[root@server2-a ~(keystone_myuser)]$ nova secgroup-add-rule mysecgroup tcp 22 22 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+-----------+--------------+
| tcp | 22 | 22 | 0.0.0.0/0 | |
+-------------+-----------+---------+-----------+--------------+- List available images (
glance image-listwould do this too):
[root@server2-a ~(keystone_myuser)]$ nova image-list
+--------------------------------------+-------+--------+--------+
| ID | Name | Status | Server |
+--------------------------------------+-------+--------+--------+
| 40f4efd4-8239-481b-a3f4-aafb5455ec20 | small | ACTIVE | |
+--------------------------------------+-------+--------+--------+- List the available flavours:
[root@server2-a ~(keystone_myuser)]$ 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 |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+- List available networks (private & public):
[root@server2-a ~(keystone_myuser)]$ neutron net-list
+--------------------------------------+---------+------------------------------------------------------+
| id | name | subnets |
+--------------------------------------+---------+------------------------------------------------------+
| 6077b8ec-6564-49d4-a476-181b2b916ba9 | private | 0ef72eb6-cd4c-4b09-ad60-9a94051b027c 172.25.102.0/24 |
| d7e212ee-f91d-4e84-a802-252833c80940 | public | 028495a2-e735-4999-8752-687383ed855f |
+--------------------------------------+---------+------------------------------------------------------+- Boot an instance using information from above:
[root@server2-a ~(keystone_myuser)]$ nova boot --flavor m1.small --image small --key-name key1 --security-groups mysecgroup --nic net-id=6077b8ec-6564-49d4-a476-181b2b916ba9 --file /etc/issue=/tmp/issue test
+--------------------------------------+----------------------------------------------+
| Property | Value |
+--------------------------------------+----------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | nova |
| OS-EXT-STS:power_state | 0 |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | - |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| adminPass | 7s5F3o3chZhw |
| config_drive | |
| created | 2015-04-29T10:07:43Z |
| flavor | m1.small (2) |
| hostId | |
| id | eed0482f-eb5e-4c6e-afc9-49b7a402589f |
| image | small (40f4efd4-8239-481b-a3f4-aafb5455ec20) |
| key_name | key1 |
| metadata | {} |
| name | test |
| os-extended-volumes:volumes_attached | [] |
| progress | 0 |
| security_groups | mysecgroup |
| status | BUILD |
| tenant_id | 02f8b026fc754acea4466e5c1e28eecc |
| updated | 2015-04-29T10:07:43Z |
| user_id | 33ef12bce0ca4658b2a20fe7262bc908 |
+--------------------------------------+----------------------------------------------+- After a while, do a
nova listto see the state of the instance:
[root@server2-a ~(keystone_myuser)]$ nova list
+--------------------------------------+------+--------+------------+-------------+-----------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+-----------------------+
| eed0482f-eb5e-4c6e-afc9-49b7a402589f | test | ACTIVE | - | Running | private=172.25.102.26 |
+--------------------------------------+------+--------+------------+-------------+-----------------------+- Get the UID of the private port:
[root@server2-a ~(keystone_myuser)]$ neutron port-list | grep 172.25.102.26 | cut -f 2 -d "|"
4fd4d340-6cff-4292-b0a3-6ceba7a30404- Get the UID of the floating IP:
[root@server2-a ~(keystone_myuser)]$ neutron floatingip-list | grep 172.25.2.26 | cut -f 2 -d "|"
787c484c-1497-4b6d-a0ac-617d5cce4e06- Associate the floating IP (UID) to the private port (UID)
[root@server2-a ~(keystone_myuser)]$ neutron floatingip-associate 787c484c-1497-4b6d-a0ac-617d5cce4e06 4fd4d340-6cff-4292-b0a3-6ceba7a30404
Associated floatingip 787c484c-1497-4b6d-a0ac-617d5cce4e06- Confirm the associated public IP:
[root@server2-a ~(keystone_myuser)]$ nova list
+--------------------------------------+------+--------+------------+-------------+------------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+------------------------------------+
| eed0482f-eb5e-4c6e-afc9-49b7a402589f | test | ACTIVE | - | Running | private=172.25.102.26, 172.25.2.26 |
+--------------------------------------+------+--------+------------+-------------+------------------------------------+- You should be able to SSH to the instance now:
[root@server2-a ~(keystone_myuser)]$ ssh 172.25.2.26
The authenticity of host '172.25.2.26 (172.25.2.26)' can't be established.
RSA key fingerprint is a3:65:f8:8e:b3:f0:f9:38:49:d8:e0:31:a9:43:f9:26.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.25.2.26' (RSA) to the list of known hosts.
root@172.25.2.26's password:
Last login: Wed Apr 29 06:12:04 2015
[root@host-172-25-102-26 ~]# exit
logout
Connection to 172.25.2.26 closed.[root@server2-a ~(keystone_myuser)]$ nova keypair-show key1 | grep Public | cut -f 2 -d ":" > /root/key1.pub
[root@server2-a ~(keystone_myuser)]$ ssh-copy-id -i /root/key1.pub root@172.25.2.26
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.2.26's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.2.26'"
and check to make sure that only the key(s) you wanted were added.[root@server2-a ~(keystone_myuser)]$ chmod 600 /root/key1
[root@server2-a ~(keystone_myuser)]$ ssh -i /root/key1 root@172.25.2.26
Last login: Wed Apr 29 06:17:31 2015 from 172.25.2.10
[root@host-172-25-102-26 ~]#- On another terminal:
[root@server2-a ~]# source /root/keystonerc_myuser
[root@server2-a ~(keystone_myuser)]$ cinder create --display-name vol1 2
+---------------------+--------------------------------------+
| Property | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| created_at | 2015-04-29T10:26:43.346741 |
| display_description | None |
| display_name | vol1 |
| encrypted | False |
| id | e004c30a-64ff-45f8-b957-da04192cdad4 |
| metadata | {} |
| size | 2 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| volume_type | None |
+---------------------+--------------------------------------+
[root@server2-a ~(keystone_myuser)]$ cinder list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| e004c30a-64ff-45f8-b957-da04192cdad4 | available | vol1 | 2 | None | false | |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
[root@server2-a ~(keystone_myuser)]$ nova volume-attach test e004c30a-64ff-45f8-b957-da04192cdad4 auto
+----------+--------------------------------------+
| Property | Value |
+----------+--------------------------------------+
| device | /dev/vdb |
| id | e004c30a-64ff-45f8-b957-da04192cdad4 |
| serverId | eed0482f-eb5e-4c6e-afc9-49b7a402589f |
| volumeId | e004c30a-64ff-45f8-b957-da04192cdad4 |
+----------+--------------------------------------+
[root@server2-a ~(keystone_myuser)]$ cinder list
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+
| e004c30a-64ff-45f8-b957-da04192cdad4 | in-use | vol1 | 2 | None | false | eed0482f-eb5e-4c6e-afc9-49b7a402589f |
+--------------------------------------+--------+--------------+------+-------------+----------+--------------------------------------+- Back in the original terminal (still SSH'd into the new instance):
[root@host-172-25-102-26 ~]# fdisk -cul /dev/vdb
Disk /dev/vdb: 2147 MB, 2147483648 bytes
16 heads, 63 sectors/track, 4161 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000