设为首页 收藏本站
查看: 978|回复: 0

[经验分享] rsyslog netconsole(debian)二

[复制链接]

尚未签到

发表于 2018-5-14 13:25:03 | 显示全部楼层 |阅读模式
我的博客已迁移到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输出基础环境
serverA=10.1.10.250(5.0.1)客户端
serverB=10.1.10.117(7.8)服务端一、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  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-460070-1-1.html 上篇帖子: sshfs命令挂载远程目录(debian centos) 下篇帖子: Debian6 下NFS 安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表