1.下载安装包(先安装maven,再安装mq)
maven安装:https://www.cnblogs.com/cannel/p/11104190.html
maven安装步骤:
(1)下载:官网-https://maven.apache.org/ 下载地址: https://maven.apache.org/download.cgi
(2)解压:tar -zxvf apache-maven-3.6.3-bin.tar.gz
(3)配置:vim settings.xml
需要配置repo路径 (可以参照windows下的repo路径)和 mirros(使用的是aliyun的地址)
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
(4)验证:
[root@localhost ~]# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/rocketmq/apache-maven-3.6.3
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /opt/java/jdk1.8.0_191/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"
[root@localhost bin]#
RocketMQ安装步骤:
(1)下载:参照官网 http://rocketmq.apache.org/docs/quick-start/
(2)解压:
unzip rocketmq-all-4.7.0-source-release.zip
(3)安装:需要maven 构建源码包
cd rocketmq-all-4.7.0-source-release/
mvn -Prelease-all -DskipTests clean install -U
cd distribution/target/rocketmq-4.7.0/rocketmq-4.7.0
Start Name Server
> nohup sh bin/mqnamesrv &
> tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
本地:
[root@localhost rocketmq-4.7.0]# nohup sh bin/mqnamesrv &
[3] 19730
[1] Exit 143 nohup sh mqnamesrv (wd: /home/rocketmq/rocketmq-all-4.7.0-source-release/distribution/target/rocketmq-4.7.0/rocketmq-4.7.0/bin)
(wd now: /home/rocketmq/rocketmq-all-4.7.0-source-release/distribution/target/rocketmq-4.7.0/rocketmq-4.7.0)
[2] Exit 143 nohup sh bin/mqbroker -n localhost:9876 autoCreateTopicEnable=true
[root@localhost rocketmq-4.7.0]# nohup: ignoring input and appending output to ‘nohup.out’
[root@localhost rocketmq-4.7.0]# tail -f ~/logs/rocketmqlogs/namesrv.log
2020-03-27 21:07:58 INFO main - tls.client.keyPassword = null
2020-03-27 21:07:58 INFO main - tls.client.certPath = null
2020-03-27 21:07:58 INFO main - tls.client.authServer = false
2020-03-27 21:07:58 INFO main - tls.client.trustCertPath = null
2020-03-27 21:08:00 INFO main - Using OpenSSL provider
2020-03-27 21:08:01 INFO main - SSLContext created for server
2020-03-27 21:08:01 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2020-03-27 21:08:01 INFO NettyEventExecutor - NettyEventExecutor service started
2020-03-27 21:08:02 INFO main - The Name Server boot success. serializeType=JSON
2020-03-27 21:08:02 INFO FileWatchService - FileWatchService service started
Start Broker (加上autoCreateTopicEnable=true & 然并卵)
> nohup sh bin/mqbroker -n localhost:9876 autoCreateTopicEnable=true &
> tail -f ~/logs/rocketmqlogs/broker.log
The broker[%s, 172.30.30.233:10911] boot success...
本地:
[root@localhost rocketmq-4.7.0]# nohup sh bin/mqbroker -n localhost:9876 autoCreateTopicEnable=true &
[4] 28584
[root@localhost rocketmq-4.7.0]# nohup: ignoring input and appending output to ‘nohup.out’
[root@localhost rocketmq-4.7.0]# tail -f ~/logs/rocketmqlogs/broker.log
2020-03-27 21:09:22 INFO main - Try to start service thread:FlushConsumeQueueService started:false lastThread:null
2020-03-27 21:09:22 INFO main - Try to start service thread:FlushRealTimeService started:false lastThread:null
2020-03-27 21:09:22 INFO main - Try to start service thread:StoreStatsService started:false lastThread:null
2020-03-27 21:09:22 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2020-03-27 21:09:22 INFO FileWatchService - FileWatchService service started
2020-03-27 21:09:22 INFO main - Try to start service thread:PullRequestHoldService started:false lastThread:null
2020-03-27 21:09:22 INFO PullRequestHoldService - PullRequestHoldService service started
2020-03-27 21:09:22 INFO main - Try to start service thread:TransactionalMessageCheckService started:false lastThread:null
2020-03-27 21:09:22 INFO brokerOutApi_thread_1 - register broker[0]to name server localhost:9876 OK
2020-03-27 21:09:22 INFO main - The broker[localhost.localdomain, 192.168.52.106:10911] boot success. serializeType=JSON and name server is localhost:9876
Shutdown Servers
[root@localhost rocketmq-4.7.0]# sh bin/mqshutdown broker
The mqbroker(17286) is running...
Send shutdown request to mqbroker(17286) OK
[root@localhost rocketmq-4.7.0]# sh bin/mqshutdown namesrv
The mqnamesrv(9111) is running...
Send shutdown request to mqnamesrv(9111) OK
[root@localhost rocketmq-4.7.0]#
功能测试:
1.生产消息【】
> export NAMESRV_ADDR=localhost:9876
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
2.消费消息【】
> export NAMESRV_ADDR=localhost:9876
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
操作:
创建topic:
[root@localhost bin]# sh mqadmin clusterList -n localhost:9876
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
#Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
DefaultCluster localhost.localdomain 0 192.168.52.106:10911 V4_7_0 0.00(0,0ms) 0.00(0,0ms) 0 440385.15 0.0306
[root@localhost bin]# sh mqadmin updateTopic -n localhost:9876 -t TopicTest-1
usage: mqadmin updateTopic -b <arg> | -c <arg> [-h] [-n <arg>] [-o <arg>] [-p <arg>] [-r <arg>] [-s <arg>] -t
<arg> [-u <arg>] [-w <arg>]
-b,--brokerAddr <arg> create topic to which broker
-c,--clusterName <arg> create topic to which cluster
-h,--help Print help
-n,--namesrvAddr <arg> Name server address list, eg: 192.168.0.1:9876;192.168.0.2:9876
-o,--order <arg> set topic's order(true|false)
-p,--perm <arg> set topic's permission(2|4|6), intro[2:W 4:R; 6:RW]
-r,--readQueueNums <arg> set read queue nums
-s,--hasUnitSub <arg> has unit sub (true|false)
-t,--topic <arg> topic name
-u,--unit <arg> is unit topic (true|false)
-w,--writeQueueNums <arg> set write queue nums
[root@localhost bin]# sh mqadmin updateTopic -n localhost:9876 -t TopicTest_001
usage: mqadmin updateTopic -b <arg> | -c <arg> [-h] [-n <arg>] [-o <arg>] [-p <arg>] [-r <arg>] [-s <arg>] -t
<arg> [-u <arg>] [-w <arg>]
-b,--brokerAddr <arg> create topic to which broker
-c,--clusterName <arg> create topic to which cluster
-h,--help Print help
-n,--namesrvAddr <arg> Name server address list, eg: 192.168.0.1:9876;192.168.0.2:9876
-o,--order <arg> set topic's order(true|false)
-p,--perm <arg> set topic's permission(2|4|6), intro[2:W 4:R; 6:RW]
-r,--readQueueNums <arg> set read queue nums
-s,--hasUnitSub <arg> has unit sub (true|false)
-t,--topic <arg> topic name
-u,--unit <arg> is unit topic (true|false)
-w,--writeQueueNums <arg> set write queue nums
[root@localhost bin]# sh mqadmin updateTopic -n localhost:9876 -b 192.168.52.106:10911 -t TopicTest_001
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
RocketMQLog:WARN Please initialize the logger system properly.
create topic to 192.168.52.106:10911 success.
TopicConfig [topicName=TopicTest_001, readQueueNums=8, writeQueueNums=8, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false][root@localhost bin]#
[root@localhost bin]#