1 | Network Management & Monitoring |
---|
2 | |
---|
3 | Using RANCID |
---|
4 | ============ |
---|
5 | |
---|
6 | Notes: |
---|
7 | ------ |
---|
8 | * Commands preceded with "$" imply that you should execute the command as |
---|
9 | a general user - not as root. |
---|
10 | * Commands preceded with "#" imply that you should be working as root. |
---|
11 | * Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") |
---|
12 | imply that you are executing commands on remote equipment, or within |
---|
13 | another program. |
---|
14 | |
---|
15 | Exercises |
---|
16 | --------- |
---|
17 | |
---|
18 | 1. Connect to your PC using ssh |
---|
19 | |
---|
20 | 2. Become root, and install postfix (mail system we are using) |
---|
21 | |
---|
22 | $ sudo bash |
---|
23 | # apt-get install postfix |
---|
24 | You might get a prompt on Postfix install, select "Internet Site" |
---|
25 | At the next prompt, enter your hostname (e.g. pcxx.ws.nsrc.org) |
---|
26 | # service postfix status |
---|
27 | |
---|
28 | Also check that the 'mutt' mail client is installed, as well as telnet |
---|
29 | and subversion: |
---|
30 | |
---|
31 | # apt-get install mutt telnet subversion |
---|
32 | |
---|
33 | |
---|
34 | 3. Add an alias for the rancid user in /etc/aliases file |
---|
35 | |
---|
36 | # editor /etc/aliases |
---|
37 | |
---|
38 | rancid-all: sysadm |
---|
39 | rancid-admin-all: sysadm |
---|
40 | |
---|
41 | Save the file, then run: |
---|
42 | |
---|
43 | # newaliases |
---|
44 | |
---|
45 | 4. Install Rancid itself |
---|
46 | |
---|
47 | # apt-get install rancid |
---|
48 | |
---|
49 | It will prompt for warning, and Really continue? Select Yes |
---|
50 | |
---|
51 | 5. Edit /etc/rancid/rancid.conf |
---|
52 | |
---|
53 | # editor /etc/rancid/rancid.conf |
---|
54 | |
---|
55 | Find this line in rancid.conf: |
---|
56 | |
---|
57 | #LIST_OF_GROUPS="sl joebobisp" |
---|
58 | |
---|
59 | And, underneath it add the following line: |
---|
60 | |
---|
61 | LIST_OF_GROUPS="all" |
---|
62 | |
---|
63 | (with no '#' at the front of line) |
---|
64 | |
---|
65 | Also, we want to use Subversion, and not CVS: |
---|
66 | |
---|
67 | Find the line with the parameter RCSSYS, and change it to: |
---|
68 | |
---|
69 | RCSSYS=svn; export RCSSYS |
---|
70 | |
---|
71 | and the line with CVSROOT: |
---|
72 | |
---|
73 | CVSROOT=$BASEDIR/svn; export CVSROOT |
---|
74 | |
---|
75 | 6. Change to the rancid user |
---|
76 | |
---|
77 | From a root prompt, switch identity to become the 'rancid' user: |
---|
78 | |
---|
79 | # su -s /bin/bash rancid |
---|
80 | |
---|
81 | Check that you ARE the rancid user: |
---|
82 | |
---|
83 | $ id |
---|
84 | |
---|
85 | You should see something similar (numbers may be different): |
---|
86 | |
---|
87 | uid=104(rancid) gid=109(rancid) groups=109(rancid) |
---|
88 | |
---|
89 | ***** IF YOU ARE NOT USER RANCID NOW, do NOT continue ****** |
---|
90 | |
---|
91 | 7. Create /var/lib/rancid/.cloginrc |
---|
92 | |
---|
93 | $ editor /var/lib/rancid/.cloginrc |
---|
94 | |
---|
95 | add user 10.10.* cisco |
---|
96 | add password 10.10.* nsrc+ws nsrc+ws |
---|
97 | |
---|
98 | (The first 'cisco' is the username, the first and second 'nsrc+ws' are the |
---|
99 | password and enable password used to login to your router. The star in the IP |
---|
100 | means that it will try to use this username and password for all routers in 10.10. |
---|
101 | network) |
---|
102 | |
---|
103 | Now protect this file so that it cannot be read by other users: |
---|
104 | |
---|
105 | $ chmod 600 /var/lib/rancid/.cloginrc |
---|
106 | |
---|
107 | In reality you want to create an extra user for RANCID on the Cisco |
---|
108 | with limited rights instead. |
---|
109 | |
---|
110 | 8. Test login to the router of your group |
---|
111 | |
---|
112 | Login to your router with clogin. You might have to type yes to the first warning, but should not need to enter a password, this should be automatic. |
---|
113 | |
---|
114 | $ /var/lib/rancid/bin/clogin 10.10.X.254 |
---|
115 | (replace x with your group no.) |
---|
116 | You should get something like: |
---|
117 | spawn ssh -c 3des -x -l cisco 10.10.2.254 |
---|
118 | The authenticity of host '10.10.2.254 (10.10.2.254)' can't be established. |
---|
119 | RSA key fingerprint is 73:f3:f0:e8:78:ab:49:1c:d9:5d:49:01:a4:e1:2a:83. |
---|
120 | Are you sure you want to continue connecting (yes/no)? |
---|
121 | Host 10.10.2.254 added to the list of known hosts. |
---|
122 | yes |
---|
123 | Warning: Permanently added '10.10.2.254' (RSA) to the list of known hosts. |
---|
124 | Password: |
---|
125 | |
---|
126 | rtr2>enable |
---|
127 | Password: |
---|
128 | rtr2# |
---|
129 | |
---|
130 | Exit the router |
---|
131 | rtr2#exit |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | 9. Initialize the SVN repository for rancid: |
---|
136 | |
---|
137 | $ /usr/lib/rancid/bin/rancid-cvs |
---|
138 | |
---|
139 | You should see something similar to this: |
---|
140 | |
---|
141 | Committed revision 1. |
---|
142 | Checked out revision 1. |
---|
143 | At revision 1. |
---|
144 | A configs |
---|
145 | Adding configs |
---|
146 | |
---|
147 | Committed revision 2. |
---|
148 | A router.db |
---|
149 | Adding router.db |
---|
150 | Transmitting file data . |
---|
151 | Committed revision 3. |
---|
152 | |
---|
153 | ***** If you have problems ****** |
---|
154 | |
---|
155 | If this does not work, then either you are missing the subversion package, or |
---|
156 | something was not properly configured during the previous steps. You should verify |
---|
157 | that subversion is installed and then before running the rancid-cvs command again |
---|
158 | do the following: |
---|
159 | |
---|
160 | $ exit |
---|
161 | # apt-get install subversion |
---|
162 | # su -s /bin/bash rancid |
---|
163 | $ cd /var/lib/rancid |
---|
164 | $ rm -rf all |
---|
165 | $ rm -rf svn |
---|
166 | |
---|
167 | Now try running the rancid-cvs command again: |
---|
168 | |
---|
169 | $ /usr/lib/rancid/bin/rancid-cvs |
---|
170 | |
---|
171 | ******************************** |
---|
172 | |
---|
173 | 10. Create the router.db |
---|
174 | |
---|
175 | $ editor /var/lib/rancid/all/router.db |
---|
176 | |
---|
177 | Add this line: |
---|
178 | |
---|
179 | 10.10.xxx.254:cisco:up |
---|
180 | |
---|
181 | (remember to replace xxx as appropriate) |
---|
182 | |
---|
183 | 11. Let's run rancid! |
---|
184 | |
---|
185 | $ /usr/lib/rancid/bin/rancid-run |
---|
186 | |
---|
187 | (Should take about half a minute) |
---|
188 | Run it again, since the first time it might not commit correctly: |
---|
189 | |
---|
190 | $ /usr/lib/rancid/bin/rancid-run |
---|
191 | |
---|
192 | 12. Check out the logs: |
---|
193 | |
---|
194 | $ cd /var/lib/rancid/logs |
---|
195 | $ ls -l |
---|
196 | |
---|
197 | ... View the contents of the file(s): |
---|
198 | |
---|
199 | $ less all.* |
---|
200 | |
---|
201 | 13. Look at the configs |
---|
202 | |
---|
203 | $ cd /var/lib/rancid/all/configs |
---|
204 | $ less 10.10.x.254 |
---|
205 | |
---|
206 | If all went well, you can see the config of the router. |
---|
207 | |
---|
208 | 14. Let's change an interface Description on the router |
---|
209 | |
---|
210 | $ /usr/lib/rancid/bin/clogin 10.10.x.254 |
---|
211 | |
---|
212 | At the "rtrX#" prompt, enter the command: |
---|
213 | |
---|
214 | rtrX# conf term |
---|
215 | |
---|
216 | You should see: |
---|
217 | |
---|
218 | Enter configuration commands, one per line. End with CNTL/Z. |
---|
219 | rtrX(config)# |
---|
220 | |
---|
221 | Enter: |
---|
222 | |
---|
223 | rtrX(config)# interface LoopbackXX (replace XX with your PC no) |
---|
224 | for example |
---|
225 | rtr5(config)# interface Loopback17 (if your PC is number 17) |
---|
226 | |
---|
227 | You should get this prompt: |
---|
228 | |
---|
229 | rtr2(config-if)# |
---|
230 | |
---|
231 | Enter: |
---|
232 | |
---|
233 | rtr2(config-if)# description <put your name here> |
---|
234 | rtr2(config-if)# end |
---|
235 | |
---|
236 | You should now have this prompt: |
---|
237 | |
---|
238 | rtr2# |
---|
239 | |
---|
240 | To save the config to memory: |
---|
241 | |
---|
242 | rtr2# write memory |
---|
243 | |
---|
244 | You should see: |
---|
245 | |
---|
246 | Building configuration... |
---|
247 | [OK] |
---|
248 | |
---|
249 | To exit type: |
---|
250 | |
---|
251 | exit |
---|
252 | |
---|
253 | 15. Let's run rancid again: |
---|
254 | |
---|
255 | $ /usr/lib/rancid/bin/rancid-run |
---|
256 | |
---|
257 | Look at the config and logs |
---|
258 | |
---|
259 | $ ls /var/lib/rancid/logs/ |
---|
260 | |
---|
261 | 16. Let's see the differences |
---|
262 | |
---|
263 | $ cd /var/lib/rancid/all/configs |
---|
264 | $ ls -l |
---|
265 | |
---|
266 | You should see all the router config files |
---|
267 | |
---|
268 | $ svn log 10.10.x.254 |
---|
269 | |
---|
270 | (where xxx is the IP of your router, .1 or .2 or 3.) |
---|
271 | |
---|
272 | Notice the revisions. Let's view the difference between two versions: |
---|
273 | |
---|
274 | $ svn diff -r 5:6 10.10.x.254 | less |
---|
275 | |
---|
276 | ... can you find your changes ? Or those of others in the same time? |
---|
277 | |
---|
278 | 17. Check your mail |
---|
279 | |
---|
280 | Now we will exit from these shells to get back to being the "sysadm" |
---|
281 | user, and run 'mutt' to see the mails which rancid has sent: |
---|
282 | |
---|
283 | $ exit |
---|
284 | # exit |
---|
285 | $ id |
---|
286 | ... check that you are now the 'sysadm' user again; |
---|
287 | ... if not, log out and in again |
---|
288 | $ mutt |
---|
289 | |
---|
290 | (When asked to create the Mail directory, say Yes) |
---|
291 | |
---|
292 | If everything goes as planned, you should be able to read the mails |
---|
293 | sent by Rancid. |
---|
294 | |
---|
295 | (use 'q' return to mail index, and 'q' again to quit mutt) |
---|
296 | |
---|
297 | 18. Let's make rancid run automatically every 30 minutes from cron |
---|
298 | |
---|
299 | $ sudo bash |
---|
300 | # crontab -e -u rancid |
---|
301 | |
---|
302 | It will ask you for your favorite editor. |
---|
303 | |
---|
304 | Add this line: |
---|
305 | |
---|
306 | */30 * * * * /usr/lib/rancid/bin/rancid-run |
---|
307 | |
---|
308 | ... then save and quit |
---|
309 | |
---|
310 | 19. Now add all the other routers |
---|
311 | Note the IP addresses for the routers |
---|
312 | |
---|
313 | 10.10.x.254 where x goes from 1 to 8 |
---|
314 | |
---|
315 | Update the router.db |
---|
316 | |
---|
317 | # su -s /bin/bash rancid |
---|
318 | $ editor /var/lib/rancid/all/router.db |
---|
319 | |
---|
320 | Add some other classroom routers to the file. You should end up with |
---|
321 | something like: |
---|
322 | |
---|
323 | 10.10.1.254:cisco:up |
---|
324 | 10.10.2.254:cisco:up |
---|
325 | 10.10.3.254:cisco:up |
---|
326 | 10.10.4.254:cisco:up |
---|
327 | 10.10.5.254:cisco:up |
---|
328 | 10.10.6.254:cisco:up |
---|
329 | 10.10.7.254:cisco:up |
---|
330 | 10.10.8.254:cisco:up |
---|
331 | |
---|
332 | |
---|
333 | (Note that "cisco" means this is Cisco equipment -- it tells Rancid |
---|
334 | that we are expecting to talk to a Cisco device here. You can also |
---|
335 | talk to Juniper, HP, ...) |
---|
336 | |
---|
337 | 20. Run rancid again: |
---|
338 | |
---|
339 | $ /usr/lib/rancid/bin/rancid-run |
---|
340 | |
---|
341 | (Should take a minute or more now, be patient) |
---|
342 | |
---|
343 | 21. Check out the logs: |
---|
344 | |
---|
345 | $ cd /var/lib/rancid/logs |
---|
346 | $ ls -l |
---|
347 | |
---|
348 | ... Pick the latest file and view it |
---|
349 | |
---|
350 | $ less all.YYYYMMDD.HHMMSS |
---|
351 | |
---|
352 | 22. Look at the configs |
---|
353 | |
---|
354 | $ cd /var/lib/rancid/all/configs |
---|
355 | $ more 10.10.* |
---|
356 | |
---|
357 | If all went well, you can see the configs of ALL routers |
---|
358 | |
---|
359 | 23. Run RANCID again just in case someone changed some configuration on the router |
---|
360 | |
---|
361 | $ /usr/lib/rancid/bin/rancid-run |
---|
362 | (patienceÉ) |
---|
363 | |
---|
364 | |
---|
365 | 23. Play with clogin: |
---|
366 | |
---|
367 | $ /usr/lib/rancid/bin/clogin -c "show clock" 10.10.x.254 |
---|
368 | |
---|
369 | What do you notice ? |
---|
370 | |
---|
371 | Even better: |
---|
372 | |
---|
373 | $ editor /tmp/commands |
---|
374 | |
---|
375 | ... in this file, add the following commands: |
---|
376 | |
---|
377 | configure terminal |
---|
378 | username afnog secret 0 afn0g |
---|
379 | exit |
---|
380 | write |
---|
381 | |
---|
382 | Save the file, exit, and run the following commands from the shell: |
---|
383 | |
---|
384 | $ for r in 1 2 3 4 |
---|
385 | do |
---|
386 | /var/lib/rancid/bin/clogin -x /tmp/commands 10.10.$r.254 |
---|
387 | done |
---|
388 | |
---|
389 | Observe - what do you notice ? How would you verify that this |
---|
390 | has executed correctly ? Hint: show run | inc |
---|
391 | |
---|
392 | |
---|
393 | 24. Add the RANCID SVN repository in to SVNWeb |
---|
394 | |
---|
395 | If you are still logged in as user rancid, get back to root |
---|
396 | |
---|
397 | $ exit |
---|
398 | # |
---|
399 | |
---|
400 | Install SVNWeb: |
---|
401 | |
---|
402 | # apt-get install websvn |
---|
403 | * Say Yes to the question if you want to configure it now |
---|
404 | * Hit Ok for the next question about supporting various web servers |
---|
405 | * As directory add /var/lib/rancid/svn both times when asked on the next screens. |
---|
406 | * Hit Ok for the next screen talking about permissions |
---|
407 | |
---|
408 | 25. Fix permissions. The web server must be able to read the SVN archive |
---|
409 | # chgrp -R www-data /var/lib/rancid/svn |
---|
410 | # chmod g+w -R /var/lib/rancid/svn |
---|
411 | |
---|
412 | |
---|
413 | 26. Browse files from your webbrowser |
---|
414 | http://pcXXX.ws.nsrc.org/websvn |
---|
415 | |
---|
416 | Browse the files under the 'all/configs' directory. |
---|
417 | You can see all your router configuration files here. |
---|
418 | |
---|
419 | |
---|
420 | |
---|
421 | 27. Review revisions |
---|
422 | |
---|
423 | If you want to see different revisions side by side, you can do that with WebSVN too. |
---|
424 | |
---|
425 | However diffs between revisions are broken in the package which comes with Ubuntu 10.04 LTS solved in the latest version |
---|
426 | |
---|
427 | Patch that bug with a simple patchfile: |
---|
428 | |
---|
429 | # apt-get install wget patch |
---|
430 | # cd /usr/share/websvn/include |
---|
431 | # wget http://noc.ws.nsrc.org/downloads/patch-svn |
---|
432 | # patch < patch-svn |
---|
433 | |
---|
434 | You can now also browse difference between file revisions with WebSVN. |
---|
435 | |
---|
436 | Browse to http://pcXXX.ws.nsrc.org/websvn again, go to all, configs |
---|
437 | Select your router file (10.10.x.254) and click "Compare with Previous" |
---|
438 | You should now see the latest changes side by side. |
---|
439 | |
---|
440 | |
---|
441 | +---- |
---|
442 | Rev. 10 May 2012 |
---|