ip地址 | 主机名 | 操作系统版本 | RocketMQ版本 | JDK版本 | maven版本 |
---|---|---|---|---|---|
172.16.7.91 | rabbitmq01 | centos 7.6 | 4.8.0 | 1.8.0_291 | 3.6 |
下载地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
新建目录/opt/java并将下载的包jdk-8u291-linux-x64.rpm 上传
[root@rabbitmq01 ~]# mkdir /opt/java
[root@rabbitmq01 ~]# cd /opt/java
[root@rabbitmq01 java]# rpm -ivh jdk-8u291-linux-x64.rpm
[root@rabbitmq01 ~]# 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
[root@rabbitmq01 ~]# tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr/local/
[root@rabbitmq01 ~]# mv /usr/local/apache-maven-3.6.3/ /usr/local/maven3.6
[root@rabbitmq01 ~]# sed -i '$a export PATH=$PATH:/usr/local/maven3.6/bin' /etc/profile && source /etc/profile
[root@rabbitmq01 ~]# mvn -v
[root@rabbitmq01 ~]# cd /usr/local/maven3.6/conf/
[root@rabbitmq01 conf]# view settings.xml
修改后:
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<localRepository>/usr/local/maven3.6/repository</localRepository>
将默认的1.4替换为实际的1.8
下载地址:https://github.com/apache/rocketmq/tags
本次选择的版本为最新的4.8.0
[root@rabbitmq01 ~]# wget https://github.com/apache/rocketmq/archive/refs/tags/rocketmq-all-4.8.0.tar.gz
[root@rabbitmq01 ~]# tar -zxvf rocketmq-all-4.8.0.tar.gz
[root@rabbitmq01 ~]# cd rocketmq-rocketmq-all-4.8.0/
[root@rabbitmq01 rocketmq-rocketmq-all-4.8.0]# mvn -Prelease-all -DskipTests clean install -U
除了使用maven编译安装方式外,还可以直接下载带bin的安装包,免编译安装,步骤3和步骤4执行一个就行。
下载地址:https://apache.claz.org/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
[root@rabbitmq01 ~]# mkdir rocketmq
[root@rabbitmq01 ~]# cd rocketmq/
[root@rabbitmq01 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编译,解压后即可使用。
调整前:
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"
调整前:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
调整后:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
由于默认启动的最大内存比较大,需要修改小点保证服务能正常启动。
[root@rabbitmq01 bin]# nohup sh mqnamesrv &
namesrv启动成功
[root@rabbitmq01 bin]# nohup sh mqbroker -n localhost:9876 &
broker节点启动成功
[root@rabbitmq01 ~]# jps -l
41467 org.apache.rocketmq.broker.BrokerStartup
41214 org.apache.rocketmq.namesrv.NamesrvStartup
43887 sun.tools.jps.Jps
namesrv和broker启动正常
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# export NAMESRV_ADDR=localhost:9876
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
消息测试,生产者发送大量的消息。
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
git下载介质
[root@rabbitmq01 ~]# yum -y install git
[root@rabbitmq01 ~]# git clone https://github.com/apache/rocketmq-externals.git
或者下载到本地再上传,下载地址:https://github.com/apache/rocketmq-externals/archive/refs/heads/master.zip
这里选择先下载再上传方式
[root@rabbitmq01 ~]# unzip rocketmq-externals-master.zip
[root@rabbitmq01 resources]# pwd
/root/rocketmq-externals-master/rocketmq-console/src/main/resources
[root@rabbitmq01 resources]# view application.properties
自定义应用端口和nameserver端口
[root@rabbitmq01 rocketmq-console]# pwd
/root/rocketmq-externals-master/rocketmq-console
[root@rabbitmq01 rocketmq-console]# mvn clean package -Dmaven.test.skip=true
编译过程如图,中间过程省略
编译成功,console目录下会生成target目录
[root@rabbitmq01 rocketmq-console]# cd target/
[root@rabbitmq01 target]# java -jar rocketmq-console-ng-2.0.0.jar
原因是跨域造成的,需要修改服务器中broker的配置,添加服务器IP即可
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# pwd
/root/rocketmq/rocketmq-all-4.8.0-bin-release
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# sh bin/mqshutdown broker
No mqbroker running.
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# sh bin/mqshutdown namesrv
No mqnamesrv running.
关闭服务时先停止broker再停止namesrv
[root@rabbitmq01 ~]# sed -i '$a brokerIP1=172.16.7.91' /root/rocketmq/rocketmq-all-4.8.0-bin-release/conf/broker.conf
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# pwd
/root/rocketmq/rocketmq-all-4.8.0-bin-release
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# nohup sh bin/mqnamesrv &
[root@rabbitmq01 rocketmq-all-4.8.0-bin-release]# nohup sh bin/mqbroker -n localhost:9876 -c conf/broker.conf &
启动服务时先启动nameserv再启动broker
启动完成
[root@rabbitmq01 init.d]# pwd
/etc/rc.d/init.d
[root@rabbitmq01 init.d]# touch rocketmq
[root@rabbitmq01 init.d]# chmod u+x rocketmq
在/etc/rc.d/init.d下新建服务rocketmq,根据实际情况修改配置参数。
[root@rabbitmq01 ~]# service rocketmq stop
[root@rabbitmq01 ~]# service rocketmq start
[root@rabbitmq01 ~]# service rocketmq restart
[root@rabbitmq01 init.d]# touch rocketmq_console
[root@rabbitmq01 init.d]# chmod u+x rocketmq_console
[root@rabbitmq01 init.d]# more rocketmq_console
[root@rabbitmq01 ~]# service rocketmq_console stop
[root@rabbitmq01 ~]# service rocketmq_console start
[root@rabbitmq01 ~]# service rocketmq_console restart
[root@rabbitmq01 ~]# systemctl enable rocketmq
[root@rabbitmq01 ~]# systemctl enable rocketmq_console
[root@rabbitmq01 ~]# chkconfil --list
设置完成后开机会自启动namesrv、broker和console服务
搭建完成