Track1Agenda: exercises-log-management-syslog-ng.txt

File exercises-log-management-syslog-ng.txt, 5.5 KB (added by b.candler, 6 years ago)
Line 
1Network Management & Monitoring
2
3Using syslog-ng
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
18Please find your classmates that are using the same router as you. Get in to
19a group and do the following exercise together. That is, pick one person who will
20log in to your group's router, but all of you should assist with the actual
21configuration.
22
231. Configure your virtual routers to send syslog messages to your server:
24
25The routers are able to send syslog messages to multiple destinations,
26so that 1 router can send messages to 4 or even 5 destinations.
27We therefore need to configure the router to send messages to each of
28the PCs in the group.
29
30You will SSH to your group's router and do the following:
31
32        $ ssh cisco@10.10.X.254
33        rtrX> enable
34        rtrX# config terminal
35
36Repeat the next command "logging 10.10.X.X" for each PC in your group. That is,
37if your group is on router 6 and you are using pcs 21, 22, 23 and 24 you would
38repeat the command four times with the ip of each machine (10.10.6.21,
3910.10.6.22, and so forth).
40
41        rtrX# logging 10.10.X.X         
42
43        rtrX(config)# logging facility local0
44        rtrX(config)# logging userinfo
45        rtrX(config)# exit
46        rtrX# write memory
47
48Now run 'show logging' to see the summary of the logging configuration.
49
50        rtrX# show logging
51
52Logout from the router (exit)
53
54        rtrX# exit
55
56That's it. The router should now be sending UDP SYSLOG packets to your PC on port 514.
57To verify this log in on your PC and do the following:
58
59        $ sudo -s
60        # apt-get install tcpdump                (don't worry if it's already installed)
61        # tcpdump -e -s0 -ni eth0 port 514
62
63Then have one person in your group log bck in on the router and do the following:
64
65        $ ssh cisco@10.10.X.254
66        rtrX.ws.nsrc.org> enable
67        rtrX.ws.nsrc.org# config terminal
68        rtrX.ws.nsrc.org(config)# exit
69        rtrX.ws.nsrc.org> exit
70
71You should see some output on your PC's screen from TCPDUMP. It should look something like:
72
7302:20:24.942289 ca:02:0d:b3:00:08 > 52:54:4a:5e:68:77, ethertype IPv4 (0x0800), length 144: 10.10.0.6.63515 > 10.10.0.250.514: SYSLOG local0.notice, length: 102
7402:20:24.944376 ca:02:0d:b3:00:08 > c4:2c:03:0b:3d:3a, ethertype IPv4 (0x0800), length 144: 10.10.0.6.53407 > 10.10.0.241.514: SYSLOG local0.notice, length: 102
75
76Now you can configure the logging softeware on your PC to receive this information and log
77it to a new set of files:
78
79
802. Install syslog-ng
81
82These exercises are done as root. If you are not root on your machine then become
83root by typing:
84
85        $ sudo -s
86
87        # apt-get install syslog-ng
88
892. Edit /etc/syslog-ng/syslog-ng.conf
90
91Find the lines:
92
93source s_src {
94       system();
95       internal();
96};
97
98and change them to:
99
100source s_src {
101       system();
102       internal();
103       udp();
104};
105
106Save the file and exit.
107
108Now, create a config section for our network logs:
109
110        # cd /etc/syslog-ng/conf.d/
111
112        # editor 10-network.conf
113
114In this file, copy and paste the following:
115
116
117        filter f_routers { facility(local0); };
118
119        log {
120                        source(s_src);
121                        filter(f_routers);
122                        destination(routers);
123        };
124
125        destination routers {
126         file("/var/log/network/$YEAR/$MONTH/$DAY/$HOST-$YEAR-$MONTH-$DAY-$HOUR.log"
127         owner(root) group(root) perm(0644) dir_perm(0755) create_dirs(yes)
128         template("$YEAR $DATE $HOST $MSG\n"));
129        };
130
131
132Save the file and exit.
133
1343. Create the directory /var/log/network/
135
136        # mkdir /var/log/network/
137
1384. Restart syslog-ng:
139
140        # service syslog-ng restart
141
1425. Test syslog
143
144To be sure there are some logging messages log back in to the router, and run
145some "config" commands, then logout. e.g.
146
147        # ssh cisco@10.10.X.254
148        rtrX> enable
149        rtrX# config terminal
150        rtrX(config)# exit
151        rtrX> exit
152
153Be sure you log out of the router. If too many people log in without logging out
154then others cannot gain access to the router.
155
1566. On your PC, See if messages are starting to appear under
157   /var/log/network/2013/.../
158
159        $ cd /var/log/network
160        $ ls
161        $ cd 2013
162        $ ls
163        ... this will show you the directory for the month
164        ... cd into this directory
165        $ ls
166        ... repeat for the next level (the day of the month)
167        $ ls
168
169Troubleshooting
170
171If no files are appearing under the /var/log/network directory, then
172another command to try while logged into the router, in config mode, is
173to shutdown / no shutdown a Loopback interface, for example:
174
175        $ ssh cisco@rtrX
176
177        rtrX> enable
178        rtrX# conf t
179        rtrX(config)# interface Loopback 999
180        rtrX(config-if)# shutdown
181
182wait a few seconds
183
184        rtrX(config-if)# no shutdown
185
186Then exit, and save the config ("write mem"):
187
188        rtrX(config-if)# exit
189        rtrX(config)# exit
190        rtrX# write memory
191        rtr1# exit
192
193Check the logs under `/var/log/network`
194
195        # cd /var/log/network
196        # ls
197
198...follow the directory trail
199
200Still no logs?
201
202Try the following command to send a test log message locally:
203
204        # logger -p local0.info "Hello World\!"
205
206If a file has not been created yet under `/var/log/network`, then check your
207configuration for typos.  Don't forget to restart the syslog-ng service each
208time you change the configuration.
209
210What other commands can you think of that you can run on the router
211(BE CAREFUL!) that will trigger syslog messages? You could try logging in
212on the router and typing an incorrect password for "enable".
213
214Be sure that you do an "ls" command in your logging directory to see if a new
215log file has been created at some point.
216