环境
我有两台 Ubuntu 14.04 服务器,在 Windows 7 机器上的 Oracle 虚拟机中运行,它们可以通过 ping 看到彼此:
- 服务器 ONE 有一个 SysLog-Ng 组件 (IP:192.168.1. 1 ) 监听 Postgresql 数据库
- 服务器2有 Apache Flume (IP:192.168.1.2 )
服务器一有这个 syslog-ng.conf 文件(部分):
# POSTGRESQL_LOGGER
destination logpgsql { file("/var/log/pgsql"); };
destination loghost {tcp("192.168.1.2" port(41414));}; # IP of Server TWO. Is it Correct?
filter f_postgres { facility(local0); };
filter f_sql_insert {match(".*INSERT INTO prova.*;");};
log { source(s_src);
filter(f_postgres);
filter(f_sql_insert);
destination(loghost);
destination(logpgsql);};
(服务器 ONE 正确接收来自 s_src 的消息,正确地将它们保存在 pgsql 日志文件中)
服务器 2 有这个 flume-syslog.conf 文件:
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# TCP based Syslog source
a1.sources.r1.type = syslogtcp
a1.sources.r1.port = 41414
a1.sources.r1.host = 192.168.1.1 # IP of Server ONE. Is it Correct?
# Describe the sink
a1.sinks.k1.type = logger
# Channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Source and sinks to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
当我启动 Flume 应用程序时:
flume-ng agent --conf conf --conf-file conf/flume-syslog.conf --name a1 -Dflume.root.logger=INFO,console
我得到这个例外:
2015-04-25 11:58:39,236 (lifecycleSupervisor-1-1) [INFO - org.apache.flume.source.SyslogTcpSource.start(SyslogTcpSource.java:118)] Syslog TCP Source starting...
2015-04-25 11:58:39,237 (lifecycleSupervisor-1-1) [ERROR - org.apache.flume.lifecycle.LifecycleSupervisor$MonitorRunnable.run(LifecycleSupervisor.java:253)] Unable to start EventDrivenSourceRunner: { source:org.apache.flume.source.SyslogTcp
Source{name:r1,state:IDLE} } - Exception follows.
org.jboss.netty.channel.ChannelException: Failed to bind to: /192.168.1.1:41414
at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:297)
at org.apache.flume.source.SyslogTcpSource.start(SyslogTcpSource.java:123)
at org.apache.flume.source.EventDrivenSourceRunner.start(EventDrivenSourceRunner.java:44)
at org.apache.flume.lifecycle.LifecycleSupervisor$MonitorRunnable.run(LifecycleSupervisor.java:251)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293
)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.BindException: Cannot assign requested address
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.bind(NioServerSocketPipelineSink.java:140)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleServerSocket(NioServerSocketPipelineSink.java:90)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:64)
at org.jboss.netty.channel.Channels.bind(Channels.java:569)
at org.jboss.netty.channel.AbstractChannel.bind(AbstractChannel.java:189)
at org.jboss.netty.bootstrap.ServerBootstrap$Binder.channelOpen(ServerBootstrap.java:342)
at org.jboss.netty.channel.Channels.fireChannelOpen(Channels.java:170)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannel.<init>(NioServerSocketChannel.java:80)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:158)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:86)
at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:276)
... 10 more
它是什么原因?谢谢你的期待。