Agenda: rancid-exercise.2.txt

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