【问题标题】:Getting Connection refused for tcp connection SysLog Golang为 tcp 连接获取连接被拒绝 SysLog Golang
【发布时间】:2017-07-02 12:08:21
【问题描述】:

我在 golang 的 ubuntu 16.4 操作系统上使用 syslog 来记录如下错误。

w, err = syslog.Dial("tcp", "localhost:2114", syslog.LOG_ERR, "testapi")

这里出现以下错误。

拨号 tcp 127.0.0.1:2114:getsockopt:连接被拒绝

我已经尝试过以下事情。

  1. 使用 - sudo ufw allow 2114 命令在防火墙中启用端口。
  2. 禁用防火墙并尝试。
  3. 通过上述步骤尝试了其他端口。

任何帮助将不胜感激。

这里是 syslog.conf

#  /etc/rsyslog.conf    Configuration file for rsyslog.
#
#           For more information see
#           /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
#  Default logging rules can be found in /etc/rsyslog.d/50-default.conf


#################
#### MODULES ####
#################

module(load="imuxsock") # provides support for local system logging
module(load="imklog")   # provides kernel logging support
#module(load="immark")  # provides --MARK-- message capability

# provides UDP syslog reception
#module(load="imudp")
#input(type="imudp" port="514")

# provides TCP syslog reception
#module(load="imtcp")
#input(type="imtcp" port="514")

# Enable non-kernel facility klog messages
$KLogPermitNonKernelFacility on

##########################
#### GLOBAL DIRECTIVES ####
##########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Filter duplicated messages
$RepeatedMsgReduction on

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

【问题讨论】:

  • 2114 是非标准端口,但 syslog 通常是 udp 而不是 tcp,特殊配置或 tls 除外。也许 syslog.Dial("udp", "localhost:2114", syslog.LOG_ERR, "testapi") ?不幸的是,即使它不正确,您也不会出错,因为 udp 是无连接的。
  • 我也试过 5514 但它不起作用!非标准端口是什么意思?
  • 你应该发布你的 syslog.conf
  • 你能检查一下是否有进程绑定到2114吗?
  • 添加了 syslog.conf。

标签: ubuntu go tcp


【解决方案1】:

你需要取消注释

#module(load="imtcp")
#input(type="imtcp" port="514")

提供 syslog TCP 接收。完成此操作后,重新启动 syslog 服务即可工作。
如果您想在端口2114 上监听 tcp,您需要将输入更改为

input(type="imtcp" port="2114")

【讨论】:

  • udp 514 是默认的?
  • 好的,让我检查一下
  • 是的 514 UDP、601 TCP 和另一个我不记得的 TLS (6514)
  • @Tinwor - 拨号 tcp 127.0.0.1:514 遇到同样的错误:getsockopt:连接被拒绝。我应该使用 601 吗?
  • 好吧,如果你想用作 tcp 是的,否则如果你想用作 ump 使用 514
猜你喜欢
  • 2020-01-01
  • 2020-12-31
  • 2016-08-18
  • 1970-01-01
  • 2017-01-13
  • 2020-10-07
  • 1970-01-01
  • 1970-01-01
  • 2017-08-08
相关资源
最近更新 更多