一、CentOS 7.9 安裝 rocketmq-4.9.2 地址: https://rocketmq.apache.org https://github.com/apache/rocketmq https://archive.apache.org/dist/rocketmq/4.9.2/rocke ...
一、CentOS 7.9 安裝 rocketmq-4.9.2
地址:
- https://rocketmq.apache.org
- https://github.com/apache/rocketmq
- https://archive.apache.org/dist/rocketmq/4.9.2/rocketmq-all-4.9.2-bin-release.zip
二、下載RocketMQ
wget https://archive.apache.org/dist/rocketmq/4.9.2/rocketmq-all-4.9.2-bin-release.zip
安裝解壓工具
yum install -y unzip zip
解壓
unzip rocketmq-all-4.9.2-bin-release.zip -d /opt/
進入文件夾
cd /opt/rocketmq-4.9.2
三、配置環境變數
將rocketmq服務加入環境變數
vim /etc/profile
export PATH=$PATH:/opt/rocketmq-4.9.2/bin
# 使配置文件生效
source /etc/profile
四、按需修改啟動記憶體
vim runserver.sh
vim runbroker.sh
vim tools.sh
五、創建目錄
創建日誌目錄
mkdir -p /opt/rocketmq-4.9.2/logs
六、啟動NameServer
cd /opt/rocketmq-4.9.2/bin
nohup sh mqnamesrv > /opt/rocketmq-4.9.2/logs/mqnamesrv.log 2>&1 &
驗證是否啟動OK:
tail -f /opt/rocketmq-4.9.2/logs/mqnamesrv.log
# 輸出
nohup: ignoring input
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
Java HotSpot(TM) 64-Bit Server VM warning: MaxNewSize (262144k) is equal to or greater than the entire heap (262144k). A new max generation size of 262080k will be used.
The Name Server boot success. serializeType=JSON
如果成功啟動,能看到類似如下的日誌
The Name Server boot success. ...
七、啟動Broker
/opt/rocketmq-4.9.2/bin
nohup sh mqbroker -n 127.0.0.1:9876 > /opt/rocketmq-4.9.2/logs/mqbroker.log 2>&1 &
驗證是否啟動OK
tail -f /opt/rocketmq-4.9.2/logs/mqbroker.log
# 輸出
nohup: ignoring input
The broker[ecs-65685, 192.168.0.98:10911] boot success. serializeType=JSON and name server is 127.0.0.1:9876
如果啟動成功,能看到類似如下的日誌:
The broker[itmuchcomdeMacBook-Pro.local, 192.168.43.197:10911] boot success. serializeType=JSON and name server is localhost:9876
八、測試
在發送/接收消息之前,需要告訴客戶名稱伺服器的位置。
RocketMQ 提供了多種方法來實現這一點。為了簡單起見,使用環境變數NAMESRV_ADDR
# 開啟兩個埠,都執行以下命令
export NAMESRV_ADDR=localhost:9876
發送消息
# Producer 埠一執行
sh /opt/rocketmq-4.9.2/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
接收消息
# Consumer 埠二執行
sh /opt/rocketmq-4.9.2/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
九、安裝RocketMQ控制台
1 編譯源碼方式
前置環境
-
64bit OS, Linux/Unix/Mac is recommended
-
64bit JDK 1.8+
-
Maven 3.2.x
2 下載源碼
https://github.com/apache/rocketmq-dashboard
git clone https://github.com/apache/rocketmq-dashboard.git
3 在啟動之前先修改下埠,預設的8080 已占用,一定要先修改埠,在進行編譯。
vim src/main/resources/application.yml
4 Maven spring-boot 方式啟動
mvn spring-boot:run
5 或者 使用Maven先build成jar包,再java -jar方式啟動
mvn clean package -Dmaven.test.skip=true
java -jar target/rocketmq-dashboard-1.0.1-SNAPSHOT.jar
訪問控制台:http://IP:8082
十、防火牆開啟埠
# 關閉防火牆
systemctl stop firewalld
# 開通埠
firewall-cmd --zone=public --add-port=8082/tcp --permanent
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --zone=public --add-port=10911/tcp --permanent
# 配置立即生效
firewall-cmd --reload
# 重啟防火牆生效
systemctl restart firewalld
雲主機需配置安全組
在入方向規則,都允許放行
-
8082:RocketMQ 控制台
-
9876:nameserver 中的埠
-
10911:broker 的埠