Agenda: exercises-log-management-rsyslog.page

File exercises-log-management-rsyslog.page, 6.3 KB (added by brian, 7 years ago)
Line 
1% Log Management Part 1: Using rsyslog
2%
3% Network Management & Monitoring
4
5# Notes
6
7* Commands preceded with "$" imply that you should execute the command as
8  a general user - not as root.
9* Commands preceded with "#" imply that you should be working as root.
10* Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>")
11  imply that you are executing commands on remote equipment, or within
12  another program.
13
14# Exercise
15
16The routers are able to send syslog messages to multiple destinations,
17so that 1 router can send messages to 4 or even 5 destinations.
18We therefore need to configure the router to send messages to each of
19the PCs in the group.
20
21## Configure sending of syslog
22
23Configure your virtual router to send syslog messages to every server
24in your group.
25
26Everyone in your group should log into your group's router and do the
27following:
28
29~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30$ ssh cisco@rtrX
31rtrX> enable
32rtrX# config terminal
33
34rtrX(config)# logging 10.10.Y.Y
35
36... where X.Y is the IP of your PC (group + number).
37
38rtrX(config)# logging facility local5
39rtrX(config)# logging userinfo
40rtrX(config)# exit
41rtrX# write memory
42~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
44Now run `show logging` to see the summary of the log configuration.
45
46The other participants in your group will be doing the same thing,
47so you should not be surprised if you see other destinations as well
48in the output of "show logging"
49
50Logout from the router (exit):
51
52~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53rtrX# exit
54~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
56That's it. The router should now be sending UDP SYSLOG packets to your PC
57on port 514.
58
59To verify this log in on your PC and do the following:
60
61~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62$ sudo bash
63# tcpdump -s0 -n -i eth0 udp port 514
64~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65
66Then have one person in your group log back in on the router and do the
67following:
68
69~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70$ ssh cisco@rtrX
71rtrX> enable
72rtrX# config terminal
73rtrX(config)# exit
74rtrX> exit
75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76
77You should see some output on your PC's screen from `tcpdump`. It should look
78something like:
79
8002:20:24.942289 10.10.0.6.63515 > 10.10.0.250.514: SYSLOG local5.notice, length: 102
8102:20:24.944376 10.10.0.6.53407 > 10.10.0.241.514: SYSLOG local5.notice, length: 102
82
83(Aside: tcpdump will show you the *content* of the syslog messages if you
84add `-v` to the command line)
85
86Now you can configure the logging software on your PC to receive this
87information and log it to a new set of files.
88
89
90## Configure rsyslog
91
92Edit file `/etc/rsyslog.conf` and find and un-comment the following lines
93(that is, remove the initial '#' only)
94
95~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96#$ModLoad imudp
97#$UDPServerRun 514
98~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
100Then change this line:
101
102~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103$PrivDropToGroup syslog
104~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105
106to
107
108~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109$PrivDropToGroup adm
110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
112Then save the file and exit.
113
114Now, create a file named `/etc/rsyslog.d/30-routerlogs.conf` with the following lines:
115
116~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117$template       RouterLogs,"/var/log/network/%$YEAR%/%$MONTH%/%$DAY%/%HOSTNAME%-%$HOUR%.log"
118local5.*        -?RouterLogs
119& ~
120~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121
122Save and exit, then:
123
124~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125# mkdir /var/log/network
126# chown syslog:adm /var/log/network
127~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128
129Restart rsyslog:
130
131~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132# service rsyslog restart
133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134
135
136## Test syslog
137
138On your PC, See if messages are starting to appear under
139`/var/log/network/<year>/.../`
140
141~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142$ cd /var/log/network
143$ ls
144$ cd 2012
145$ ls
146... etc
147~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148
149If not, try to login back into the router, and run some "config" commands,
150then logout. e.g.
151
152~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153$ ssh cisco@rtrX
154rtrX> enable
155rtrX# config terminal
156rtrX(config)# exit
157rtrX> exit
158~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159
160Be sure you log out of the router when you are finished.  If too many people
161log in without logging out then others cannot gain access to the router.
162
163Another command to try while logged into the router, in config mode, is
164to shutdown / no shutdown a Loopback interface, for example:
165
166~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167rtrX# conf t
168rtrX(config)# interface Loopback 999
169rtrX(config-if) # shutdown
170~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171
172wait a few seconds
173
174~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175rtrX(config-if) # no shutdown
176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
178Then exit, and save the config ("write mem")
179
180Check the logs under `/var/log/network`
181
182Still no logs?
183
184Try the following command to send a test log message locally:
185
186~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187# logger -p local5.info "Hello World\!"
188~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
189
190If a file has not been created yet under `/var/log/network`, then check your
191configuration for typos.  Don't forget to restart the rsyslog service each
192time you change the configuration.
193
194What other commands can you think of that you can run on the
195router (BE CAREFUL!) that will trigger syslog messages ?
196
197What about access lists ?
198
199Others ?
200