1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
我的博客已迁移到xdoujiang.com请去那边和我交流 netconsole is a kernel module that sends all kernel log messages (i.e. dmesg) over the network to another computer,without involving user space (e.g. syslogd). Name "netconsole" is a misnomer because its not really a "console" ,
more like a remote logging service.It can be used either built- in or as a module.
Built- in netconsole initializes immediately after NIC cards and will bring up the
specified interface as soon as possible. The module is mainly used for capturing
kernel panic output from a headless machine,or in other situations where the
user space is no more functional.Documentation is available in the Linux kernel
tree under Documentation /networking/netconsole .txt.
是一个通过网络发送所有内核日志消息(即dmesg)到另一台计算机的内核模块, 且无需用户空间(如syslogd的)。 "netconsole" 这个名字不是很恰当,
因为它不是一个真正的“控制台”,更像是一个远程日志服务。 它可以内建或者编译成模块使用.内建式的netconsole在网卡后立即初始化以尽快建立指定的接口. 模块方式一般用于获取无屏幕系统或用户空间无法工作时的kernel panic输出 |
1
2
3
|
基础环境 serverA=10.1.10.250(5.0.1)客户端 serverB=10.1.10.117(7.8)服务端 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
一、10.1.10.250(客户端)serverA配置 1、具体脚本 cat aaa.sh
#!/bin/bash senddev=eth0 receip=10.1.10.117 receport=8888 mac= gateway=$(ip -4 -o route get $receip| /usr/bin/cut -f 3 -d ' ' )
if echo $gateway| /bin/grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$'
then mac=$(ip -4 neigh show $gateway| /usr/bin/cut -f 5 -d ' ' )
else /bin/ping -c 2 $receip > /dev/null
mac=$(ip -4 neigh show $receip| /usr/bin/cut -f 5 -d ' ' )
fi [ x$mac = x ] && exit
echo 7 > /proc/sys/kernel/printk
/sbin/modprobe -r netconsole
/sbin/modprobe netconsole netconsole=@/$senddev,$receport@$receip/$mac
2、说明 1)modprobe命令的-r参数 -r --remove This option causes modprobe to remove rather than insert a module. 2)现在我们需要使用console功能 这边手动调整内核printk打印级别( man 2 syslog)
7 -- Enable printk to console 3)ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ] 4)ip neigh { show | flush } [ to PREFIX ] [ dev DEV ] [ nud STATE ] 5)-4 shortcut for -family inet.
6)-f, -family followed by protocol family identifier: inet, 二、10.1.10.117(服务端)serverB配置 1、创建1个以.conf结尾的文件就行了 内容如下 cat /etc/rsyslog .d /jimmygong .conf
$ModLoad imudp $UDPServerRun 8888 $template DynFile, "/opt/rsyslog/%fromhost-ip%.log"
if $fromhost-ip startswith '10.1.' then ?DynFile
& ~ 2、重启服务 /etc/init .d /rsyslog restart
三、使用和测试 1、需要给aaa.sh加执行权限 chmod +x aaa.sh
2、写进开机启动 echo /root/aaa .sh >> /etc/rc . local
3、手动执行下 bash aaa.sh
4、查看dmesg信息 dmesg| grep console
[ 0.004000] console [tty0] enabled [111098.509861] netconsole: local port 6665
[111098.509983] netconsole: local IP 0.0.0.0
[111098.510055] netconsole: interface eth0 [111098.510122] netconsole: remote port 8888 [111098.510193] netconsole: remote IP 10.1.10.117 [111098.510273] netconsole: remote ethernet address 00:0c:29:c8:87:a1 [111098.510420] netconsole: local IP 10.1.10.250
[111098.526162] console [netcon0] enabled [111098.526548] netconsole: network logging started [114036.698520] console [netcon0] enabled [114036.698621] netconsole: network logging started 5、查看是否有过来日志信息了10.1.10.117(服务端) cat /opt/rsyslog/10 .1.10.250.log
Jun 16 04:33:38 10.1.10.250 [111098.526162] console [netcon0] enabled Jun 16 04:33:38 10.1.10.250 [111098.526548] netconsole: network logging started Jun 16 05:52:23 10.1.10.250 [115824.861174] console [netcon0] enabled Jun 16 05:52:23 10.1.10.250 [115824.861460] netconsole: network logging started 四、参考文章 http: //www .cyberciti.biz /tips/linux-netconsole-log-management-tutorial .html
https: //wiki .archlinux.org /index .php /Netconsole
https: //wiki .ubuntu.com /Kernel/Netconsole
|
本文转自 xdoujiang 51CTO博客,原文链接:http://blog.51cto.com/7938217/1662524,如需转载请自行联系原作者