Centos7.6搭建RocketMQ4.8全纪录
环境说明
ip地址主机名操作系统版本RocketMQ版本JDK版本maven版本172.16.7.91rabbitmq01centos 7.64.8.01.8.0_2913.6
一、安装jdk
1.下载jdk
下载地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
2.安装jdk
新建目录/opt/java并将下载的包jdk-8u291-linux-x64.rpm 上传
# mkdir /opt/java # cd /opt/java# rpm -ivh jdk-8u291-linux-x64.rpm
二、安装maven
1.下载安装包
# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz也可以到官网下载,下载地址:http://maven.apache.org/download.cgi
2.解压并配置环境变量
# tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr/local/# mv /usr/local/apache-maven-3.6.3/ /usr/local/maven3.6# sed -i '$a export PATH=$PATH:/usr/local/maven3.6/bin' /etc/profile && source /etc/profile# mvn -v
3.maven优化
3.1配置阿里源
# cd /usr/local/maven3.6/conf/# view settings.xml修改后:
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
3.2指定资源下载路径
<localRepository>/usr/local/maven3.6/repository</localRepository>
3.3指定JDK版本
将默认的1.4替换为实际的1.8
三、RocketMQ安装
1.版本选取
下载地址:https://github.com/apache/rocketmq/tags
本次选择的版本为最新的4.8.0
2.下载安装包
# wget https://github.com/apache/rocketmq/archive/refs/tags/rocketmq-all-4.8.0.tar.gz
3.编译方式安装
# tar -zxvf rocketmq-all-4.8.0.tar.gz# cd rocketmq-rocketmq-all-4.8.0/# mvn -Prelease-all -DskipTests clean install -U4.免编译安装
除了使用maven编译安装方式外,还可以直接下载带bin的安装包,免编译安装,步骤3和步骤4执行一个就行。
下载地址:https://apache.claz.org/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
# mkdir rocketmq# cd rocketmq/# wget https://apache.claz.org/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
rocketmq-all-4.8.0-bin-release.zip带bin版本的介质无需maven编译,解压后即可使用。
5.调整runserver.sh参数
调整前:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"调整后:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"6.调整runbroker.sh参数
调整前:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"调整后:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"由于默认启动的最大内存比较大,需要修改小点保证服务能正常启动。
7.启动namesrv
# nohup sh mqnamesrv &
namesrv启动成功
8.启动broker
# nohup sh mqbroker -n localhost:9876 &
broker节点启动成功
9.查看服务是否启动成功
# jps -l41467 org.apache.rocketmq.broker.BrokerStartup41214 org.apache.rocketmq.namesrv.NamesrvStartup43887 sun.tools.jps.Jpsnamesrv和broker启动正常
四、消息收发测试
1.生产者发送消息
# export NAMESRV_ADDR=localhost:9876
# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
消息测试,生产者发送大量的消息。
2.消费者消费消息
# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
五、安装管理面板
1.介质下载
git下载介质
# yum -y install git
# git clone https://github.com/apache/rocketmq-externals.git
或者下载到本地再上传,下载地址:https://github.com/apache/rocketmq-externals/archive/refs/heads/master.zip
这里选择先下载再上传方式
2.解压
# unzip rocketmq-externals-master.zip
3.修改配置文件
# pwd
/root/rocketmq-externals-master/rocketmq-console/src/main/resources
# view application.properties
自定义应用端口和nameserver端口
4.编译
# pwd
/root/rocketmq-externals-master/rocketmq-console
# mvn clean package -Dmaven.test.skip=true
编译过程如图,中间过程省略
编译成功,console目录下会生成target目录
5.运行
# cd target/
# java -jar rocketmq-console-ng-2.0.0.jar
6.访问console
原因是跨域造成的,需要修改服务器中broker的配置,添加服务器IP即可
六、重启服务
1.关闭服务
# pwd
/root/rocketmq/rocketmq-all-4.8.0-bin-release
# sh bin/mqshutdown broker
No mqbroker running.
# sh bin/mqshutdown namesrv
No mqnamesrv running.
关闭服务时先停止broker再停止namesrv
2.修改broker配置
# sed -i '$a brokerIP1=172.16.7.91' /root/rocketmq/rocketmq-all-4.8.0-bin-release/conf/broker.conf 3.开启服务
# pwd
/root/rocketmq/rocketmq-all-4.8.0-bin-release
# nohup sh bin/mqnamesrv &
# nohup sh bin/mqbroker -n localhost:9876 -c conf/broker.conf &启动服务时先启动nameserv再启动broker
启动完成
3.重新登陆console
七、自启动脚本
1.rocketmq服务脚本
# pwd
/etc/rc.d/init.d
# touch rocketmq
# chmod u+x rocketmq在/etc/rc.d/init.d下新建服务rocketmq,根据实际情况修改配置参数。
2.rocketmq服务启停测试
# service rocketmq stop
# service rocketmq start
# service rocketmq restart
3.rocketmq_console自启停脚本
# touch rocketmq_console
# chmod u+x rocketmq_console
# more rocketmq_console
4.rocketmq_console服务启停测试
# service rocketmq_console stop
# service rocketmq_console start
# service rocketmq_console restart
5.设置服务开机启动
# systemctl enable rocketmq
# systemctl enable rocketmq_console
# chkconfil --list
设置完成后开机会自启动namesrv、broker和console服务
搭建完成,配置和软件包已上传github:RocketMQ_install
页:
[1]