openstack.md 3.26 KB
Newer Older
Bo-Chun Chen's avatar
Bo-Chun Chen committed
1 2 3 4 5 6 7 8 9
## OpenStack note

### Prerequisite

You need to set a bunch of thing to access OpenStack. Fortunately, you can just download OpenStack RC File from openstack dashboard by clicking your user dropdown on top right. Once you have your `openrc.sh` file downloaded, simply source it and you are good to go.

```shell
source openrc.sh
```
Bo-Chun Chen's avatar
Bo-Chun Chen committed
10 11 12 13 14 15 16

Alternatively, you can create an application credential from web UI, and download the credential.

```shell
source app-cred.sh
```

Bo-Chun Chen's avatar
Bo-Chun Chen committed
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 71 72 73 74 75 76 77
- Virtual environment (Optional but recommended)

```shell
virtualenv osc
source osc/bin/activate
```

- OpenStack CLI

Everything starts with the CLI unless you have web interface. So, let's install it via pip.

```shell
pip install python-openstackclient
```

- Auto-completion (Optional)

OpenStack CLI provides lots of command to interactive with OpenStack. It might be a little to much to memorize all of the command. You can setup auto-completion to make it a little bit easier.

```shell
# On most Linux Environment
openstack complete | sudo tee /etc/bash_completion.d/osc.bash_completion > /dev/null

# On MAC with bash-completion installed by homebrew
openstack complete | sudo tee /usr/local/etc/bash_completion.d/osc.bash_completion > /dev/null
```

## Launch first instance from CLI

Following instruction from manual provided by bright cluster manager. Starting from Section 1.4

- Add keypair

```shell
openstack keypair create --public-key ~/.ssh/id_rsa.pub key_name
```

- Create Public Network and subnet

```shell
openstack network create brightnet
openstack subnet create --dns-nameserver 8.8.8.8 --subnet-range 192.168.1.0/24 --network brightnet brightsubnet
```

- Create Private Network and subnet

```shell
openstack network create compute
openstack subnet create --no-dhcp --subnet-range 10.1.1.0/24 --network compute computesubnet
```

- Create router attach to external network

```shell
openstack router create brightrouter

networkidbrightnet=$(openstack network list -c ID --name brightnet -f value)
openstack router set brightrouter --external-gateway bright-external-flat-externalnet
openstack router add subnet brightrouter brightsubnet
```

Bo-Chun Chen's avatar
Bo-Chun Chen committed
78 79 80 81 82 83 84 85
- Create VM with Centos image

```shell
networkidbrightnet=$(openstack network list -c ID --name brightnet -f value)
networkidcompute=$(openstack network list -c ID --name compute -f value)
openstack server create --image CentOS-7-x86_64-GenericCloud-1905 --flavor m1.medium --key-name louis-key --nic net-id=$networkidbrightnet --nic net-id=$networkidcompute louis-vm1
```

Bo-Chun Chen's avatar
Bo-Chun Chen committed
86 87 88 89 90 91 92 93 94 95 96 97
- Create floating IP and attach to the VM

```shell
openstack floating ip create bright-external-flat-externalnet

floatingipflatexternalnet=$(openstack floating ip list -c "Floating IP Address" -f value)
openstack server add floating ip louis-vm1 $floatingipflatexternalnet
```

- Enable port 22 in default security group

```shell
98
openstack security group rule create --protocol tcp --dst-port 22 default
Bo-Chun Chen's avatar
Bo-Chun Chen committed
99
```
Bo-Chun Chen's avatar
Bo-Chun Chen committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

- ssh into VM

When ssh into VMs, you will need the last octet of your floating IP.
For example, if you are assigned a floating IP 192.168.16.***158***, the IP address you will use for ssh will be: 164.111.161.***158***

```shell
# Default user for login is different depends on distribution.

# CentOS
ssh centos@164.111.161.158

# Debian
ssh admin@164.111.161.158

# Ubuntu
ssh ubuntu@164.111.161.158
```