环境说明
主机 | IP地址 | 角色 | 系统版本 | 软件版本 | JDK 版本 |
---|---|---|---|---|---|
base-server01 | 192.168.0.9 | namerv | Kylin Linux Advanced Server V10 | rockermq-4.9.3 | 1.8.0_333 |
base-server02 | 192.168.0.30 | namerv,broker-a | Kylin Linux Advanced Server V10 | rockermq-4.9.3 | 1.8.0_333 |
base-server03 | 192.168.0.78 | namerv,broker-b | Kylin Linux Advanced Server V10 | rockermq-4.9.3 | 1.8.0_333 |
安装 JDK
所有节点执行以下命令,安装 JDK 环境
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17# 创建 JDK 安装目录
mkdir /usr/local/java
# 解压压缩包
tar xvf jdk-8u333-linux-aarch64.tar.gz -C /usr/local/java/
# 配置环境变量
cat > /etc/profile.d/java.sh <<EOF
#!/bin/bash
export JAVA_HOME=/usr/local/java/jdk1.8.0_333
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 软件包
1
wget https://archive.apache.org/dist/rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip --no-check-certificate
解压 rocketmq
1
unzip rocketmq-all-4.9.3-bin-release.zip -d /usr/local/
创建 rocketmq 运行用户以及数据存放目录
1
2useradd -s /sbin/nologin -M rocketmq
mkdir -p /data/rocketmq/登录 base-server02 服务器,修改 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 '^#\|^$' rocketmq-4.9.3/conf/2m-noslave/broker-a.properties
brokerClusterName=rocketmq-cluster
enablePropertyFilter=true
brokerName=broker-a
brokerId=0
namesrvAddr=192.168.0.9:9876;192.168.0.30:9876;192.168.0.78: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登录 base-server03 服务器,修改 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 '^#\|^$' rocketmq-4.9.3/conf/2m-noslave/broker-b.properties
brokerClusterName=rocketmq-cluster
enablePropertyFilter=true
brokerName=broker-b
brokerId=0
namesrvAddr=192.168.0.9:9876;192.168.0.30:9876;192.168.0.78: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# 在所有节点上执行以下命令,创建 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
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_333"
Environment="CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib"
ExecStart=/usr/local/rocketmq-4.9.3/bin/mqnamesrv
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
# 在 base-server02 节点上执行以下命令,创建 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
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_333"
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
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
# 在 base-server03 节点上执行以下命令,创建 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
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_333"
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
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF修改所有创建的与 rocketmq 相关的文件属主与属组为 rocketmq
1
2
3
4
5# 修改数据存放目录
chown -R rocketmq:rocketmq /data/rocketmq/
# 修改 rocketmq 工作目录
chown -R rocketmq:rocketmq /usr/local/rocketmq-4.9.3/启动 rocketmq 服务
1
2
3
4
5# 首先在所有节点启动 namesrv 服务
systemctl enable --now rocketmq-namesrv.service
# 其次在 base-noroot2 与 base-noroot3 节点启动 brocker 服务
systemctl enable --now rocketmq-broker.service查看服务状态
1
2
3
4
5
6
7
8# 查看 namesrv 服务
systemctl status rocketmq-namesrv.service
# 查看 brocker 服务
systemctl status rocketmq-broker.service
# 查看集群状态
/usr/local/rocketmq-4.9.3/bin/mqadmin clusterList -n localhost:9876
错误问题
问题1:
Error: VM option 'UseG1GC' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.
1
2
3mqbroker[43827]: Error: VM option 'UseG1GC' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.
mqbroker[43827]: Error: Could not create the Java Virtual Machine.
mqbroker[43827]: Error: A fatal exception has occurred. Program will exit.解决方法: 编辑
/usr/local/rocketmq-4.9.3/bin/runbroker.sh
文件,去掉-XX:+UseG1GC
选项
部署 Rocketmq Dashboard
Docker run 方式部署
安装 RocketMQ 管理控制台
1
2
3
4
5
6docker run -d \
--restart=always \
--name rocketmq-dashboard \
-e "JAVA_OPTS=-Drocketmq.config.namesrvAddr=192.168.0.9:9876;192.168.0.30:9876;192.168.0.78:9876" \
-p 8089:8089 \
-it registry-changsha.vonebaas.com/publics/rocketmq-dashboard:v1.0.1使用 ingress 代理 rocketmq-dashboard
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
54cat > rocketmq-dashboard.yaml <<EOF
apiVersion: v1
kind: Service
metadata:
labels:
app: rocketmq-dashboard
name: rocketmq-dashboard
namespace: publics
spec:
ports:
- port: 80
name: http
protocol: TCP
targetPort: 8089
type: ClusterIP
---
apiVersion: v1
kind: Endpoints
metadata:
labels:
app: rocketmq-dashboard
name: rocketmq-dashboard
namespace: publics
subsets:
- addresses:
- ip: 192.168.0.9
ports:
- name: http
port: 8089
protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rocketmq-dashboard
namespace: publics
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 20m
spec:
ingressClassName: nginx
rules:
- host: rocketmq-dashboard.vonebaas.com
http:
paths:
- backend:
service:
name: rocketmq-dashboard
port:
number: 80
path: /
pathType: ImplementationSpecific
EOF
$ kubectl create -f rocketmq-dashboard.yaml
K8s Deployment 方式部署
创建资源清单 rocketmq-dashboard.yaml,文件内容如下
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92apiVersion: v1
kind: Service
metadata:
labels:
app: rocketmq-dashboard
name: rocketmq-dashboard
namespace: publics
spec:
ports:
- port: 8089
name: http
protocol: TCP
targetPort: 8089
selector:
app: rocketmq-dashboard
type: ClusterIP
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rocketmq-dashboard
namespace: publics
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 20m
spec:
ingressClassName: nginx
rules:
- host: rocketmq-dashboard.vonebaas.com
http:
paths:
- backend:
service:
name: rocketmq-dashboard
port:
number: 8089
path: /
pathType: ImplementationSpecific
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: rocketmq-dashboard
name: rocketmq-dashboard
namespace: publics
spec:
replicas: 1
selector:
matchLabels:
app: rocketmq-dashboard
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: rocketmq-dashboard
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: groups
operator: In
values:
- vbaas
containers:
- env:
- name: JAVA_OPTS
value: "-Drocketmq.namesrv.addr=192.168.0.9:9876;192.168.0.30:9876;192.168.0.78:9876"
image: registry-changsha.vonebaas.com/publics/rocketmq-dashboard:v1.0.1
imagePullPolicy: IfNotPresent
name: rocketmq-dashboard
ports:
- containerPort: 8089
name: http
protocol: TCP
resources:
requests:
cpu: 100m
memory: 512Mi
imagePullSecrets:
- name: harbor-secret-changsha
restartPolicy: Always
tolerations:
- effect: NoExecute
key: groups
operator: Equal
value: vbaas应用资源清单
1
kubectl create -f rocketmq-dashboard.yaml