root / docs / collection_of_examples / server.rst @ 404eb288
History | View | Annotate | Download (6.4 kB)
1 | 76e9db55 | Stavros Sachtouris | Creating Servers (Virtual Machines) |
---|---|---|---|
2 | 76e9db55 | Stavros Sachtouris | =================================== |
3 | 76e9db55 | Stavros Sachtouris | |
4 | 76e9db55 | Stavros Sachtouris | A `server` (also known as `virtual machine`), is created based on a registered |
5 | 76e9db55 | Stavros Sachtouris | `image` and a reconfigured hardware setup (also known as `flavor`). |
6 | 76e9db55 | Stavros Sachtouris | |
7 | 76e9db55 | Stavros Sachtouris | Create a virtual server |
8 | 76e9db55 | Stavros Sachtouris | ----------------------- |
9 | 76e9db55 | Stavros Sachtouris | |
10 | 76e9db55 | Stavros Sachtouris | List available flavors |
11 | 76e9db55 | Stavros Sachtouris | |
12 | 76e9db55 | Stavros Sachtouris | .. code-block:: console |
13 | 76e9db55 | Stavros Sachtouris | |
14 | 76e9db55 | Stavros Sachtouris | [kamaki]: flavor list -l |
15 | 76e9db55 | Stavros Sachtouris | 1 C1R128D1drbd |
16 | 76e9db55 | Stavros Sachtouris | SNF:disk_template: drbd |
17 | 76e9db55 | Stavros Sachtouris | disk: 1 |
18 | 76e9db55 | Stavros Sachtouris | id: 1 |
19 | 76e9db55 | Stavros Sachtouris | links: |
20 | 76e9db55 | Stavros Sachtouris | href: https://example.com/cyclades/compute/v2.0/flavors/1 |
21 | 76e9db55 | Stavros Sachtouris | rel: bookmark |
22 | 76e9db55 | Stavros Sachtouris | . . . . . . . |
23 | 76e9db55 | Stavros Sachtouris | href: https://example.com/cyclades/compute/v2.0/flavors/1 |
24 | 76e9db55 | Stavros Sachtouris | rel: self |
25 | 76e9db55 | Stavros Sachtouris | name: C1R128D1drbd |
26 | 76e9db55 | Stavros Sachtouris | ram: 128 |
27 | 76e9db55 | Stavros Sachtouris | vcpus: 1 |
28 | 76e9db55 | Stavros Sachtouris | 2 C1R128D1plain |
29 | 76e9db55 | Stavros Sachtouris | SNF:disk_template: plain |
30 | 76e9db55 | Stavros Sachtouris | disk: 1 |
31 | 76e9db55 | Stavros Sachtouris | id: 2 |
32 | 76e9db55 | Stavros Sachtouris | links: |
33 | 76e9db55 | Stavros Sachtouris | href: https://example.com/cyclades/compute/v2.0/flavors/2 |
34 | 76e9db55 | Stavros Sachtouris | rel: bookmark |
35 | 76e9db55 | Stavros Sachtouris | . . . . . . . |
36 | 76e9db55 | Stavros Sachtouris | href: https://example.com/cyclades/compute/v2.0/flavors/2 |
37 | 76e9db55 | Stavros Sachtouris | rel: self |
38 | 76e9db55 | Stavros Sachtouris | name: C1R128D1plain |
39 | 76e9db55 | Stavros Sachtouris | ram: 128 |
40 | 76e9db55 | Stavros Sachtouris | vcpus: 1 |
41 | 76e9db55 | Stavros Sachtouris | [kamaki]: |
42 | 76e9db55 | Stavros Sachtouris | |
43 | 76e9db55 | Stavros Sachtouris | List available images |
44 | 76e9db55 | Stavros Sachtouris | |
45 | 76e9db55 | Stavros Sachtouris | .. code-block:: console |
46 | 76e9db55 | Stavros Sachtouris | |
47 | 76e9db55 | Stavros Sachtouris | [kamaki]: image compute list |
48 | 76e9db55 | Stavros Sachtouris | f1r57-1m4g3-1d Debian Base Alpha |
49 | 76e9db55 | Stavros Sachtouris | 53c0nd-1m4g3-1d Beta Debian Base |
50 | 76e9db55 | Stavros Sachtouris | [kamaki]: |
51 | 76e9db55 | Stavros Sachtouris | |
52 | 76e9db55 | Stavros Sachtouris | Let's pick the `C1R128D1drbd` (id: 1) flavor and the `Debian Base Alpha` (id: |
53 | 76e9db55 | Stavros Sachtouris | f1r57-1m4g3-1d) image to create a new VM called 'My First Server' |
54 | 76e9db55 | Stavros Sachtouris | |
55 | 76e9db55 | Stavros Sachtouris | .. code-block:: console |
56 | 76e9db55 | Stavros Sachtouris | |
57 | 76e9db55 | Stavros Sachtouris | [kamaki]: server create 'My First Server' 1 f1r57-1m4g3-1d |
58 | 76e9db55 | Stavros Sachtouris | accessIPv4: |
59 | 76e9db55 | Stavros Sachtouris | accessIPv6: |
60 | 76e9db55 | Stavros Sachtouris | addresses: |
61 | 76e9db55 | Stavros Sachtouris | adminPass: Y0uW0nt5eeMeAg4in |
62 | 76e9db55 | Stavros Sachtouris | attachments: |
63 | 76e9db55 | Stavros Sachtouris | config_drive: |
64 | 76e9db55 | Stavros Sachtouris | created: 2013-06-19T12:34:47.362078+00:00 |
65 | 76e9db55 | Stavros Sachtouris | diagnostics: |
66 | 76e9db55 | Stavros Sachtouris | flavor: |
67 | 76e9db55 | Stavros Sachtouris | id: 1 |
68 | 76e9db55 | Stavros Sachtouris | hostId: |
69 | 76e9db55 | Stavros Sachtouris | id: 141 |
70 | 76e9db55 | Stavros Sachtouris | image: |
71 | 76e9db55 | Stavros Sachtouris | id: f1r57-1m4g3-1d |
72 | 76e9db55 | Stavros Sachtouris | key_name: None |
73 | 76e9db55 | Stavros Sachtouris | metadata: |
74 | 76e9db55 | Stavros Sachtouris | os: debian |
75 | 76e9db55 | Stavros Sachtouris | users: root |
76 | 76e9db55 | Stavros Sachtouris | name: My First Server |
77 | 76e9db55 | Stavros Sachtouris | progress: 0 |
78 | 76e9db55 | Stavros Sachtouris | security_groups: |
79 | 76e9db55 | Stavros Sachtouris | name: default |
80 | 76e9db55 | Stavros Sachtouris | status: BUILD |
81 | 76e9db55 | Stavros Sachtouris | suspended: False |
82 | 76e9db55 | Stavros Sachtouris | tenant_id: s0m3-u53r-1d |
83 | 76e9db55 | Stavros Sachtouris | updated: 2013-06-19T12:34:48.512867+00:00 |
84 | 76e9db55 | Stavros Sachtouris | user_id: s0m3-u53r-1d |
85 | 76e9db55 | Stavros Sachtouris | [kamaki]: |
86 | 76e9db55 | Stavros Sachtouris | |
87 | 76e9db55 | Stavros Sachtouris | .. note:: The adminPass field is not stored anywhere, therefore users would |
88 | 76e9db55 | Stavros Sachtouris | rather write it down and change it the first time they use the VM |
89 | 76e9db55 | Stavros Sachtouris | |
90 | 76e9db55 | Stavros Sachtouris | Wait for the VM with id 141 to build (optional) |
91 | 76e9db55 | Stavros Sachtouris | |
92 | 76e9db55 | Stavros Sachtouris | .. code-block:: console |
93 | 76e9db55 | Stavros Sachtouris | |
94 | 76e9db55 | Stavros Sachtouris | [kamaki]: server wait 141 |
95 | 76e9db55 | Stavros Sachtouris | <bar showing build progress, until 100%> |
96 | 76e9db55 | Stavros Sachtouris | Server 141 is not in ACTIVE mode |
97 | 76e9db55 | Stavros Sachtouris | [kamaki]: |
98 | 76e9db55 | Stavros Sachtouris | |
99 | 76e9db55 | Stavros Sachtouris | Destroy the VM (wait is still optional) |
100 | 76e9db55 | Stavros Sachtouris | |
101 | 76e9db55 | Stavros Sachtouris | .. code-block:: console |
102 | 76e9db55 | Stavros Sachtouris | |
103 | 76e9db55 | Stavros Sachtouris | [kamaki]: server delete 141 |
104 | 76e9db55 | Stavros Sachtouris | [kamaki]: server wait 141 ACTIVE |
105 | 76e9db55 | Stavros Sachtouris | <bar showing destruction progress, until 100%> |
106 | 76e9db55 | Stavros Sachtouris | Server 141 is not in DELETED mode |
107 | 76e9db55 | Stavros Sachtouris | [kamaki]: |
108 | 76e9db55 | Stavros Sachtouris | |
109 | ef04bdeb | Stavros Sachtouris | Inject ssh keys to a debian server |
110 | 76e9db55 | Stavros Sachtouris | ---------------------------------- |
111 | 76e9db55 | Stavros Sachtouris | |
112 | 76e9db55 | Stavros Sachtouris | Assume that the servers build from the image `Debian Base Alpha` accept ssh |
113 | 76e9db55 | Stavros Sachtouris | connections. We need to build servers that can log us as roots without a |
114 | 76e9db55 | Stavros Sachtouris | password. This can be achieved if the `/root/.ssh/authorized_keys` file exists |
115 | 76e9db55 | Stavros Sachtouris | and contains the public key of the current user. |
116 | 76e9db55 | Stavros Sachtouris | |
117 | 76e9db55 | Stavros Sachtouris | Assume that the public key file of the current user is located at |
118 | 76e9db55 | Stavros Sachtouris | `/home/someuser/.ssh/id_rsa.pub` . We need a method of injecting this file as |
119 | 76e9db55 | Stavros Sachtouris | `/root/.ssh/authorized_keys` while creating the virtual server. |
120 | 76e9db55 | Stavros Sachtouris | |
121 | 76e9db55 | Stavros Sachtouris | Luckily, Synnefo fully supports the OpenStack suggestion for file injections on |
122 | 76e9db55 | Stavros Sachtouris | VMs and kamaki allows it by using the **-p** argument (p stands for |
123 | 76e9db55 | Stavros Sachtouris | `PERSONALITY` and is the term used in the |
124 | 76e9db55 | Stavros Sachtouris | `respective OpenStack <http://docs.openstack.org/api/openstack-compute/2/content/CreateServers.html>`_ description). |
125 | 76e9db55 | Stavros Sachtouris | |
126 | 76e9db55 | Stavros Sachtouris | The syntax of the -p argument is something called "the personlity string":: |
127 | 76e9db55 | Stavros Sachtouris | |
128 | 76e9db55 | Stavros Sachtouris | -p <local file path>[,<remote path>[,<remote owner>[,<remote group>[,<mode>]]]] |
129 | 76e9db55 | Stavros Sachtouris | |
130 | 76e9db55 | Stavros Sachtouris | e.g. |
131 | 76e9db55 | Stavros Sachtouris | |
132 | 76e9db55 | Stavros Sachtouris | -p /home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys,root,root,0777 |
133 | 76e9db55 | Stavros Sachtouris | |
134 | 76e9db55 | Stavros Sachtouris | .. note:: In case of omitting an optional part of the personality string, the |
135 | 76e9db55 | Stavros Sachtouris | default behavior depends on the remote server, e.g. for a debian image we |
136 | 76e9db55 | Stavros Sachtouris | expect the file to have root ownership, if the ownership is not specified. |
137 | 76e9db55 | Stavros Sachtouris | |
138 | 76e9db55 | Stavros Sachtouris | Create a vm while injecting current users public key to root account |
139 | 76e9db55 | Stavros Sachtouris | |
140 | 76e9db55 | Stavros Sachtouris | .. code-block:: console |
141 | 76e9db55 | Stavros Sachtouris | |
142 | ef04bdeb | Stavros Sachtouris | [kamaki]: server |
143 | ef04bdeb | Stavros Sachtouris | [server]: create 'NoPassword Server' 1 f1r57-1m4g3-1d -p /home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys |
144 | 76e9db55 | Stavros Sachtouris | accessIPv4: |
145 | 76e9db55 | Stavros Sachtouris | accessIPv6: |
146 | 76e9db55 | Stavros Sachtouris | addresses: |
147 | 76e9db55 | Stavros Sachtouris | adminPass: Th1s1s4U5elessTh1ngN0w |
148 | 76e9db55 | Stavros Sachtouris | attachments: |
149 | 76e9db55 | Stavros Sachtouris | config_drive: |
150 | 76e9db55 | Stavros Sachtouris | created: 2013-06-19T12:34:47.362078+00:00 |
151 | 76e9db55 | Stavros Sachtouris | diagnostics: |
152 | 76e9db55 | Stavros Sachtouris | flavor: |
153 | 76e9db55 | Stavros Sachtouris | id: 1 |
154 | 76e9db55 | Stavros Sachtouris | hostId: |
155 | 76e9db55 | Stavros Sachtouris | id: 142 |
156 | 76e9db55 | Stavros Sachtouris | image: |
157 | 76e9db55 | Stavros Sachtouris | id: f1r57-1m4g3-1d |
158 | 76e9db55 | Stavros Sachtouris | key_name: None |
159 | 76e9db55 | Stavros Sachtouris | metadata: |
160 | 76e9db55 | Stavros Sachtouris | os: debian |
161 | 76e9db55 | Stavros Sachtouris | users: root |
162 | ef04bdeb | Stavros Sachtouris | name: No Password Server |
163 | 76e9db55 | Stavros Sachtouris | progress: 0 |
164 | 76e9db55 | Stavros Sachtouris | security_groups: |
165 | 76e9db55 | Stavros Sachtouris | name: default |
166 | 76e9db55 | Stavros Sachtouris | status: BUILD |
167 | 76e9db55 | Stavros Sachtouris | suspended: False |
168 | 76e9db55 | Stavros Sachtouris | tenant_id: s0m3-u53r-1d |
169 | 76e9db55 | Stavros Sachtouris | updated: 2013-06-19T12:34:48.512867+00:00 |
170 | 76e9db55 | Stavros Sachtouris | user_id: s0m3-u53r-1d |
171 | ef04bdeb | Stavros Sachtouris | [server]: |
172 | 76e9db55 | Stavros Sachtouris | |
173 | 76e9db55 | Stavros Sachtouris | When the VM is ready, get the VMs external IP from the web UI. Let's assume the |
174 | 76e9db55 | Stavros Sachtouris | IP is 123.456.78.90 . |
175 | 76e9db55 | Stavros Sachtouris | |
176 | 76e9db55 | Stavros Sachtouris | .. code-block:: console |
177 | 76e9db55 | Stavros Sachtouris | |
178 | ef04bdeb | Stavros Sachtouris | [server]: /exit |
179 | 76e9db55 | Stavros Sachtouris | $ ssh 123.456.78.90 |
180 | ef04bdeb | Stavros Sachtouris | Linux remote-vm-4241 2.6.32-5-amd64 #1 SMP XXXX x86_64 |
181 | 76e9db55 | Stavros Sachtouris | |
182 | 76e9db55 | Stavros Sachtouris | The programs included with the Debian GNU/Linux system are free software; |
183 | 76e9db55 | Stavros Sachtouris | the exact distribution terms for each program are described in the |
184 | 76e9db55 | Stavros Sachtouris | individual files in /usr/share/doc/*/copyright. |
185 | 76e9db55 | Stavros Sachtouris | |
186 | 76e9db55 | Stavros Sachtouris | Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent |
187 | 76e9db55 | Stavros Sachtouris | permitted by applicable law. |
188 | 76e9db55 | Stavros Sachtouris | root@remote-vm-4241:~# ls -l .ssh/ |
189 | 76e9db55 | Stavros Sachtouris | total 4 |
190 | ef04bdeb | Stavros Sachtouris | -rw-r--r-- 1 root root 399 Jun 19 12:34 authorized_keys |
191 | 76e9db55 | Stavros Sachtouris | root@remote-vm-4241:~# |
192 | 76e9db55 | Stavros Sachtouris | |
193 | 76e9db55 | Stavros Sachtouris | You can now log to your remote VM as root, without a password. Well done! |
194 | 76e9db55 | Stavros Sachtouris | |
195 | 76e9db55 | Stavros Sachtouris | .. note:: There is no reason to limit injections to ssh keys. Users with an |
196 | 76e9db55 | Stavros Sachtouris | adequate understanding of the remote OS are encouraged to prepare and |
197 | 76e9db55 | Stavros Sachtouris | inject all kinds of useful files, e.g. **lists of package sources**, |
198 | 76e9db55 | Stavros Sachtouris | **default user profiles**, **device mount configurations**, etc. |