配置三台主机的IP与主机名的映射
下边展示的ip不是真实的,只是用来替代一下,请大家在自己配置的时候用自己真实ip进行替换。前边是ip,主机名在后边。
192.168.152.128 Sea1
192.168.152.129 Sea2
192.168.152.130 Sea3
三台机器都使用vim /etc/hosts
将上边的ip与主机名称放到hosts文件里边。
cat /etc/hosts
可以显示hosts文件里边的内容。
安装JDK 8
下载
https://www.oracle.com/java/technologies/downloads/是Oracle下载的官网。https://www.oracle.com/java/technologies/downloads/archive/页面往下边拉才可以找JDK 8的下载地址。还是可以使用wget进行下载,但是需要登录才能获得下载地址或者直接在浏览器里边下载。
解压
我下载到了/root目录下,这里解压到/jdk目录下然后配置环境变量。
mkdir /jdk
在根目录下创建jdk目录。
tar -zxf /root/jdk-8u341-linux-x64.tar.gz -C /jdk
将jdk-8u341-linux-x64解压至jdk目录里。
ls -l /jdk/jdk1.8.0_341/
确认是否解压成功。
配置环境变量
vim /etc/profile
配置环境变量,在末尾加上下边的内容:
export JAVA_HOME=/jdk/jdk1.8.0_341/
PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
使用环境变量生效。
java -version
输入终端,若是出现下边的内容,就是成功了:
三台云主机都需要把JDK安装好。
RocketMQ安装
下载与解压
https://rocketmq.apache.org/是官网。
https://rocketmq.apache.org/download,在刚刚官网首页点击“Download”,可以进入这个下载网址。
mkdir /rocketmq
创建放置压缩包的目录。
wget https://archive.apache.org/dist/rocketmq/4.9.1/rocketmq-all-4.9.1-bin-release.zip -P /rocketmq
下载压缩包。
可以三个云主机都用这个命令下载,也可以一台下载好之后,然后使用scp 需要传输的文件 用户@IP/主机名:放置的目录
远程传输,比如使用scp /root/rocketmq-all-4.9.1-bin-release.zip root@192.168.152.129:/app/
IP远程传输,比如使用scp rocketmq-all-4.9.1-bin-release.zip root@192.168.152.130:/rocketmq/
IP远程传输。也可以使用上边配置好的主机名scp rocketmq-all-4.9.1-bin-release.zip root@Sea1:/rocketmq/
进行远程传输。
yum install unzip
下载解压zip软件。
显示“Complete!”才算完成。
unzip /rocketmq/rocketmq-all-4.9.1-bin-release.zip -d /rocketmq/
解压文件到/rocketmq目录。
配置RocketMQ环境变量
vim /etc/profile
编辑配置文件,在文件末尾加上下边的内容:
export ROCKETMQ_HOME=/rocketmq/rocketmq-all-4.9.1-bin-release
PATH=$PATH:$JAVA_HOME/bin:$ROCKETMQ_HOME/bin
我的/etc/profile最后内容如下:
source /etc/profile
使用配置生效。
配置RocketMQ启动文件和配置文件
第一个节点Sea1配置
vim /rocketmq/rocketmq-all-4.9.1-bin-release/bin/runserver.sh
,把NameServer启动内存从默认的4G调整为512M。
调整后的内容如下:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
需要调整这两行。
vim /rocketmq/rocketmq-all-4.9.1-bin-release/bin/runbroker.sh
把Broker的8G默认预设内存调整为如下:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m"
vim /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-a.properties
然后把下边的RocketMQ启动文件内容配置进去。
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.152.128
brokerIP2=192.168.152.128
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-a
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=Sea1:9876;Sea2:9876;Sea3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128
vim /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-b-s.properties
,把下边的内容配置进去。
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.152.128
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-b
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=Sea1:9876;Sea2:9876;Sea3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=11011
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/rocketmq/storeSlave
#commitLog 存储路径
storePathCommitLog=/rocketmq/storeSlave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/rocketmq/storeSlave/consumequeue
#消息索引存储路径
storePathIndex=/rocketmq/storeSlave/index
#checkpoint 文件存储路径
storeCheckpoint=/rocketmq/storeSlave/checkpoint
#abort 文件存储路径
abortFile=/rocketmq/storeSlave/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128
第二个节点Sea2配置
像第一个节点一样配置NameServer启动内存和Broker启动内存,配置参数如上边一样。vim /rocketmq/rocketmq-all-4.9.1-bin-release/bin/runserver.sh
,把NameServer启动内存从默认的4G调整为512M。vim /rocketmq/rocketmq-all-4.9.1-bin-release/bin/runbroker.sh
把Broker启动内存调整为512M。
vim /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-b.properties
,把下边的内容配置进去。
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.152.129
brokerIP2=192.168.152.129
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-b
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=Sea1:9876;Sea2:9876;Sea3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128
vim /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-a-s.properties
,把下边的内容配置进去。
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.152.129
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-a
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=Sea1:9876;Sea2:9876;Sea3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=11011
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/rocketmq/storeSlave
#commitLog 存储路径
storePathCommitLog=/rocketmq/storeSlave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/rocketmq/storeSlave/consumequeue
#消息索引存储路径
storePathIndex=/rocketmq/storeSlave/index
#checkpoint 文件存储路径
storeCheckpoint=/rocketmq/storeSlave/checkpoint
#abort 文件存储路径
abortFile=/rocketmq/storeSlave/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128
第三个节点Sea3配置
像第一个节点一样配置NameServer启动内存,配置参数如上边第一个节点Sea1一样。vim /rocketmq/rocketmq-all-4.9.1-bin-release/bin/runserver.sh
,把NameServer启动内存从默认的4G调整为512M。
在云服务器上把端口打开
如下图把云服务器中的9876端口、11011端口、11009端口和10909 端口都打开。
已经把9876端口的设置如上图设置好了,其他端口一样设置。
第一个节点Sea1启动组件
cd /rocketmq/rocketmq-all-4.9.1-bin-release
进入到特定目录下,把把下边程序NameServer和Broker启动之后产生的nohup.out放到这里nohup.out放到这里。
nohup mqnamesrv &
,“&”表示后台启动NameServer,nohup相当于日志。
nohup mqbroker -c /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-a.properties &
,使用broker-a.properties配置文件后台启动Broker。
nohup mqbroker -c /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-b-s.properties &
,使用broker-b-s.properties配置文件后台启动Broker。
可以使用
jps
查看是否启动成功。
第二个节点Sea2启动组件
cd /rocketmq/rocketmq-all-4.9.1-bin-release
进入到特定目录下,把下边程序启动之后产生的nohup.out放到这里。
nohup mqnamesrv &
,后台启动NameServer.
nohup mqbroker -c /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-b.properties &
,使用broker-b.properties配置文件后台启动Broker。
nohup mqbroker -c /rocketmq/rocketmq-all-4.9.1-bin-release/conf/2m-2s-async/broker-a-s.properties &
,使用broker-a-s.properties后台启动Broker。
第三个节点Sea3启动组件
cd /rocketmq/rocketmq-all-4.9.1-bin-release
进入到特定目录下,把下边程序启动之后产生的nohup.out放到这里。
nohup mqnamesrv &
,后台启动NameServer.
也可以使用cat nohup.out查看日志来确定是否启动了。
上图中日志输出内容就是启动成功了。
进行启动后的测试
在Sea1
发送消息之前,先使用vim /etc/profile
把export NAMESRV_ADDR='Sea1:9876;Sea2:9876;Sea3:9876'
配置到/etc/profile中,然后使用source /etc/profile
使环境变量生效。
我的环境变量最后如下图所示,图中还有source /etc/profile命令:
在第一个节点Sea1
上使用示例代码tools.sh org.apache.rocketmq.example.quickstart.Producer
使用发送消息。
消息发送成功会显示如下内容:
23:25:47.401 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[192.168.152.128:10911] result: true
23:25:47.405 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[192.168.152.129:9876] result: true
23:25:47.405 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[192.168.152.129:10911] result: true
按下Ctrl+C
按键,可以停止。
在第二个节点Sea2
执行tools.sh org.apache.rocketmq.example.quickstart.Consumer
报错如下:
Exception in thread "main" java.lang.IllegalStateException: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to null failed
at org.apache.rocketmq.client.impl.factory.MQClientInstance.updateTopicRouteInfoFromNameServer(MQClientInstance.java:679)
at org.apache.rocketmq.client.impl.factory.MQClientInstance.updateTopicRouteInfoFromNameServer(MQClientInstance.java:509)
at org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl.updateTopicSubscribeInfoWhenSubscriptionChanged(DefaultMQPushConsumerImpl.java:871)
at org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl.start(DefaultMQPushConsumerImpl.java:654)
at org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.start(DefaultMQPushConsumer.java:698)
at org.apache.rocketmq.example.quickstart.Consumer.main(Consumer.java:78)
Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to null failed
at org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:394)
at org.apache.rocketmq.client.impl.MQClientAPIImpl.getTopicRouteInfoFromNameServer(MQClientAPIImpl.java:1365)
at org.apache.rocketmq.client.impl.MQClientAPIImpl.getTopicRouteInfoFromNameServer(MQClientAPIImpl.java:1355)
at org.apache.rocketmq.client.impl.factory.MQClientInstance.updateTopicRouteInfoFromNameServer(MQClientInstance.java:622)
... 5 more
这是由于虽然把
export NAMESRV_ADDR='Sea1:9876;Sea2:9876;Sea3:9876'
写到了Sea2
节点/etc/profile中,但是忘记执行source /etc/profile
使环境变量生效。
执行完source /etc/profile
,再次执行tools.sh org.apache.rocketmq.example.quickstart.Consumer
,反复显示下边类似的内容就是成功:
ConsumeMessageThread_19 Receive New Messages: [MessageExt [brokerName=broker-a, queueId=1, storeSize=194, queueOffset=499, sysFlag=0, bornTimestamp=1669735746400, bornHost=/192.168.152.128:42632, storeTimestamp=1669735746400, storeHost=/192.168.152.128:10911, msgId=726055A000002A9F000000000005E943, commitLogOffset=387395, bodyCRC=1359908749, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1669735746400, UNIQ_KEY=7F00000132664AA298B7953C236003E6, CLUSTER=rocketmq-cluster, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 57, 56], transactionId='null'}]]
ConsumeMessageThread_1 Receive New Messages: [MessageExt [brokerName=broker-a, queueId=2, storeSize=194, queueOffset=499, sysFlag=0, bornTimestamp=1669735746400, bornHost=/192.168.152.128:42632, storeTimestamp=1669735746401, storeHost=/192.168.152.128:10911, msgId=726055A000002A9F000000000005EA05, commitLogOffset=387589, bodyCRC=638172955, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1669735746403, UNIQ_KEY=7F00000132664AA298B7953C236003E7, CLUSTER=rocketmq-cluster, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 57, 57], transactionId='null'}]]
按下Ctrl+C
按键,可以停止。
安装管理控制台并启动
安装Maven
我这里选择的是3.6.3进行安装,使用wget https://dlcdn.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
下载文件的时候,报下边的错:
ERROR: cannot verify dlcdn.apache.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
To connect to dlcdn.apache.org insecurely, use `--no-check-certificate'.
然后改成
wget --no-check-certificate https://dlcdn.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
,就可以下载成功了。
tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr
解压到/usr目录下面。
ln -s /usr/apache-maven-3.6.3 /usr/apache-maven
设置软链接,这样的话,以后只需要把-s后边/usr/apache-maven-3.6.3改成其他目录,比如/root/apache-maven-3.8.6,可以在不改动环境变量的情况下,就能升降版本。
使用ll /usr/apache-maven
查看是否设置成功
使用
vim /etc/profile
,在末尾添上内容:
M2_HOME=/usr/apache-maven
PATH=$PATH:$M2_HOME/bin
source /etc/profile
使环境变量生效。
mvn -v
命令显示如下图内容就是安装成功。
vim /usr/apache-maven-3.6.3/conf/settings.xml
在中间添上如下内容:
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
配置国内Maven仓库,加快依赖包下载速度。
下载rocketmq-dashboard并安装运行
在Sea1节点上cd /rocketmq/
进入/rocketmq下。
git clone https://github.com/apache/rocketmq-dashboard.git
获取源代码。
vim /rocketmq/rocketmq-dashboard/src/main/resources/application.yml
编辑namesrvAddrs的值:
- Sea1:9876
- Sea2:9876
- Sea3:9876
cd /rocketmq/rocketmq-dashboard/
进入到pom.xml
文件所在目录。
mvn clean package -Dmaven.test.skip=true
开始编译源码,会下载很多依赖包,时间会就久一些。
上边失败了,再次执行mvn clean package -Dmaven.test.skip=true
,就成功了。
也可以使用cd /rocketmq/rocketmq-dashboard/ && mvn clean package -Dmaven.test.skip=true
直接开始编译,“&&”相当于把两个命令先后执行,即先执行cd /rocketmq/rocketmq-dashboard/
,然后执行mvn clean package -Dmaven.test.skip=true
。
跟上面一样需要打开端口,这次打开的是8080,点开主机名称进入下方安全组的设置:
点击“添加规则”按钮:
添加上“8080”之后,然后点击“确定”。
然后使用
java -jar /rocketmq/rocketmq-dashboard/target/rocketmq-dashboard-1.0.1-SNAPSHOT.jar
启动起来。
在自己本机电脑浏览器中输入192.168.152.128:8080,发现连接超时。然后自己从各个配置文件中找到ip、主机名和端口设置,发现都没有问题。后来我想到天翼云的云服务器公网ip使用我这边的家用wifi连不上,所以我调成了自己的手机热点供浏览器使用,结果发现putty正常连上云主机,浏览器输入192.168.152.128:8080还是显示连接超时。在本机上使用curl+上图中clientIP,即curl 172.31.0.180:8080
可以连通发现能够连通内网,下图是本机上curl 172.31.0.180:8080
正常访问返回页面的图片。
查过网上才知道天翼云的80、443和8080端口都要提交注册,注册成功之后才能使用。使用“Ctrl+C”组合按键把rocketmq-dashboard关闭。vim /rocketmq/rocketmq-dashboard/src/main/resources/application.yml
把8091设为提供服务的端口。
然后像上边到安全组添加8080端口一样,把云服务器中的8091端口添加规则里。然后java -jar /rocketmq/rocketmq-dashboard/target/rocketmq-dashboard-1.0.1-SNAPSHOT.jar
启动起来rocketmq-dashboard程序。
在自己本机电脑浏览器中输入192.168.152.128:8091,浏览器加载了一会儿,显示如下:
说明已经成功。