netconsole

  1. 学习
    1. netconsole原理

当然这个不太适合放在硬件大目录下,但是谁让他也是种console呢?先放在这里吧

学习

netconsole原理

netconsole模块可以让printk信息(输出到控制台的信息)通过网络(UDP)发送到远程主机。

与串口控制台不同,netconsole不需要串口线和串口。另外,它可以轻易地将多台服务器的内核信息收集到一台服务器上。

首先,netconsole当前并不是默认加载的,有两个config选项控制CONFIG_NETCONSOLE、CONFIG_NETCONSOLE_DYNAMIC

然后看一下doc相关,有一些内容需要明确:

  1. 如果把这个模块搞成built-in的,需要在网卡驱动加载后再加载这个(因为可以看到netconsole需要使用netpoll,而netpoll需要等网卡准备好才可以)
  2. 加载模块时可以加一些参数,比如insmod netconsole netconsole=@/,@10.0.0.2/
.. Warning::

   the default target ethernet setting uses the broadcast
   ethernet address to send packets, which can cause increased load on
   other systems on the same ethernet segment.

.. Tip::

   some LAN switches may be configured to suppress ethernet broadcasts
   so it is advised to explicitly specify the remote agents' MAC addresses
   from the config parameters passed to netconsole.

.. Tip::

   to find out the MAC address of, say, 10.0.0.2, you may try using::

	ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2

.. Tip::

   in case the remote logging agent is on a separate LAN subnet than
   the sender, it is suggested to try specifying the MAC address of the
   default gateway (you may use /sbin/route -n to find it out) as the
   remote MAC address instead.

.. note::

   the network device (eth1 in the above case) can run any kind
   of other network traffic, netconsole is not intrusive. Netconsole
   might cause slight delays in other traffic if the volume of kernel
   messages is high, but should have no other impact.

.. note::

   if you find that the remote logging agent is not receiving or
   printing all messages from the sender, it is likely that you have set
   the "console_loglevel" parameter (on the sender) to only send high
   priority messages to the console. You can change this at runtime using::

	dmesg -n 8

   or by specifying "debug" on the kernel command line at boot, to send
   all kernel messages to the console. A specific value for this parameter
   can also be set using the "loglevel" kernel boot option. See the
   dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
   for details.

文件在drivers/net/netconsole.c中

比如:netconsole=@169.254.62.129/XXX,+514@169.254.62.1/,,意思就是从ip为169.254.62.129网卡名字为XXX向169.254.62.1地址的514端口发送

目的地址可以使用mac地址,但是源地址不可以

netconsole简单来说其实就是注册一个console设备,这样printk遍历console发送log的时候就会调用到netconsole的write方法向netconsole中写入了,而日志是怎么转发的呢?其实netconsole模块还调用netpoll_setup注册了netpoll,netconsole的write函数其实就是利用netpoll的netpoll_send_udp转发这些日志

netpoll原理见:https://yzwddsg-plus.github.io/2025/02/24/netpoll%E5%8E%9F%E7%90%86/


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 857879363@qq.com