基于 CentOS 7,ActiveMQ 5.9.1

问题重现

在 CentOS 7 下安装好ActiveMQ后,执行 /usr/local/apache-activemq-5.9.1/bin/activemq start 启动 ActiveMQ,显示:

INFO: Using default configuration
(you can configure options in one of these file: /etc/default/activemq /home/xueliang/.activemqrc)

INFO: Invoke the following command to create a configuration file
/usr/local/apache-activemq-5.9.1/bin/activemq setup [ /etc/default/activemq | /home/xueliang/.activemqrc ]

INFO: Using java ‘/usr/local/java/jdk1.8.0_101/bin/java’
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : ‘/usr/local/apache-activemq-5.9.1/data/activemq-server2.pid’ (pid ‘24484’)

从提示信息看,似乎启动成功,但根据提示信息中的 pid 查找进程时,却发现并无此进程:

ps -eLf | grep 24484

结果:

[xueliang@server2 ~]$ ps -eLf | grep 24484
xueliang 24520 23462 24520 0 1 00:52 pts/2 00:00:00 grep –color=auto 24484
[xueliang@server2 ~]$

问题原因

一个好的软件,总能在错误发生时告诉你如何解决。
执行 cat /usr/local/apache-activemq-5.9.1/data/activemq.log 看一下日志信息:

2016-10-12 02:04:09,053 | INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:04:09 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2016-10-12 02:04:10,498 | INFO | PListStore:[/usr/local/apache-activemq-5.9.1/data/localhost/tmp_storage] started | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2016-10-12 02:04:10,512 | INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[/usr/local/apache-activemq-5.9.1/data/kahadb] | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:10,683 | INFO | KahaDB is version 5 | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:04:10,746 | INFO | Recovering from the journal … | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:04:10,757 | INFO | Recovery replayed 332 operations from the journal in 0.071 seconds. | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:04:10,955 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-35685-1476209050769-0:1) is starting | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:10,969 | ERROR | Failed to start Apache ActiveMQ ([localhost, ID:server2-35685-1476209050769-0:1], java.io.IOException: Transport Connector could not be registered in JMX: Failed to bind to server socket: tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 due to: java.net.BindException: Address already in use) | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:10,970 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-35685-1476209050769-0:1) is shutting down | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:10,970 | INFO | Connector openwire stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:10,970 | INFO | Connector amqp stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:10,970 | INFO | Connector stomp stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:10,970 | INFO | Connector mqtt stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:10,970 | INFO | Connector ws stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:10,973 | INFO | PListStore:[/usr/local/apache-activemq-5.9.1/data/localhost/tmp_storage] stopped | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2016-10-12 02:04:10,973 | INFO | Stopping async queue tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:04:10,973 | INFO | Stopping async topic tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:04:10,974 | INFO | Stopped KahaDB | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:04:11,193 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-35685-1476209050769-0:1) uptime 0.691 seconds | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:11,193 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-35685-1476209050769-0:1) is shutdown | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:11,193 | INFO | Closing org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:04:09 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2016-10-12 02:04:11,194 | WARN | Exception thrown from LifecycleProcessor on context close | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
java.lang.IllegalStateException: LifecycleProcessor not initialized - call ‘refresh’ before invoking lifecycle methods via the context: org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:04:09 CST 2016]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
at org.apache.activemq.hooks.SpringContextHook.run(SpringContextHook.java:30)
at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:809)
at org.apache.activemq.xbean.XBeanBrokerService.stop(XBeanBrokerService.java:122)
at org.apache.activemq.broker.BrokerService.start(BrokerService.java:601)
at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1638)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:64)
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:52)
at org.apache.activemq.xbean.XBeanBrokerFactory$1.(XBeanBrokerFactory.java:104)
at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)
at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:150)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)
at org.apache.activemq.console.Main.main(Main.java:115)
2016-10-12 02:04:30,534 | INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:04:30 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2016-10-12 02:04:31,297 | INFO | PListStore:[/usr/local/apache-activemq-5.9.1/data/localhost/tmp_storage] started | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2016-10-12 02:04:31,311 | INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[/usr/local/apache-activemq-5.9.1/data/kahadb] | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:31,472 | INFO | KahaDB is version 5 | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:04:31,530 | INFO | Recovering from the journal … | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:04:31,543 | INFO | Recovery replayed 334 operations from the journal in 0.068 seconds. | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:04:31,680 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-52293-1476209071560-0:1) is starting | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:31,695 | ERROR | Failed to start Apache ActiveMQ ([localhost, ID:server2-52293-1476209071560-0:1], java.io.IOException: Transport Connector could not be registered in JMX: Failed to bind to server socket: tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 due to: java.net.BindException: Address already in use) | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:31,695 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-52293-1476209071560-0:1) is shutting down | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:31,696 | INFO | Connector openwire stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:31,696 | INFO | Connector amqp stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:31,696 | INFO | Connector stomp stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:31,696 | INFO | Connector mqtt stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:31,696 | INFO | Connector ws stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:04:31,699 | INFO | PListStore:[/usr/local/apache-activemq-5.9.1/data/localhost/tmp_storage] stopped | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2016-10-12 02:04:31,699 | INFO | Stopping async queue tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:04:31,699 | INFO | Stopping async topic tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:04:31,700 | INFO | Stopped KahaDB | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:04:31,984 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-52293-1476209071560-0:1) uptime 0.682 seconds | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:31,984 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-52293-1476209071560-0:1) is shutdown | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:04:31,984 | INFO | Closing org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:04:30 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2016-10-12 02:04:31,985 | WARN | Exception thrown from LifecycleProcessor on context close | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
java.lang.IllegalStateException: LifecycleProcessor not initialized - call ‘refresh’ before invoking lifecycle methods via the context: org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:04:30 CST 2016]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
at org.apache.activemq.hooks.SpringContextHook.run(SpringContextHook.java:30)
at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:809)
at org.apache.activemq.xbean.XBeanBrokerService.stop(XBeanBrokerService.java:122)
at org.apache.activemq.broker.BrokerService.start(BrokerService.java:601)
at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1638)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:64)
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:52)
at org.apache.activemq.xbean.XBeanBrokerFactory$1.(XBeanBrokerFactory.java:104)
at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)
at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:150)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)
at org.apache.activemq.console.Main.main(Main.java:115)
2016-10-12 02:07:32,656 | INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:07:32 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2016-10-12 02:07:33,326 | INFO | PListStore:[/usr/local/apache-activemq-5.9.1/data/localhost/tmp_storage] started | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2016-10-12 02:07:33,343 | INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[/usr/local/apache-activemq-5.9.1/data/kahadb] | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:07:33,528 | INFO | KahaDB is version 5 | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:07:33,587 | INFO | Recovering from the journal … | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:07:33,602 | INFO | Recovery replayed 336 operations from the journal in 0.071 seconds. | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 02:07:33,740 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-53098-1476209253622-0:1) is starting | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:07:33,749 | ERROR | Failed to start Apache ActiveMQ ([localhost, ID:server2-53098-1476209253622-0:1], java.io.IOException: Transport Connector could not be registered in JMX: Failed to bind to server socket: tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 due to: java.net.BindException: Address already in use) | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:07:33,750 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-53098-1476209253622-0:1) is shutting down | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:07:33,750 | INFO | Connector openwire stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:07:33,750 | INFO | Connector amqp stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:07:33,750 | INFO | Connector stomp stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:07:33,750 | INFO | Connector mqtt stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:07:33,750 | INFO | Connector ws stopped | org.apache.activemq.broker.TransportConnector | main
2016-10-12 02:07:33,752 | INFO | PListStore:[/usr/local/apache-activemq-5.9.1/data/localhost/tmp_storage] stopped | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2016-10-12 02:07:33,753 | INFO | Stopping async queue tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:07:33,753 | INFO | Stopping async topic tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:07:33,753 | INFO | Stopped KahaDB | org.apache.activemq.store.kahadb.KahaDBStore | main
2016-10-12 02:07:34,039 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-53098-1476209253622-0:1) uptime 0.710 seconds | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:07:34,039 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-53098-1476209253622-0:1) is shutdown | org.apache.activemq.broker.BrokerService | main
2016-10-12 02:07:34,040 | INFO | Closing org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:07:32 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2016-10-12 02:07:34,041 | WARN | Exception thrown from LifecycleProcessor on context close | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
java.lang.IllegalStateException: LifecycleProcessor not initialized - call ‘refresh’ before invoking lifecycle methods via the context: org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 02:07:32 CST 2016]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
at org.apache.activemq.hooks.SpringContextHook.run(SpringContextHook.java:30)
at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:809)
at org.apache.activemq.xbean.XBeanBrokerService.stop(XBeanBrokerService.java:122)
at org.apache.activemq.broker.BrokerService.start(BrokerService.java:601)
at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1638)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:64)
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:52)
at org.apache.activemq.xbean.XBeanBrokerFactory$1.(XBeanBrokerFactory.java:104)
at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)
at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:150)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)
at org.apache.activemq.console.Main.main(Main.java:115)

刚开始把精力留在了最后一个 WARN 处,即:

2016-10-12 01:08:54,001 | WARN | Exception thrown from LifecycleProcessor on context close | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
java.lang.IllegalStateException: LifecycleProcessor not initialized - call ‘refresh’ before invoking lifecycle methods via the context: org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 01:08:52 CST 2016]; root of context hierarchy

Google 了很久,问题并没有解决,其实问题在上面第一个 ERROR 处,即:

2016-10-12 01:08:53,602 | ERROR | Failed to start Apache ActiveMQ ([localhost, ID:server2-43498-1476205733474-0:1], java.io.IOException: Transport Connector could not be registered in JMX: Failed to bind to server socket: tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 due to: java.net.BindException: Address already in use) | org.apache.activemq.broker.BrokerService | main

从提示信息中的 due to: java.net.BindException: Address already in use 可以看到是端口 61616 被占用了。

解决方案

既然问题找到了,也就知道怎么解决。
使用 netstat -anp | grep 61616 查看是哪个程序占用了 61616 端口:

[xueliang@server2 ~]$ netstat -anp | grep 61616
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::61616 :::* LISTEN 10738/java
[xueliang@server2 ~]$

可以看出 PID10738,可以确定的是该进程可以直接执行以下命令终止掉:

kill 10738

再次执行 netstat -anp | grep 61616 可以看到刚才占用端口程序已经终止运行了。
再次启动 ActiveMQ,并查看日志信息:

[xueliang@server2 ~]$ cat /usr/local/apache-activemq-5.9.1/data/activemq.log
2016-10-12 01:35:56,610 | INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@13c78c0b: startup date [Wed Oct 12 01:35:56 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2016-10-12 01:35:57,423 | INFO | PListStore:[/usr/local/apache-activemq-5.9.1/data/localhost/tmp_storage] started | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2016-10-12 01:35:57,436 | INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[/usr/local/apache-activemq-5.9.1/data/kahadb] | org.apache.activemq.broker.BrokerService | main
2016-10-12 01:35:57,593 | INFO | KahaDB is version 5 | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 01:35:57,716 | INFO | Recovering from the journal … | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 01:35:57,717 | INFO | Recovery replayed 1 operations from the journal in 0.121 seconds. | org.apache.activemq.store.kahadb.MessageDatabase | main
2016-10-12 01:35:57,844 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-47815-1476207357729-0:1) is starting | org.apache.activemq.broker.BrokerService | main
2016-10-12 01:35:57,855 | INFO | Listening for connections at: tcp://server2:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2016-10-12 01:35:57,855 | INFO | Connector openwire started | org.apache.activemq.broker.TransportConnector | main
2016-10-12 01:35:57,857 | INFO | Listening for connections at: amqp://server2:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2016-10-12 01:35:57,857 | INFO | Connector amqp started | org.apache.activemq.broker.TransportConnector | main
2016-10-12 01:35:57,859 | INFO | Listening for connections at: stomp://server2:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2016-10-12 01:35:57,862 | INFO | Connector stomp started | org.apache.activemq.broker.TransportConnector | main
2016-10-12 01:35:57,864 | INFO | Listening for connections at: mqtt://server2:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2016-10-12 01:35:57,864 | INFO | Connector mqtt started | org.apache.activemq.broker.TransportConnector | main
2016-10-12 01:35:58,018 | INFO | Listening for connections at ws://server2:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.ws.WSTransportServer | main
2016-10-12 01:35:58,019 | INFO | Connector ws started | org.apache.activemq.broker.TransportConnector | main
2016-10-12 01:35:58,048 | INFO | Apache ActiveMQ 5.9.1 (localhost, ID:server2-47815-1476207357729-0:1) started | org.apache.activemq.broker.BrokerService | main
2016-10-12 01:35:58,048 | INFO | For help or more information please see: http://activemq.apache.org | org.apache.activemq.broker.BrokerService | main
2016-10-12 01:35:58,536 | INFO | ActiveMQ WebConsole available at http://localhost:8161/ | org.apache.activemq.web.WebConsoleStarter | main
2016-10-12 01:35:58,741 | INFO | Initializing Spring FrameworkServlet ‘dispatcher’ | /admin | main
2016-10-12 01:36:01,077 | INFO | jolokia-agent: No access restrictor found at classpath:/jolokia-access.xml, access to all MBeans is allowed | /api | main
[xueliang@server2 ~]$

可以看到已经没有了错误信息,ActiveMQ 正常启动。

其他可能导致启动失败的原因

在查找问题原因的过程中,发现一些其他可能导致 ActiveMQ 启动失败的原因:
1. 主机名包含下划线,相关链接:http://stackoverflow.com/a/21255931/5122380
2. 将 conf/activemq.xml 文件中 transportConnectors/transportConnector uri 属性中的 0.0.0.0 替换成你主机的域名,或者 127.0.0.1 ,形如:

<transportConnectors>
<!– DOS protection, limit concurrent connections to 1000 and frame size to 100MB –>
<transportConnector name=”openwire” uri=”tcp://127.0.0.1:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600”/>
</transportConnectors>

相关链接:http://stackoverflow.com/a/25039610/5122380

About Me
WEB开发工程师
GitHub Repos