集群配置
主机名 | 地址 | 角色 | 软件 | 版本 |
---|---|---|---|---|
cacshop-middleware01 | 10.1.30.41 | namesrv | rocketmq | 4.9.3 |
cacshop-middleware02 | 10.1.30.42 | namesrv,broker-a | rocketmq | 4.9.3 |
cacshop-middleware03 | 10.1.30.43 | namesrv,broker-b | rocketmq | 4.9.3 |
配置环境
配置 host 解析
1
2
3
4
5
6cat >> /etc/hosts <<EOF
10.1.30.41 cacshop-middleware01
10.1.30.42 cacshop-middleware02
10.1.30.43 cacshop-middleware03
EOF
部署 JDK 环境
解压 jdk 安装包
1
2
3
4
5# 创建 JDK 安装目录
mkdir /usr/local/java
# 解压压缩包
tar xvf jdk-8u202-linux-x64.tar.gz -C /usr/local/java/配置环境变量
1
2
3
4
5
6
7
8
9
10cat > /etc/profile.d/java.sh <<EOF
#!/bin/bash
export JAVA_HOME=/usr/local/java/jdk1.8.0_202
export CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib
export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH:\$HOME/bin
EOF
# 刷新环境变量
source /etc/profile.d/java.sh
部署 RocketMQ
下载安装 RocketMQ
以下步骤在所有节点都要执行
下载 rocketmq 软件包
1
wget https://dlcdn.apache.org/rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip --no-check-certificate
解压 rocketmq
1
2
3unzip rocketmq-all-4.9.3-bin-release.zip -d /usr/local/
ln -s /usr/local/rocketmq-4.9.3 /usr/local/rocketmq创建 rocketmq 服务运行用户
1
2
3useradd -s /sbin/nologin -M rocketmq
chown -R rocketmq:rocketmq /usr/local/rocketmq /usr/local/rocketmq-4.9.3创建 rocketmq 数据存放目录
1
2
3mkdir -p /data/rocketmq/
chown -R rocketmq:rocketmq /data/rocketmq
配置 RocketMQ
登录 cacshop-middleware02 服务器,修改 broker-a.properties 配置文件,修改后内容如下
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# grep -v '^#\|^$' broker-a.properties
brokerClusterName=rocketmq-cluster
enablePropertyFilter=true
brokerName=broker-a
brokerId=0
namesrvAddr=cacshop-middleware01:9876;cacshop-middleware02:9876;cacshop-middleware03:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=11011
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
storePathCommitLog=/data/rocketmq/store/commitlog
storePathConsumeQueue=/data/rocketmq/store/consumequeue
storePathIndex=/data/rocketmq/store/index
storeCheckpoint=/data/rocketmq/store/checkpoint
abortFile=/data/rocketmq/store/abort
maxMessageSize=65536
brokerRole=ASYNC_FLUSH
flushDiskType=ASYNC_FLUSH登录 cacshop-middleware03 服务器,修改 broker-b.properties 配置文件,修改后内容如下
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# grep -v '^#\|^$' broker-b.properties
brokerClusterName=rocketmq-cluster
enablePropertyFilter=true
brokerName=broker-b
brokerId=0
namesrvAddr=cacshop-middleware01:9876;cacshop-middleware02:9876;cacshop-middleware03:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=11011
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
storePathCommitLog=/data/rocketmq/store/commitlog
storePathConsumeQueue=/data/rocketmq/store/consumequeue
storePathIndex=/data/rocketmq/store/index
storeCheckpoint=/data/rocketmq/store/checkpoint
abortFile=/data/rocketmq/store/abort
maxMessageSize=65536
brokerRole=ASYNC_FLUSH
flushDiskType=ASYNC_FLUSH创建 RocketMQ 服务管理文件
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
54
55
56
57
58
59
60
61
62
63
64
65
66# 在所有节点上执行以下命令,创建 namesrv 服务管理文件
cat > /usr/lib/systemd/system/rocketmq-namesrv.service <<EOF
[Unit]
Description=rocketmq - nameserver
Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
After=network.target
[Service]
Type=simple
User=rocketmq
Group=rocketmq
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_202"
Environment="CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib"
ExecStart=/usr/local/rocketmq-4.9.3/bin/mqnamesrv
ExecStop=/usr/local/rocketmq-4.9.3/bin/mqshutdown namesrv
Restart=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
# 在 cacshop-middleware02 节点上执行以下命令,创建 brocker 服务管理文件
cat > /usr/lib/systemd/system/rocketmq-broker.service <<EOF
[Unit]
Description=rocketmq - broker-master-1
Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
After=network.target
[Service]
Type=simple
User=rocketmq
Group=rocketmq
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_202"
Environment="CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib"
ExecStart=/usr/local/rocketmq-4.9.3/bin/mqbroker -c /usr/local/rocketmq-4.9.3/conf/2m-noslave/broker-a.properties
ExecStop=/usr/local/rocketmq-4.9.3/bin/mqshutdown broker
Restart=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
# 在 cacshop-middleware03 节点上执行以下命令,创建 brocker 服务管理文件
cat > /usr/lib/systemd/system/rocketmq-broker.service <<EOF
[Unit]
Description=rocketmq - broker-master-2
Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
After=network.target
[Service]
Type=simple
User=rocketmq
Group=rocketmq
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_202"
Environment="CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib"
ExecStart=/usr/local/rocketmq-4.9.3/bin/mqbroker -c /usr/local/rocketmq-4.9.3/conf/2m-noslave/broker-b.properties
ExecStop=/usr/local/rocketmq-4.9.3/bin/mqshutdown broker
Restart=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF启动 rocketmq 相关关服务
1
2
3
4
5
6# 首先在所有节点启动 namesrv 服务
systemctl enable --now rocketmq-namesrv.service
# 其次在 cacshop-middleware02 与 cacshop-middleware03 节点启动 namesrv 与 brocker 服务
systemctl enable --now rocketmq-namesrv.service
systemctl enable --now rocketmq-broker.service查看服务状态
1
2
3
4
5# 查看 namesrv 服务
systemctl status rocketmq-namesrv.service
# 查看 brocker 服务
systemctl status rocketmq-broker.service注意: rocketmq-broker.service 有可能会启动失败,需要修改 JVM 配置,可以修改 bin/runbroker.sh 文件中(88行左右) JAVA_OPT=”${JAVA_OPT} -server -Xms2g -Xmx2g” 配置
可以使用以下命令查看集群状态
1
2
3
4
5
6# /usr/local/rocketmq/bin/mqadmin clusterList -n localhost:9876
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.InternalThreadLocalMap).
RocketMQLog:WARN Please initialize the logger system properly.
#Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
rocketmq-cluster broker-a 0 10.1.30.42:11011 V4_9_3 0.00(0,0ms) 0.00(0,0ms) 0 475953.46 0.0700
rocketmq-cluster broker-b 0 10.1.30.43:11011 V4_9_3 0.00(0,0ms) 0.00(0,0ms) 0 475953.46 0.0700