Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1798605
  • 博文数量: 184
  • 博客积分: 10122
  • 博客等级: 上将
  • 技术积分: 5566
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-08 12:32
文章存档

2011年(1)

2008年(183)

我的朋友

分类: LINUX

2008-03-03 21:32:45

3.3. Sources and source drivers

A source is where syslog-ng receives log messages. Sources consist of one or more drivers, each defining where and how messages are received.

# 注释 :一个 source (源)就是 syslog-ng 接收日志信息的地方。source 由一个或者多个 drivers 组成,每个 driver 指出消息的位置和接收方式

To define a source, add a source statement to the syslog-ng configuration file using the following syntax:

# 注释 :要定义一个 source ,可以在 syslog-ng 的配置文件中增加一个 source 语句,格式如下

source  { source-driver(params); source-driver(params); ... };
[Example] Example 3.2. A simple source statement

The following source statement receives messages on the TCP port 1999 of the interface having the 10.1.2.3 IP address.

# 注释 :下面的语句定义一个 s_demo_tcp 的 source ,它带一个 tcp 选项和 port 选项。表示在 10.1.2.3:1999 这个本地地址:端口上接收日志

source s_demo_tcp { tcp(ip(10.1.2.3) port(1999)); };
[Example] Example 3.3. A source statement using two source drivers

The following source statement receives messages on the 1999 TCP port and the 1999 UDP port of the interface having the 10.1.2.3 IP address.

# 注释 :下面的 source 定义了两个 source drivers ,一个是 tcp 的,一个是 udp 的。地址都是 10.1.2.3,端口都是 1999

source s_demo_two_drivers { 
tcp(ip(10.1.2.3) port(1999));
udp(ip(10.1.2.3) port(1999)); };

To collect log messages on a specific platform, it is important to know how the native syslogd communicates on that platform. The following table summarizes the operation methods of syslogd on some of the tested platforms:

# 注释 :要收集某种平台上的日志消息,很重要的一点就是知道它们上面的 syslogd 是如何和 os 通信的

# 例如对于 Linux 来说,使用的是 /dev/log 这个 unix domain socket

# 补充 :要查看是什么类型的,用 netstat -ax 命令查看

[root@monitor root]# netstat -ax |grep '/dev/log'
unix  4      [ ]         DGRAM                    3346585 /dev/log
[root@monitor root]#

Platform Method
Linux A SOCK_STREAM unix socket named /dev/log; some of the distributions switched over to using SOCK_DGRAM, though applications still work with either method.
BSD flavors A SOCK_DGRAM unix socket named /var/run/log.
Solaris (2.5 or below) An SVR4 style STREAMS device named /dev/log.
Solaris (2.6 or above) In addition to the STREAMS device used in earlier versions, 2.6 uses a new multithreaded IPC method called door. By default the door used by syslogd is /etc/.syslog_door.
HP-UX 11 or later HP-UX uses a named pipe called /dev/log that is padded to 2048 bytes, e.g., source s_hp-ux {pipe ("/dev/log" pad_size(2048)}.
AIX 5.2 and 5.3 A SOCK_STREAM or SOCK_DGRAM unix socket called /dev/log.

Table 3.2. Communication methods used between the applications and syslogd

Each possible communication mechanism has a corresponding source driver in syslog-ng. For example, to open a unix socket with SOCK_DGRAM style communication use the driver unix-dgram. The same socket using the SOCK_STREAM style — as used under Linux — is called unix-stream.

# 注释 :每种可能的通信方案在 syslog-ng 中都有对应的 source driver ,例如要打开一个 unix domain socket 使用 unix-dgram 或者 unix-stream 。

[Example] Example 3.4. Source statement on a Linux based operating system

The following source statement collects the following log messages:

# 注释 :例如下面的例子定义了 3个 source driver

#     -)1、internal()表示收集来自 syslog-ng 本身 的消息

#     -)2、udp(ip (0.0.0.0)) port (514)) 表示收集本地主机的 514 端口的消息,这些是 client 端发送过来的

#     -)3、unix-stream("/dev/log") 表示来自 /dev/log 的消息

  • internal(): Messages generated by syslog-ng.

  • udp(ip(0.0.0.0) port(514)): Messages arriving to the 514/UDP port of any interface of the host.

  • unix-stream("/dev/log");: Messages arriving to the /dev/log socket.

source s_demo { 
internal();
udp(ip(0.0.0.0) port(514));
unix-stream("/dev/log"); };

The following table lists the source drivers available in syslog-ng.

# 注释 :syslog-ng 可用的 source dirver 类型有如下几种 。注意!括号是必须的,即使不带任何参数

#     -)1、internal():表示来自 syslog-ng 本身的消息

#     -)2、unix-stream():以 SOCK_STREAM 方式在指定的 unix socket 上监听进入的消息

#     -)3、unix-dgram():以 SOCK_DGRAM 方式在指定的 unix socket 上监听进入的消息

#     -)4、file():打开指定文件并读取消息

#     -)5、pipe()、fifo :打开指定的命名管道并读取消息

#     -)6、tcp():表示在指定的  TCP 地址/端口上监听

#     -)7、udp():表示在指定的 UDP 地址/端口上监听

#     -)8、tcp6 和 udp6 :针对 ip V6 的

#     -)9、sun-stream()、sun-streams()

Name Description
internal() Messages generated internally in syslog-ng.
unix-stream() Opens the specified unix socket in SOCK_STREAM mode and listens for incoming messages.
unix-dgram() Opens the specified unix socket in SOCK_DGRAM mode and listens for incoming messages.
file() Opens the specified file and reads messages.
pipe(), fifo Opens the specified named pipe and reads messages.
tcp() Listens on the specified TCP port for incoming messages.
udp() Listens on the specified UDP port for incoming messages.
tcp6() Listens on the specified TCP port for incoming messages over IPv6.
udp6() Listens on the specified UDP port for incoming messages over IPv6.
sun-stream(), sun-streams() Opens the specified STREAMS device on Solaris systems and reads incoming messages.

Table 3.3. Source drivers available in syslog-ng

For a complete description on the above drivers, see .

Define a source only once. The same source can be used in several log paths. Duplicating sources causes syslog-ng to open the source (TCP/IP port, file, etc.) more than once, which might cause problems. For example, include the /dev/log file source only in one source statement, and use this statement in more than one log path if needed.

# 注释 :一个 source 一旦被定义,就可以在多个 log paths 中被引用,如果有重复定义的 source ,可能会导致出现问题,所以不要这么做

阅读(1088) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~