暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

OpenWrt:发送syslog日志到服务器

han码录 2019-09-09
2964
  • 准备syslog日志服务器

    可以选择的很多,这里选择了syslog watcher,比较喜欢这种简洁而且安装包小的软件包

  • 配置OpenWrt设备

    采用Linux下比较熟悉的syslogd服务

root@:~# ps -w | grep logd
525 root 1520 S /sbin/syslogd -C4
527 root 1516 S /sbin/klogd
15104 root 1516 S N grep logd
复制

    在OpenWrt中相应的配置文件位于

/etc/config/system
复制

几个system段里相关的配置

log_ip: syslog服务器的IP地址
log_port:syslog服务器日志发送的端口号,默认514
log_proto:日志以tcp、udp形式发送,默认udp
log_remote:远程日志开关
log_prefix:在发送给syslog日志的添加前缀
log_hostname:配置发送给syslog服务器的hostname,默认为主机hostname
复制

重启设备进行测试

root@:~# logger "This is han's syslog test"
root@:~# logger "This is han's syslog test"
root@:~# logger "This is han's syslog test"
root@:~# logger "This is han's syslog test"
root@:~# logger "This is han's syslog test"
复制

使用syslog在shell下可以使用logger命令,在C中使用syslog对应的API即可

root@:~# logger --help
BusyBox v1.19.4 (2019-09-02 18:22:29 CST) multi-call binary.


Usage: logger [OPTIONS] [MESSAGE]


Write MESSAGE (or stdin) to syslog


-s Log to stderr as well as the system log
-t TAG Log using the specified tag (defaults to user name)
-p PRIO Priority (numeric or facility.level pair)
复制


文章转载自han码录,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论