jdk安装 传送门
1、下载apache最新rocketmq二进制压缩文件
1 2 3 |
下载地址:https://archive.apache.org/dist/rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip wget https://archive.apache.org/dist/rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip |
2、解压安装
1 2 3 4 |
#新建一个新的程序文件夹用来放rocketmq mkdir -p /usr/local/rocketmq 解压: unzip rocketmq-all-4.2.0-bin-release.zip -d /usr/local/rocketmq |
3.启动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 进入目录 cd /usr/local/rocketmq/ 创建日志目录: mkdir -p /usr/local/rocketmq/logs/rocketmqlogs # 1.先启动mqnamesrv #启动命令 nohup sh bin/mqnamesrv & # 最好加上输出日志 nohup sh /usr/local/rocketmq/bin/mqnamesrv > /usr/local/rocketmq/logs/rocketmqlogs/namesrv.log & # 停止命令 nohup sh bin/mqshutdown namesrv # 2.启动broker #startBroker.sh #注意,下面的ip地址以及端口请填写你安装的rocketmq机器的ip地址及端口。 nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/broker.conf -n 192.168.0.66:9876 > /usr/local/rocketmq/logs/rocketmqlogs/broker.log & # 查看日志 tail -f /usr/local/rocketmq/logs/rocketmqlogs/broker.log #stopBroker.sh nohup sh bin/mqshutdown broker |
4. broker启动错误
1 |
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12) |
原因是:
1 2 3 4 5 6 7 8 9 10 |
bin/runserver.sh runbroker.sh服务启动脚中对于内存的限制(默认是4G,本人当前机器才2G内存,所以要改小) cd /usr/local/rocketmq/bin/ vim runserver.sh 修改: JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m" 修改为: JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx128m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m" |
1 2 3 4 5 |
vim runbroker.sh 修改: JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g" 修改为: JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx128m -Xmn128m" |
5.重启服务
1 2 3 4 5 6 7 |
pkill -9 [xxxx] 1.启动mqnamesrv nohup sh /usr/local/rocketmq/bin/mqnamesrv > /usr/local/rocketmq/logs/rocketmqlogs/namesrv.log & 2.启动mabroker nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/broker.conf -n 192.168.0.66:9876 > /usr/local/rocketmq/logs/rocketmqlogs/broker.log & |
6. 收发消息
1 2 3 4 5 |
export NAMESRV_ADDR=192.168.0.66:9876 sh /usr/local/rocketmq/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer sh /usr/local/rocketmq/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer |
二、RocketMQ控制台
拉取源码:
1 |
cd /opt && git clone https://github.com/apache/rocketmq-externals.git |
修改配置:
1 2 |
cd rocketmq-externals/rocketmq-console/src/main/resources vim application.properties |
配置文件内容:
1 2 3 4 |
将项目使用的 rocketmq.config.namesrvAddr=[192.168.0.66:9876] #改成对应的namesrvAddr 地址 设置: rocketmq.config.isVIPChannel=false |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
server.contextPath= server.port=8080 ### SSL setting #server.ssl.key-store=classpath:rmqcngkeystore.jks #server.ssl.key-store-password=rocketmq #server.ssl.keyStoreType=PKCS12 #server.ssl.keyAlias=rmqcngkey #spring.application.index=true spring.application.name=rocketmq-console spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true spring.http.encoding.force=true logging.config=classpath:logback.xml #if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876 rocketmq.config.namesrvAddr= #if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true rocketmq.config.isVIPChannel= #rocketmq-console's data path:dashboard/monitor rocketmq.config.dataPath=/tmp/rocketmq-console/data #set it false if you don't want use dashboard.default true rocketmq.config.enableDashBoardCollect=true #set the message track trace topic if you don't want use the default one rocketmq.config.msgTrackTopicName= rocketmq.config.ticketKey=ticket #Must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required rocketmq.config.loginRequired=false |
将rocktmq-console打成jar包,得到rocketmq-console-ng-1.0.0.jar:
1 |
cd /opt/rocketmq-externals/rocketmq-console |
1 |
mvn clean package -Dmaven.test.skip=true |
运行jar包,启动项目,这里也可以设置rocketmq.config.namesrvAdd:
1 |
java -jar rocketmq-console-ng-1.0.0.jar --server.port=12581 --rocketmq.config.namesrvAddr=192.168.0.66:9876 |
服务器上需要开放几个端口用于console的连接,如果没有配置,就是默认的:9876,10911,10909 或者关掉防火墙
1 2 3 |
systemctl stop firewalld.service systemctl status firewalld.service systemctl start firewalld.service |
访问
1 |
http://192.168.0.66:12581/#/ |
配置文件详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#broker集群名称,用于划分broker brokerClusterName=MQCluster001 #broker名称,用于主从配对,相同名称的broker才能做主从设置 brokerName=mq_broker_1 #用于标识主从关系,0为主,其他大于0的为从(不能小于0)master设置0,slave设置1。Master角色的Broker支持读和写,Slave角色的Broker仅支持读,也就是Producer只能和Master角色的Broker连接写人消息:Consumer可以连接Master角色的Broker,也可以连接Slave角色的Broker来读取消息。 #Master节点设置 brokerId=0 #Slave节点设置 #brokerId=1 #name server服务器地址及端口,可以是多个,分号隔开 namesrvAddr=192.168.1.100:9876 #创建topic时,若未指定topic下的队列数,则取该默认值作为默认队列数 defaultTopicQueueNums=8 #是否自动创建默认topic,生产需保持关闭 autoCreateTopicEnable=true #是否自动创建topic的订阅组,默认开启 autoCreateSubscriptionGroup=true #broker服务监听端口 listenPort=10911 #未消费的持久化消息清理时间点 deleteWhen=04 #持久化消息保存周期(单位:小时),超过该周期将被清理 fileReservedTime=24 #单个commitLog文件的大小限制(单位:字节) mapedFileSizeCommitLog=1073741824 #单个consumeQueue大小限制(存储的消息条数 * 每条消息的索引大小20) mapedFileSizeConsumeQueue=8000000 #存储使用率阀值,当使用率超过阀值时,将拒绝发送消息请求 diskMaxUsedSpaceRatio=88 #持久化消息存储根路径(如果是容器启动,这里写容器内部目录即可,因为有外部挂载) storePathRootDir=/data/store(如果是容器启动,这里写容器内部目录即可,因为有外部挂载) #commitLog文件存储路径 storePathCommitLog=/data/store/commitlog #最大消息大小限制(单位:字节) maxMessageSize=65536 #commitLog最少刷盘page数 flushCommitLogLeastPages=4 #consumeQueue最少刷盘page数 flushConsumeQueueLeastPages=2 #commitLog刷盘间隔时间 flushCommitLogThoroughInterval=10000 #consumeQueue刷盘间隔时间 flushConsumeQueueThoroughInterval=60000 #处理消息发送线程池大小 sendMessageThreadPoolNums=128 #处理消息拉取线程池大小 pullMessageThreadPoolNums=128 #broker角色(SYNC_MASTER:同步双写Master、ASYNC_MASTER:异步复制Master、SLAVE:Slave) brokerRole=ASYNC_MASTER #Slave节点设置 #brokerRole=SLAVE #刷盘方式(ASYNC_FLUSH:异步刷盘、SYNC_FLUSH:同步刷盘) flushDiskType=ASYNC_FLUSH |
- 本文固定链接: https://www.yoyoask.com/?p=5341
- 转载请注明: shooter 于 SHOOTER 发表