root / docs / examplesdir / server.rst @ 0bf38f8c
History | View | Annotate | Download (12.7 kB)
1 |
Creating Servers (Virtual Machines) |
---|---|
2 |
=================================== |
3 |
|
4 |
A `server` (also known as `virtual machine`), is created based on a registered |
5 |
`image` and a hardware setup (also known as `flavor`). |
6 |
|
7 |
Create a virtual server |
8 |
----------------------- |
9 |
|
10 |
List available flavors |
11 |
|
12 |
.. code-block:: console |
13 |
|
14 |
$ kamaki flavor list -l |
15 |
1 C1R128D1drbd |
16 |
SNF:disk_template: drbd |
17 |
disk: 1 |
18 |
id: 1 |
19 |
links: |
20 |
href: https://example.com/cyclades/compute/v2.0/flavors/1 |
21 |
rel: bookmark |
22 |
. . . . . . . |
23 |
href: https://example.com/cyclades/compute/v2.0/flavors/1 |
24 |
rel: self |
25 |
name: C1R128D1drbd |
26 |
ram: 128 |
27 |
vcpus: 1 |
28 |
2 C1R128D1plain |
29 |
SNF:disk_template: plain |
30 |
disk: 1 |
31 |
id: 2 |
32 |
links: |
33 |
href: https://example.com/cyclades/compute/v2.0/flavors/2 |
34 |
rel: bookmark |
35 |
. . . . . . . |
36 |
href: https://example.com/cyclades/compute/v2.0/flavors/2 |
37 |
rel: self |
38 |
name: C1R128D1plain |
39 |
ram: 128 |
40 |
vcpus: 1 |
41 |
|
42 |
List available images |
43 |
|
44 |
.. code-block:: console |
45 |
|
46 |
$ kamaki image list |
47 |
f1r57-1m4g3-1d Debian Base Alpha |
48 |
53c0nd-1m4g3-1d Beta Debian Base |
49 |
|
50 |
Pick the `C1R128D1drbd` (id: 1) flavor and the `Debian Base Alpha` (id: |
51 |
f1r57-1m4g3-1d) image to create a new virtual server called 'My First Server' |
52 |
|
53 |
.. code-block:: console |
54 |
|
55 |
$ kamaki server create --name='My First Server' --flavor-id=1 --image-id=f1r57-1m4g3-1d |
56 |
accessIPv4: |
57 |
accessIPv6: |
58 |
addresses: |
59 |
adminPass: Y0uW0nt5eeMeAg4in |
60 |
attachments: |
61 |
config_drive: |
62 |
created: 2013-06-19T12:34:47.362078+00:00 |
63 |
diagnostics: |
64 |
flavor: |
65 |
id: 1 |
66 |
hostId: |
67 |
id: 141 |
68 |
image: |
69 |
id: f1r57-1m4g3-1d |
70 |
key_name: None |
71 |
metadata: |
72 |
os: debian |
73 |
users: root |
74 |
name: My First Server |
75 |
progress: 0 |
76 |
security_groups: |
77 |
name: default |
78 |
status: BUILD |
79 |
suspended: False |
80 |
tenant_id: s0m3-u53r-1d |
81 |
updated: 2013-06-19T12:34:48.512867+00:00 |
82 |
user_id: s0m3-u53r-1d |
83 |
|
84 |
.. note:: The adminPass field is not stored anywhere, therefore users would |
85 |
rather write it down and change it the first time they use the virtual |
86 |
server |
87 |
|
88 |
Wait for the virtual server with id 141 to build (optional) |
89 |
|
90 |
.. code-block:: console |
91 |
|
92 |
$ kamaki server wait 141 |
93 |
<bar showing build progress, until 100%> |
94 |
Server 141 is now in ACTIVE mode |
95 |
|
96 |
Destroy the virtual server (wait is still optional) |
97 |
|
98 |
.. code-block:: console |
99 |
|
100 |
$ kamaki server delete 141 --wait |
101 |
<bar showing destruction progress, until 100%> |
102 |
Server 141 is now in DELETED mode |
103 |
|
104 |
Create Servers with networks |
105 |
---------------------------- |
106 |
|
107 |
First, check the available IPs: |
108 |
|
109 |
.. code-block:: console |
110 |
|
111 |
$ kamaki ip list |
112 |
42042 |
113 |
instance_id: 424242 |
114 |
floating_network_id: 1 |
115 |
fixed_ip_address: None |
116 |
floating_ip_address: 123.456.78.90 |
117 |
port_id: 24024 |
118 |
|
119 |
So, there is an ip (123.456.78.90) on network 1. We can use it: |
120 |
|
121 |
.. code-block:: console |
122 |
|
123 |
$ kamaki server create --network=1,123.456.78.90 --name='Extrovert Server' --flavor-id=1 --image-id=f1r57-1m4g3-1d |
124 |
... |
125 |
|
126 |
Another case it the connection to a private network (so, no IP): |
127 |
|
128 |
.. code-block:: console |
129 |
|
130 |
$ kamaki network list |
131 |
1 Public network |
132 |
7 A custom private network |
133 |
9 Another custom private network |
134 |
|
135 |
$ kamaki server create --network=7 --name='Introvert Server' --flavor-id=1 --image-id=f1r57-1m4g3-1d |
136 |
|
137 |
.. note:: Multiple *- -network* args will create a corresponding number of |
138 |
connections (nics) to the specified networks. |
139 |
|
140 |
.. note:: Ommiting *- -network* will let the cloud apply the default network |
141 |
policy. To create a server without any connections (nics), use the |
142 |
*- -no-network argument* |
143 |
|
144 |
|
145 |
Inject ssh keys to a debian server |
146 |
---------------------------------- |
147 |
|
148 |
Assume that the servers build from the image `Debian Base Alpha` accept ssh |
149 |
connections. We need to build servers that can log us as root without a |
150 |
password. This can be achieved if the `/root/.ssh/authorized_keys` file exists |
151 |
and contains the public key of the current user. |
152 |
|
153 |
Assume that the public key file of the current user is located at |
154 |
`/home/someuser/.ssh/id_rsa.pub` . We need to inject this file as |
155 |
`/root/.ssh/authorized_keys` while creating the virtual server. |
156 |
|
157 |
Luckily, Synnefo fully supports the OpenStack suggestion for file injections on |
158 |
virtual servers and kamaki features the **-p** argument (p stands for |
159 |
`PERSONALITY` and is the term used in the respective |
160 |
`respective OpenStack <http://docs.openstack.org/api/openstack-compute/2/content/CreateServers.html>`_ description). |
161 |
|
162 |
The syntax of the -p argument is something called "the personality string":: |
163 |
|
164 |
-p <local file path>[,<remote path>[,<remote owner>[,<remote group>[,<mode>]]]] |
165 |
|
166 |
e.g., |
167 |
|
168 |
-p /home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys,root,root,0777 |
169 |
|
170 |
.. note:: In case of omitting an optional part of the personality string, the |
171 |
default behavior depends on the remote server, e.g., for a debian image we |
172 |
expect the file to have root ownership, if the ownership is not specified. |
173 |
|
174 |
Create a virtual server while injecting current user public key to root account |
175 |
|
176 |
.. code-block:: console |
177 |
|
178 |
$ kamaki server create --name='NoPassword Server' --flavor-id=1 --image-id=f1r57-1m4g3-1d \ |
179 |
--network=1,123.456.78.90 \ |
180 |
-p /home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys |
181 |
|
182 |
accessIPv4: |
183 |
accessIPv6: |
184 |
addresses: |
185 |
adminPass: Th1s1s4U5elessTh1ngN0w |
186 |
attachments: |
187 |
config_drive: |
188 |
created: 2013-06-19T12:34:47.362078+00:00 |
189 |
diagnostics: |
190 |
flavor-id: 1 |
191 |
hostId: |
192 |
id: 142 |
193 |
image-id: f1r57-1m4g3-1d |
194 |
key_name: None |
195 |
metadata: |
196 |
os: debian |
197 |
users: root |
198 |
name: No Password Server |
199 |
progress: 0 |
200 |
status: BUILD |
201 |
suspended: False |
202 |
tenant_id: s0m3-u53r-1d |
203 |
updated: 2013-06-19T12:34:48.512867+00:00 |
204 |
user_id: s0m3-u53r-1d |
205 |
|
206 |
When the server is ready, we can connect through the public network 1 and the |
207 |
IP 123.456.78.90 : |
208 |
|
209 |
.. code-block:: console |
210 |
|
211 |
$ ssh root@123.456.78.90 |
212 |
Linux remote-virtual server-4241 2.6.32-5-amd64 #1 SMP XXXX x86_64 |
213 |
|
214 |
The programs included with the Debian GNU/Linux system are free software; |
215 |
the exact distribution terms for each program are described in the |
216 |
individual files in /usr/share/doc/*/copyright. |
217 |
|
218 |
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent |
219 |
permitted by applicable law. |
220 |
root@remote-virtual server-4241:~# ls -l .ssh/ |
221 |
total 4 |
222 |
-rw-r--r-- 1 root root 399 Jun 19 12:34 authorized_keys |
223 |
root@remote-virtual server-4241:~# |
224 |
|
225 |
You can now log to your remote virtual server as root, without a password. Well done! |
226 |
|
227 |
.. note:: There is no reason to limit injections to ssh keys. Users with an |
228 |
adequate understanding of the remote OS are encouraged to prepare and |
229 |
inject all kinds of useful files, e.g., **lists of package sources**, |
230 |
**default user profiles**, **device mount configurations**, etc. |
231 |
|
232 |
Clusters of virtual servers |
233 |
--------------------------- |
234 |
|
235 |
A virtual cluster is a number of virtual servers which have names starting with |
236 |
the same prefix e.g., *cluster1*, *cluster2*, etc. This prefix acts as the |
237 |
cluster name. Still, users must be careful not to confuse cluster servers with |
238 |
other servers that coincidentally have the same prefix (e.g., |
239 |
*cluster_of_stars*). |
240 |
|
241 |
First, let's create a cluster of 4 servers. Each server will run the image with |
242 |
id *f1r57-1m4g3-1d* on the hardware specified by the flavor with id *1*. The |
243 |
prefix of the cluster will be "my cluster " |
244 |
|
245 |
.. code-block:: console |
246 |
|
247 |
$ kamaki |
248 |
$ kamaki server |
249 |
$ kamaki server create --name="my cluster " --flavor-id=1 --image=if1r57-1m4g3-1d --cluster-size=4 --wait |
250 |
... <omitted for clarity> |
251 |
adminPass: S0mePassw0rd0n3 |
252 |
flavor-id: 1 |
253 |
id: 322 |
254 |
image-id: f1r57-1m4g3-1d |
255 |
name: my cluster 1 |
256 |
[progress bar waiting server to build] |
257 |
Server 321: status is now ACTIVE |
258 |
|
259 |
... <omitted for clarity> |
260 |
adminPass: S0mePassw0rdTwo |
261 |
flavor-id: 1 |
262 |
id: 321 |
263 |
image-id: f1r57-1m4g3-1d |
264 |
name: my cluster 2 |
265 |
[progress bar waiting server to build] |
266 |
Server 322: status is now ACTIVE |
267 |
|
268 |
... <omitted for clarity> |
269 |
adminPass: S0mePassw0rdThree |
270 |
created: 2013-06-19T12:34:55.362078+00:00 |
271 |
flavor0id: 1 |
272 |
id: 323 |
273 |
image-id: f1r57-1m4g3-1d |
274 |
name: my cluster 3 |
275 |
[progress bar waiting server to build] |
276 |
Server 323: status is now ACTIVE |
277 |
|
278 |
... <omitted for clarity> |
279 |
adminPass: S0mePassw0rdFour |
280 |
created: 2013-06-19T12:34:59.362078+00:00 |
281 |
flavor-id: 1 |
282 |
id: 324 |
283 |
image-id: f1r57-1m4g3-1d |
284 |
name: my cluster 4 |
285 |
[progress bar waiting server to build] |
286 |
Server 324: status is now ACTIVE |
287 |
|
288 |
.. note:: The virtual servers can be created asynchronously. To activate |
289 |
asynchronous operations, set max_theads to some value greater than 1. |
290 |
Default is 1, though. |
291 |
|
292 |
.. code-block:: console |
293 |
|
294 |
# Create a cluster using multithreading (4 threads) |
295 |
|
296 |
$ kamaki server create --name="my cluster " --flavor-id=1 --image=if1r57-1m4g3-1d --cluster-size=4 --wait --threads=4 |
297 |
|
298 |
.. note:: the *- - wait* argument is optional, but if not used, the *create* |
299 |
call will terminate as long as the servers are spawned, even if they are |
300 |
not built yet. |
301 |
|
302 |
.. warning:: The server details (password, etc.) are printed in |
303 |
**standard output** while the progress bar and notification messages are |
304 |
printed in **standard error** |
305 |
|
306 |
Now, let's see our clusters: |
307 |
|
308 |
.. code-block:: console |
309 |
|
310 |
$ kamaki server list --name-prefix 'my cluster ' |
311 |
321 my cluster 2 |
312 |
322 my cluster 1 |
313 |
323 my cluster 3 |
314 |
324 my cluster 4 |
315 |
|
316 |
For demonstration purposes, let's suppose that the maximum resource limit is |
317 |
reached if we create 2 more servers. We will attempt to expand "my cluster" by |
318 |
4 servers, expecting kamaki to raise a quota error. |
319 |
|
320 |
.. code-block:: console |
321 |
|
322 |
$ kamaki server create --name="my cluster " --flavor-id=1 --image-id=f1r57-1m4g3-1d --cluster-size=4 --wait |
323 |
Failed to build 4 servers |
324 |
Found 2 matching servers: |
325 |
325 my cluster 1 |
326 |
326 my cluster 2 |
327 |
Check if any of these servers should be removed |
328 |
|
329 |
(413) REQUEST ENTITY TOO LARGE overLimit (Resource Limit Exceeded for your |
330 |
account.) |
331 |
| Limit for resource 'Virtual Machine' exceeded for your account. |
332 |
Available: 0, Requested: 1 |
333 |
|
334 |
The cluster expansion has failed, but 2 of the attempted 4 servers are being |
335 |
created right now. It's up to the users judgment to destroy or keep them. |
336 |
|
337 |
First, we need to list all servers: |
338 |
|
339 |
.. code-block:: console |
340 |
|
341 |
$ kamaki server list --name-prefix="my cluster " |
342 |
321 my cluster 2 |
343 |
322 my cluster 1 |
344 |
323 my cluster 3 |
345 |
324 my cluster 4 |
346 |
325 my cluster 1 |
347 |
326 my cluster 2 |
348 |
|
349 |
.. warning:: Kamaki will always create clusters by attaching an increment at |
350 |
the right of the prefix. The increments always start from 1. |
351 |
|
352 |
Now, our cluster seems messed up. Let's destroy it and rebuilt it. |
353 |
|
354 |
.. code-block:: console |
355 |
|
356 |
$ kamaki server delete --cluster "my cluster " --wait |
357 |
[progress bar waiting server to be deleted] |
358 |
Server 321: status is now DELETED |
359 |
|
360 |
[progress bar waiting server to be deleted] |
361 |
Server 322: status is now DELETED |
362 |
|
363 |
[progress bar waiting server to be deleted] |
364 |
Server 323: status is now DELETED |
365 |
|
366 |
[progress bar waiting server to be deleted] |
367 |
Server 324: status is now DELETED |
368 |
|
369 |
[progress bar waiting server to be deleted] |
370 |
Server 325: status is now DELETED |
371 |
|
372 |
[progress bar waiting server to be deleted] |
373 |
Server 326: status is now DELETED |
374 |
|
375 |
.. note:: *delete* performs a single deletion if fed with a server id, but it |
376 |
performs a mass deletion based on the name, if called with --cluster |
377 |
|
378 |
While creating the first cluster, we had to write down all passwords |
379 |
|
380 |
The passwords for each server are printed on the console while creating them. |
381 |
It would be far more convenient, though, if we could massively inject an ssh |
382 |
key into all of them. Let's do that! |
383 |
|
384 |
.. code-block:: console |
385 |
|
386 |
$ kamaki server create --name="my new cluster " --flavor-id=1 --image-id=f1r57-1m4g3-1d --cluster-size=4 --wait --personality=/home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys,root,root,0777 |
387 |
|
388 |
... <output omitted for clarity> |
389 |
|
390 |
Now, let's check if the cluster has been created. |
391 |
|
392 |
.. code-block:: console |
393 |
|
394 |
$ kamaki server list --name-prefix="my new cluster " |
395 |
321 my new cluster 1 |
396 |
322 my new cluster 2 |
397 |
323 my new cluster 3 |
398 |
324 my new cluster 4 |
399 |
|
400 |
We now have a cluster of 4 virtual servers and we can ssh in all of them |
401 |
without a password. |