欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

腾讯云 Linux下配置activemq小结

程序员文章站 2024-03-24 09:11:40
...

今天在腾讯云的linux上配置了activemq,遇到了很多问题,现把所有问题和流程记录下来,以便日后使用,文章很多引入其他博客内容,在文末会统一附上坐标。

1.环境

  • jdk:1.8.0_221
  • apache-activemq-5.15.12

2.下载

可以点击下载网址进行下载,我选择的是最新版5.15.12版本。
如果下载较慢,可以选择这个地址

2.1对应版本

由于activemq和java版本有着对应关系,可以查看文末的链接查看更多帮助。

3.解压和安装

下载后放入 /usr/local/activemq 文件夹中腾讯云 Linux下配置activemq小结

进入文件夹
cd /usr/local/activemq
解压文件
tar -zxvf apache-activemq-5.15.12-bin.tar.gz
进入bin目录
cd apache-activemq-5.15.12/bin/
开启
./activemq start
查看状态
./activemq status
关闭
./activemq stop

4.注册为服务和开机启动

创建软连接
ln -s /usr/local/activemq/apache-activemq-5.15.12/bin/activemq /etc/init.d
配置开机启动
chkconfig activemq on

可以使用如下命令操作mq了
service activemq start
service activemq status
service activemq stop

5.添加云服务器对外端口

我是用的是腾讯云服务器,直接进入安全组添加入站规则,加入8161(管理页面) ,61616(java调用) 两个端口,并绑定至目标实例上。
腾讯云 Linux下配置activemq小结
腾讯云 Linux下配置activemq小结

6.启动

运行 service activemq start 开启mq。

6.1 问题1:java_home=""

错误信息:

[aaa@qq.com_0_15_centos ~]# service activemq start                                 INFO: Loading '/usr/local/activemq/apache-activemq-5.15.12//bin/env'
ERROR: Configuration variable JAVA_HOME or JAVACMD is not defined correctly.
       (JAVA_HOME='', JAVACMD='java')

解决方案

#查看服务器jdk是否安装好
java -version

#如何安装好
vim bin/activemq
#在第一行加入
JAVA_HOME="/xxx/xxx/1.8.0_161"  
export JAVA_HOME

6.2 问题2:ActiveMQ not running

解决上述问题后,再次启动,这次没有报错信息,但是扔然未启动成功!
腾讯云 Linux下配置activemq小结

启动日志可以在 /usr/local/activemq/apache-activemq-5.15.12/data/activemq.log 查看
全部报错信息如下

2020-04-24 16:09:26,523 | INFO  | Refreshing org.apache.activemq.xbean.XBeanBrokerFactoryaaa@qq.com: startup date [Fri Apr 24 16:09:26 CST 2020]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2020-04-24 16:09:27,440 | INFO  | Using Persistence Adapter: KahaDBPersistenceAdapter[/usr/local/activemq/apache-activemq-5.15.12/data/kahadb] | org.apache.activemq.broker.BrokerService | main
2020-04-24 16:09:27,538 | INFO  | PListStore:[/usr/local/activemq/apache-activemq-5.15.12/data/localhost/tmp_storage] started | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2020-04-24 16:09:27,720 | INFO  | Apache ActiveMQ 5.15.12 (localhost, ID:VM_0_15_centos-3632-1587715767549-0:1) is starting | org.apache.activemq.broker.BrokerService | main
2020-04-24 16:09:27,742 | INFO  | Listening for connections at: tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2020-04-24 16:09:27,743 | INFO  | Connector openwire started | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,747 | INFO  | Listening for connections at: amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2020-04-24 16:09:27,748 | INFO  | Connector amqp started | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,769 | INFO  | Listening for connections at: stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2020-04-24 16:09:27,773 | INFO  | Connector stomp started | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,778 | INFO  | Listening for connections at: mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2020-04-24 16:09:27,779 | INFO  | Connector mqtt started | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,784 | INFO  | Starting Jetty server | org.apache.activemq.transport.WebTransportServerSupport | main
2020-04-24 16:09:27,859 | INFO  | Creating Jetty connector | org.apache.activemq.transport.WebTransportServerSupport | main
2020-04-24 16:09:27,860 | ERROR | Failed to start Apache ActiveMQ (localhost, ID:VM_0_15_centos-3632-1587715767549-0:1) | org.apache.activemq.broker.BrokerService | main
java.net.URISyntaxException: Illegal character in hostname at index 7: ws://VM_0_15_centos:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600
	at java.net.URI$Parser.fail(URI.java:2848)[:1.8.0_221]
	at java.net.URI$Parser.parseHostname(URI.java:3387)[:1.8.0_221]
	at java.net.URI$Parser.parseServer(URI.java:3236)[:1.8.0_221]
	at java.net.URI$Parser.parseAuthority(URI.java:3155)[:1.8.0_221]
	at java.net.URI$Parser.parseHierarchical(URI.java:3097)[:1.8.0_221]
	at java.net.URI$Parser.parse(URI.java:3053)[:1.8.0_221]
	at java.net.URI.<init>(URI.java:673)[:1.8.0_221]
	at org.apache.activemq.transport.WebTransportServerSupport.bind(WebTransportServerSupport.java:106)[activemq-http-5.15.12.jar:5.15.12]
	at org.apache.activemq.transport.ws.WSTransportServer.doStart(WSTransportServer.java:67)[activemq-http-5.15.12.jar:5.15.12]
	at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55)[activemq-client-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.TransportConnector.start(TransportConnector.java:253)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.BrokerService.startTransportConnector(BrokerService.java:2761)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.BrokerService.startAllConnectors(BrokerService.java:2654)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.BrokerService.doStartBroker(BrokerService.java:777)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.BrokerService.startBroker(BrokerService.java:739)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.BrokerService.start(BrokerService.java:642)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:73)[activemq-spring-5.15.12.jar:5.15.12]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_221]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_221]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_221]
	at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_221]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1748)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1685)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1615)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:757)[spring-beans-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)[spring-context-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)[spring-context-4.3.26.RELEASE.jar:4.3.26.RELEASE]
	at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)[xbean-spring-4.16.jar:4.16]
	at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)[xbean-spring-4.16.jar:4.16]
	at org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:104)[activemq-spring-5.15.12.jar:5.15.12]
	at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)[activemq-spring-5.15.12.jar:5.15.12]
	at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)[activemq-spring-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)[activemq-broker-5.15.12.jar:5.15.12]
	at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)[activemq-console-5.15.12.jar:5.15.12]
	at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:63)[activemq-console-5.15.12.jar:5.15.12]
	at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:154)[activemq-console-5.15.12.jar:5.15.12]
	at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:63)[activemq-console-5.15.12.jar:5.15.12]
	at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)[activemq-console-5.15.12.jar:5.15.12]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_221]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_221]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_221]
	at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_221]
	at org.apache.activemq.console.Main.runTaskClass(Main.java:262)[activemq.jar:5.15.12]
	at org.apache.activemq.console.Main.main(Main.java:115)[activemq.jar:5.15.12]
2020-04-24 16:09:27,864 | INFO  | Apache ActiveMQ 5.15.12 (localhost, ID:VM_0_15_centos-3632-1587715767549-0:1) is shutting down | org.apache.activemq.broker.BrokerService | main
2020-04-24 16:09:27,867 | INFO  | Connector openwire stopped | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,868 | INFO  | Connector amqp stopped | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,870 | INFO  | Connector stomp stopped | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,871 | INFO  | Connector mqtt stopped | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,872 | INFO  | Connector ws stopped | org.apache.activemq.broker.TransportConnector | main
2020-04-24 16:09:27,875 | INFO  | PListStore:[/usr/local/activemq/apache-activemq-5.15.12/data/localhost/tmp_storage] stopped | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2020-04-24 16:09:27,876 | INFO  | Stopping async queue tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2020-04-24 16:09:27,876 | INFO  | Stopping async topic tasks | org.apache.activemq.store.kahadb.KahaDBStore | main
2020-04-24 16:09:27,877 | INFO  | Stopped KahaDB | org.apache.activemq.store.kahadb.KahaDBStore | main
2020-04-24 16:09:27,925 | INFO  | Apache ActiveMQ 5.15.12 (localhost, ID:VM_0_15_centos-3632-1587715767549-0:1) uptime 0.501 seconds | org.apache.activemq.broker.BrokerService | main
2020-04-24 16:09:27,926 | INFO  | Apache ActiveMQ 5.15.12 (localhost, ID:VM_0_15_centos-3632-1587715767549-0:1) is shutdown | org.apache.activemq.broker.BrokerService | main
2020-04-24 16:09:27,926 | INFO  | Closing org.apache.activemq.xbean.XBeanBrokerFactoryaaa@qq.com: startup date [Fri Apr 24 16:09:26 CST 2020]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2020-04-24 16:09:27,930 | WARN  | Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.URISyntaxException: Illegal character in hostname at index 7: ws://VM_0_15_centos:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main

这里竟然显示主机名有非法字符?百度一下,果然是腾讯云的坑。

解决方案

hostnamectl set-hostname 主机名 ; 修改后需重新连接ssh

退出重连,问题解决!
腾讯云 Linux下配置activemq小结
网页成功打开!
腾讯云 Linux下配置activemq小结

参考资源