[ActiveMQ]java.net.UnknownHostException: localhost

來源:互聯網
上載者:User

問題描述:

今天在配置ActiveMQ的時候,修改了ActiveMQ的設定檔:<broker brokerName="localhost" useJmx="false" xmlns= "http://activemq.org/config/1.0" >

啟動的時候報錯:

Loading message broker from: xbean:activemq.xmlINFO  BrokerService                  - ActiveMQ 4.1.1 JMS Message Broker (localhost) is startingINFO  BrokerService                  - For help or more information please see: http://incubator.apache.org/activemq/INFO  JDBCPersistenceAdapter         - Database driver recognized: [apache_derby_embedded_jdbc_driver]INFO  DefaultDatabaseLocker          - Attempting to acquire the exclusive lock to become the Master brokerINFO  DefaultDatabaseLocker          - Becoming the master on dataSource: org.apache.derby.jdbc.EmbeddedDataSource@31ca9394INFO  JournalPersistenceAdapter      - Journal Recovery Started from: Active Journal: using 5 x 20.0 Megs at: /home/dhcp2/lcdmp2_web/apache-activemq-4.1.1/activemq-data/journalINFO  JournalPersistenceAdapter      - Journal Recovered: 0 message(s) in transactions recovered.ERROR BrokerService                  - Failed to start ActiveMQ JMS Message Broker. Reason: java.net.UnknownHostException: localhostjava.net.UnknownHostException: localhost   at java.net.ResolverCache.getHostByName(libgcj.so.7rh)   at java.net.InetAddress.getAllByName(libgcj.so.7rh)   at java.net.InetAddress.getByName(libgcj.so.7rh)   at org.apache.activemq.transport.tcp.TcpTransportServer.bind(TcpTransportServer.java:76)   at org.apache.activemq.transport.tcp.TcpTransportFactory.doBind(TcpTransportFactory.java:56)   at org.apache.activemq.transport.TransportFactory.bind(TransportFactory.java:109)   at org.apache.activemq.broker.TransportConnector.createTransportServer(TransportConnector.java:270)   at org.apache.activemq.broker.TransportConnector.getServer(TransportConnector.java:122)   at org.apache.activemq.broker.TransportConnector.start(TransportConnector.java:220)   at org.apache.activemq.broker.BrokerService.startTransportConnector(BrokerService.java:1519)   at org.apache.activemq.broker.BrokerService.startAllConnectors(BrokerService.java:1471)   at org.apache.activemq.broker.BrokerService.start(BrokerService.java:402)   at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:47)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)   at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:161)   at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:51)   at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:41)   at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:57)   at org.apache.activemq.console.command.StartCommand.startBroker(StartCommand.java:82)   at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:47)   at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:50)   at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:82)   at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:50)   at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:46)   at java.lang.reflect.Method.invoke(libgcj.so.7rh)   at org.apache.activemq.console.Main.runTaskClass(Main.java:202)   at org.apache.activemq.console.Main.main(Main.java:91)ERROR: java.lang.RuntimeException: Failed to execute start task. Reason: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.UnknownHostException: localhostjava.lang.RuntimeException: Failed to execute start task. Reason: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.UnknownHostException: localhost   at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:70)   at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:50)   at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:82)   at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:50)   at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:46)   at java.lang.reflect.Method.invoke(libgcj.so.7rh)   at org.apache.activemq.console.Main.runTaskClass(Main.java:202)   at org.apache.activemq.console.Main.main(Main.java:91)Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.UnknownHostException: localhost   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1032)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)   at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:161)   at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:51)   at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:41)   at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:57)   at org.apache.activemq.console.command.StartCommand.startBroker(StartCommand.java:82)   at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:47)   ...7 moreCaused by: java.net.UnknownHostException: localhost   at java.net.ResolverCache.getHostByName(libgcj.so.7rh)   at java.net.InetAddress.getAllByName(libgcj.so.7rh)   at java.net.InetAddress.getByName(libgcj.so.7rh)   at org.apache.activemq.transport.tcp.TcpTransportServer.bind(TcpTransportServer.java:76)   at org.apache.activemq.transport.tcp.TcpTransportFactory.doBind(TcpTransportFactory.java:56)   at org.apache.activemq.transport.TransportFactory.bind(TransportFactory.java:109)   at org.apache.activemq.broker.TransportConnector.createTransportServer(TransportConnector.java:270)   at org.apache.activemq.broker.TransportConnector.getServer(TransportConnector.java:122)   at org.apache.activemq.broker.TransportConnector.start(TransportConnector.java:220)   at org.apache.activemq.broker.BrokerService.startTransportConnector(BrokerService.java:1519)   at org.apache.activemq.broker.BrokerService.startAllConnectors(BrokerService.java:1471)   at org.apache.activemq.broker.BrokerService.start(BrokerService.java:402)   at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:47)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)   ...20 moreERROR: java.lang.Exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.UnknownHostException: localhostjava.lang.Exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.UnknownHostException: localhost   at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:71)   at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:50)   at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:82)   at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:50)   at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:46)   at java.lang.reflect.Method.invoke(libgcj.so.7rh)   at org.apache.activemq.console.Main.runTaskClass(Main.java:202)   at org.apache.activemq.console.Main.main(Main.java:91)Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.UnknownHostException: localhost   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1032)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)   at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:161)   at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:51)   at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:41)   at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:57)   at org.apache.activemq.console.command.StartCommand.startBroker(StartCommand.java:82)   at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:47)   ...7 moreCaused by: java.net.UnknownHostException: localhost   at java.net.ResolverCache.getHostByName(libgcj.so.7rh)   at java.net.InetAddress.getAllByName(libgcj.so.7rh)   at java.net.InetAddress.getByName(libgcj.so.7rh)   at org.apache.activemq.transport.tcp.TcpTransportServer.bind(TcpTransportServer.java:76)   at org.apache.activemq.transport.tcp.TcpTransportFactory.doBind(TcpTransportFactory.java:56)   at org.apache.activemq.transport.TransportFactory.bind(TransportFactory.java:109)   at org.apache.activemq.broker.TransportConnector.createTransportServer(TransportConnector.java:270)   at org.apache.activemq.broker.TransportConnector.getServer(TransportConnector.java:122)   at org.apache.activemq.broker.TransportConnector.start(TransportConnector.java:220)   at org.apache.activemq.broker.BrokerService.startTransportConnector(BrokerService.java:1519)   at org.apache.activemq.broker.BrokerService.startAllConnectors(BrokerService.java:1471)   at org.apache.activemq.broker.BrokerService.start(BrokerService.java:402)   at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:47)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)   ...20 moreINFO  BrokerService                  - ActiveMQ Message Broker (localhost, null) is shutting downINFO  NetworkConnector               - Network Connector default-nc StoppedINFO  TransportConnector             - Connector openwire StoppedINFO  BrokerService                  - ActiveMQ JMS Message Broker (localhost, null) stopped


問題分析:

根據日誌java.net.UnknownHostException: localhost判斷,應該是由於伺服器無法正確解析localhost造成的

[123@test conf]$ ping localhostping: unknown host localhost[123@test conf]$ ping 127.0.0.1PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.020 ms64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.026 ms64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.023 ms

根據日誌Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]判斷,應該是activemq.xml檔案中的BrokerService配置出錯

解決方式:

一:不使用localhost而使用127.0.0.1代替

二:修改主機映射

[root@test test]# vi /etc/hosts

在開啟的檔案中增加下面一行(保證新增的這條為以127.0.0.1開頭的第一個):

127.0.0.1               localhost.localdomain localhost

出現如下測試結果說明配置成功:

[root@test test]# ping localhostPING localhost.localdomain (127.0.0.1) 56(84) bytes of data.64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=64 time=0.019 ms64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=2 ttl=64 time=0.020 ms64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=3 ttl=64 time=0.024 ms64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=4 ttl=64 time=0.020 ms64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=5 ttl=64 time=0.018 ms--- localhost.localdomain ping statistics ---5 packets transmitted, 5 received, 0% packet loss, time 4009msrtt min/avg/max/mdev = 0.018/0.020/0.024/0.003 ms

此時可以在設定檔中使用localhost,伺服器會將localhost解析為127.0.0.1

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.