rocketmq安装和部署

一、下载

本文rocketmq版本是4.3.2,下载地址:https://rocketmq.apache.org/dowloading/releases/
系统:centos 7
JDK版本:1.8.0_221
rocketmq安装和部署_第1张图片
如果是安装部署需求的话,建议下载Binary版本,因为下载Source版本的话,还要到linux中编译
如果是学习源码需求的话,建议下载Source版本

二、单机版安装部署
2.1 修改运行内存

因为rocketmq默认运行内存是4g,但是我们这是虚拟机,给不了那么多内存,所以这里给个256m
修改/usr/local/rocketmq/bin/runserver.sh/usr/local/rocketmq/bin/runbroker.sh中JAVA_OPT关于内存的设置

/usr/local/rocketmq-all-4.3.2-bin-release/bin目录执行vim runserver.sh修改JAVA_OPT,下面是修改后的样子

#修改此处的内存大小,默认为4g,一般我们的虚拟机内存不会太大 40 #所以此处修改为256m,可以根据自己机器的配置合理设置
#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m"

/usr/local/rocketmq-all-4.3.2-bin-release/bin目录执行vim runbroker.sh修改JAVA_OPT,下面是修改后的样子

# 默认需要内存大小为8g
#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
2.2、运行服务namesrv
[root@load01 bin]# pwd
/usr/local/rocketmq-all-4.3.2-bin-release/bin
#可以不用nohup,这里用nohup,只是方便看其运行日志
#192.168.93.224:9876是本机ip和其分配的端口号
[root@load01 bin] nohup sh mqnamesrv ‐n 192.168.93.224:9876 &

#查看日志
[root@load01 bin] nohup: 忽略输入并把输出追加到"nohup.out"
tail -f nohup.out
OpenJDK 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
OpenJDK 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON
2.3、启动broker

第一步,假设我们的IP是:192.168.93.224,修改配置文件broker.conf,加上:brokerIP1=192.168.93.224

brokerIP1=192.168.93.224
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH

第二步,启动配置配置文件

#192.168.93.224:9876为nameserver,链接进行注册
#autoCreateTopicEnable=true(允许创建topic)
[root@load01 rocketmq-all-4.3.2-bin-release] nohup sh bin/mqbroker ‐n 192.168.93.224:9876 ‐c conf/broker.conf autoCreateTopicEnable=true &
#查询日志
[root@load01 rocketmq-all-4.3.2-bin-release] tail -f nohup.out
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
The broker[load01, 192.168.93.224:10911] boot success. serializeType=JSON
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
The broker[load01, 192.168.93.224:10911] boot success. serializeType=JSON and name server is 192.168.93.224:9876
2.3、关闭命令

方案一

#‐‐关闭broker
[root@load01 rocketmq-all-4.3.2-bin-release] sh bin/mqshutdown broker

#‐‐关闭namesrv
[root@load01 rocketmq-all-4.3.2-bin-release] sh bin/mqshutdown namesrv

方案二

#‐‐杀掉进程 
[root@load01 rocketmq-all-4.3.2-bin-release] ps ‐ef|grep rocketmq 查看pid(进程号) 
[root@load01 rocketmq-all-4.3.2-bin-release] kill ‐9 pid(进程号)
三、集群版安装部署

准备2个虚拟机分别是虚拟机192.168.93.224与192.168.93.222,分别部署2个 NameServer,并在每台机器上分别启动一个Master和一个Slave,互为主备

准备动作,在192.168.93.224和192.168.93.222的rocketmq的conf目录下创建2个文件

[root@save conf]# cp broker.conf broker-m.conf 
[root@save conf]# cp broker.conf broker-s.conf
3.1、配置192.168.93.224 Master和Slave

Master broker-m.conf配置如下

namesrvAddr = 192.168.93.224:9876;192.168.93.222:9876
brokerIP1 = 192.168.93.224
brokerClusterName = clyu_cluster
brokerName = broker-a
#0表示主节点
brokerId = 0
deleteWhen = 04
fileReservedTime = 48

#当前节点角色
brokerRole = SYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true

#broker通信端口,默认端口
listenPort = 10911
storePathRootDir = /root/rocketmq/store‐m

Slave broker-s.conf配置

namesrvAddr = 192.168.93.224:9876;192.168.93.222:9876
brokerIP1 = 192.168.93.224
brokerClusterName = clyu_cluster
brokerName = broker-a

brokerId = 1
deleteWhen = 04
fileReservedTime = 48

#当前节点角色
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true

#broker通信端口,默认端口
listenPort = 10811
storePathRootDir = /root/rocketmq/store‐s

启动mqnamesrv

[root@load01 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqnamesrv -n 192.168.93.224:9876 &

启动broker Master

[root@load01 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c conf/broker-m.conf &

启动broker Slave

[root@load01 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c conf/broker-s.conf &
3.2、配置192.168.93.222 Master和Slave

Master broker-m.conf配置如下

namesrvAddr = 192.168.93.224:9876;192.168.93.222:9876
brokerIP1 = 192.168.93.222
brokerClusterName = clyu_cluster
brokerName = broker-b
#0表示主节点
brokerId = 0
deleteWhen = 04
fileReservedTime = 48

#当前节点角色
brokerRole = SYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true

#broker通信端口,默认端口
listenPort = 10911
storePathRootDir = /root/rocketmq/store‐m

Slave broker-s.conf配置

namesrvAddr = 192.168.93.224:9876;192.168.93.222:9876
brokerIP1 = 192.168.93.222
brokerClusterName = clyu_cluster
brokerName = broker-b

brokerId = 1
deleteWhen = 04
fileReservedTime = 48

#当前节点角色
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true

#broker通信端口,默认端口
listenPort = 10811
storePathRootDir = /root/rocketmq/store‐s

启动mqnamesrv 与 mqbroker

[root@load01 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqnamesrv -n 192.168.93.222:9876 &

启动broker Master

[root@load01 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c conf/broker-m.conf &

启动broker Slave

[root@load01 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c conf/broker-s.conf &

集群启动后,查看集群监控状态

[root@save rocketmq-all-4.3.2-bin-release]# sh bin/mqadmin clusterlist -n 192.168.93.222:9876
OpenJDK 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
#Cluster Name     #Broker Name            #BID  #Addr                  #Version                #InTPS(LOAD)       #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
clyu_cluster      broker-a                0     192.168.93.224:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 457361.49 -1.0000
clyu_cluster      broker-a                1     192.168.93.224:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 457361.49 0.0493
clyu_cluster      broker-b                0     192.168.93.222:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 457361.49 0.0550
clyu_cluster      broker-b                1     192.168.93.222:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 457361.49 0.0550

你可能感兴趣的:(RocketMQ,centos,java,中间件)