在官网下载rocketmq的zip包
在rocketmq目录下,将
rocketmq-all-4.3.2-bin-release.zip
变成可以执行的文件hpms@hpms-1:~/xxh009/soft$ chmod -R 777 *
unzip 命令解压缩
hpms@hpms-1:~/xxh009/soft$ unzip rocketmq-all-4.3.2-bin-release.zip
进入rockmq
hpms@hpms-1:~/xxh009/soft$ cd rocketmq-all-4.3.2-bin-release/ hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release$ cd bin/ hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release/bin$ ls cachedog.sh mqadmin.xml mqbroker.numanode2 mqnamesrv.xml play.cmd runserver.cmd tools.sh cleancache.sh mqbroker mqbroker.numanode3 mqshutdown play.sh runserver.sh cleancache.v1.sh mqbroker.cmd mqbroker.xml mqshutdown.cmd README.md setcache.sh mqadmin mqbroker.numanode0 mqnamesrv nohup.out runbroker.cmd startfsrv.sh mqadmin.cmd mqbroker.numanode1 mqnamesrv.cmd os.sh runbroker.sh tools.cmd
运行
运行前修改rocketmq默认配置
1 修改mqbroker.xml
hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release/bin$ vi mqbroker.xml
<options>
<-Xms512m>
</-Xms512m>
<-Xmx1g>
</-Xmx1g>
<-XX:NewSize>256M</-XX:NewSize>
<-XX:MaxNewSize>512M</-XX:MaxNewSize>
<-XX:PermSize>128M</-XX:PermSize>
<-XX:MaxPermSize>128M</-XX:MaxPermSize>
</options>
改为
<options>
<-Xms512m>
</-Xms512m>
<-Xmx1g>
</-Xmx1g>
<-XX:NewSize>256M</-XX:NewSize>
<-XX:MaxNewSize>512M</-XX:MaxNewSize>
<-XX:PermSize>128M</-XX:PermSize>
<-XX:MaxPermSize>128M</-XX:MaxPermSize>
</options>
2 修改 runbroker.sh
hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release/bin$ vim runbroker.sh
将
#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
改为
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn512m"
Start Name Server
rocketmq目录下:
nohup sh bin/mqnamesrv &
mqnamesrv进程默认是在9876端口
hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release$ netstat -anp|grep 9876
tcp6 0 0 :::9876 :::* LISTEN 11491/java
还可以tail -f ~/logs/rocketmqlogs/namesrv.log
查看日志
hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release$ tail -f ~/logs/rocketmqlogs/namesrv.log
2019-07-03 09:38:52 INFO main - tls.client.certPath = null
2019-07-03 09:38:52 INFO main - tls.client.authServer = false
2019-07-03 09:38:52 INFO main - tls.client.trustCertPath = null
2019-07-03 09:38:53 INFO main - Using OpenSSL provider
2019-07-03 09:38:53 INFO main - SSLContext created for server
2019-07-03 09:38:53 INFO NettyEventExecutor - NettyEventExecutor service started
2019-07-03 09:38:53 INFO FileWatchService - FileWatchService service started
2019-07-03 09:38:53 INFO main - The Name Server boot success. serializeType=JSON
2019-07-03 09:39:53 INFO NSScheduledThread1 - --------------------------------------------------------
2019-07-03 09:39:53 INFO NSScheduledThread1 - configTable SIZE: 0
Start Broker
hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release$ nohup sh bin/mqbroker -n localhost:9876 &
查看日志
tail -f ~/logs/rocketmqlogs/broker.log
broker.log :
hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release$ tail -f ~/logs/rocketmqlogs/broker.log
2019-07-03 09:46:08 INFO main - The broker[hpms-1, 202.117.35.221:10911] boot success. serializeType=JSON and name server is localhost:9876
2019-07-03 09:46:18 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2019-07-03 09:46:18 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes
2019-07-03 09:46:18 INFO brokerOutApi_thread_2 - register broker to name server localhost:9876 OK
2019-07-03 09:46:48 INFO brokerOutApi_thread_3 - register broker to name server localhost:9876 OK
2019-07-03 09:47:08 INFO TransactionalMessageCheckService - create new topic TopicConfig [topicName=RMQ_SYS_TRANS_HALF_TOPIC, readQueueNums=1, writeQueueNums=1, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false]
2019-07-03 09:47:08 INFO brokerOutApi_thread_4 - register broker to name server localhost:9876 OK
2019-07-03 09:47:18 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2019-07-03 09:47:18 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes
2019-07-03 09:47:18 INFO brokerOutApi_thread_1 - register broker to name server localhost:9876 OK
2019-07-03 09:47:48 INFO brokerOutApi_thread_2 - register broker to name server localhost:9876 OK
2019-07-03 09:48:18 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2019-07-03 09:48:18 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes
2019-07-03 09:48:18 INFO brokerOutApi_thread_3 - register broker to name server localhost:9876 OK
Send & Receive Messages
Before sending/receiving messages, we need to tell clients the location of name servers. RocketMQ provides multiple ways to achieve this. For simplicity, we use environment variable NAMESRV_ADDR
> export NAMESRV_ADDR=localhost:9876
//投放消息
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
//消费消息
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
Shutdown Servers
> sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK
> sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK
topic创建
使用/bin/mqadmin updateTopic
命令创建topic
hpms@hpms-1:~/xxh009/soft/rocketmq-all-4.3.2-bin-release/bin$ sudo su
root@hpms-1:/home/hpms/xxh009/soft/rocketmq-all-4.3.2-bin-release/bin# ./mqadmin updateTopic -n localhost:9876 -t stock -c DefaultCluster
ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! !!
但是正如命令行显示,出现了错误,在后面坑中有解决方法。
解决完后,我们继续创建topic:
soft/rocketmq-all-4.3.2-bin-release/bin# ./mqadmin updateTopic -n localhost:9876 -t stock -c DefaultCluster
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
create topic to 202.117.35.221:10911 success.
TopicConfig [topicName=stock, readQueueNums=8, writeQueueNums=8, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false]
坑
在ubuntu运行 sudo java,但结果提示 sudo:java:command not found,为什么呢?我的java环境变量也配置了
在Ubuntu环境中安装好Java环境后设置环境变量:在/etc/profile中设置好了JAVA_HOME变量并引入到PATH中,
vim /etc/profile
:
export JAVA_HOME=/usr/local/jdk1.8.0_111
export CLASSPATH=.:$JAVA_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH
sudo是切换用户存取权限,但是没有获得环境变量,所以PATH没有被带入
注:
/etc/environmen
t是设置整个系统的环境,而/etc/profile
是设置所有用户的环境,前者与登陆用户无关,后者与登陆用户有关。系统应用程序的执行与用户环境可以是无关的,但与系统环境时相关的,所以当你登陆时,你看到的提示信息,如日期、时间信息的显示格式与系统环境的LANG是相关的,缺省LANG=en_US,如果系统环境LANG-zh_CN,则提示信息是中文的,否则是英文的。
解决方法:
设置整个系统的环境变量
sudo vim /etc/environment
//修改为
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export JAVA_HOME=/usr/local/jdk1.8.0_111
我的jdk是在/usr/local/jdk1.8.0_111
目录下
使环境变量立刻生效
source /etc/environment
解决