RocketMQ, dashboard deployment and security settings
1. Start RocketMQ
1.1 Download RocketMQ
RocketMQ installation package download address: https://rocketmq.apache.org/download
Create a rocketmq folder under the /opt folder to store rocketmq related files
cd /opt
mkdir rocketmq
cd rocketmq/
Copy the RocketMQ download path
Take the latest version: 5.1.3 as an example, the download link is: https://dist.apache.org/repos/dist/release/rocketmq/5.1.3/rocketmq-all-5.1.3-bin-release.zip
Use wget to download directly to the current path
wget https://dist.apache.org/repos/dist/release/rocketmq/5.1.3/rocketmq-all-5.1.3-bin-release.zip
If you don't have wget, install it first
yum -y install wget
download successful
Use unzip to decompress
unzip rocketmq-all-5.1.3-bin-release.zip
If unzip is not available, install it first
yum install -y unzip zip
View Results
Modify the folder name (the folder name is too long, it looks uncomfortable)
mv rocketmq-all-5.1.3-bin-release rocketmq-5.1.3
So far, the preparation of RocketMQ related documents has been completed
1.2 Modify the configuration file
Since the default configuration of RocketMQ is relatively high, we need to adjust relevant parameters according to our own machine configuration. (If the machine configuration is relatively high, you can directly transfer to the 1.3 startup chapter)
1.2.1 Modify nameServer Jvm memory configuration
/opt/rocketmq/rocketmq-5.1.3/bin
vim runserver.sh
Modify -Xms4g -Xmx4g -Xmn2g
, three parameters
- Xms is the memory allocated when jvm starts, such as -Xms512m, which means that 512M is allocated
- Xmx is the maximum memory allocated during jvm running, such as -Xms512m, which means that the jvm process can only occupy up to 512M memory
- The size of the new generation in the Xmn heap, -Xmn256m means the size of the new generation is 256M
Here, according to your own configuration, adjust to the following parameters:
1.2.2 Modify broker parameters
vim runbroker.sh
- -Xms -Xmx has been explained above
- -XX:MaxDirectMemorySize is used to set the maximum size of direct memory.
According to the machine configuration, modify as follows:
1.2.3 Modify broker configuration
cd /opt/rocketmq/rocketmq-5.1.3/conf/
1.3 start
1.3.1 Start NameServer
# 启动NameServer
sh bin/mqnamesrv &
# 查看日志
tail -f ~/logs/rocketmqlogs/namesrv.log
The log shows: The Name Server boot success. serializeType=JSON, address 0.0.0.0:9876
The representative has started
1.3.2 Start Broker
# 在rocketmq-5.1.3目录启动Broker,使用conf/broker.conf配置文件
nohup sh bin/mqbroker -c conf/broker.conf -n localhost:9876 &
# 查看日志
tail -f ~/logs/rocketmqlogs/proxy.log
1.3.3 Test whether the startup is successful
1.3.3.1 Test message sending
export NAMESRV_ADDR=localhost:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
Successful example:
1.3.3.2 Test message reception
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
Successful example:
1.3.3.3 Java programs send messages
Note that the linux server should open the corresponding port!
Maven project imports dependencies
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId>
<version>5.1.1</version>
</dependency>
test class
public class ASimpleTest {
public static void main(String[] args) throws Exception{
// 创建一个生产者(指定一个组名)
DefaultMQProducer producer = new DefaultMQProducer("test-producer-group");
// 连接namersrv
producer.setNamesrvAddr("192.168.1.7:9876");
// 启动
producer.start();
for (int i = 0; i < 10; i++) {
Message testTopic = new Message("testTopic", "我是一个简单的消息".getBytes());
SendResult send = producer.send(testTopic);
System.out.println(send.getSendStatus());
}
producer.shutdown();
}
}
output:
1.3.4 Close NameServer and broker
# 关闭broker
sh bin/mqshutdown broker
# 关闭namesrv
sh bin/mqshutdown namesrv
1.3.5 Summary startup script
Combining the previous scripts into a unified script
to create a file
vim restart.sh
Script content
# 关闭broker
sh bin/mqshutdown broker
# 关闭namesrv
sh bin/mqshutdown namesrv
# 启动namersrv
sh bin/mqnamesrv &
# 启动broker
nohup sh bin/mqbroker -c conf/broker.conf -n localhost:9876 &
After that, just do a sh restart.sh
quick reboot
So far, the startup of RocketMQ, whether the test is started and shut down have been explained
2. Start RocketMQ Dashboard
RocketMQ Dashboard is a web interface for managing and monitoring Apache RocketMQ message queues.
2.1 Download Dashboard source code
RocketMq Dashboard download address
Download to the local or Linux environment (because I only have Maven locally, so download to the Windows environment)
2.2 Maven packaging
After decompression, enter the folder
Execute the Maven command to output the corresponding jar package
mvn clean package
2.3 Upload to Linux server
Upload target
the files under the folder rocketmq-dashboard-1.0.0.jar
to the server
2.4 Start Dashboard
Start the dashboard, specify the Dashboard port as 18001
, and the NameServer address as127.0.0.1:9876
nohup java -jar rocketmq-dashboard-1.0.0.jar --server.port=18001 --rocketmq.config.namsrvAddr=127.0.0.1:9876 > dashboard.log 2>&1 &
2.5 Access panel
At this point, the RocketMQ panel startup is complete. However, in actual use, password restrictions will be added to RocketMQ access. Next, set the password
3. Set a password
3.1 RocketMQ configuration password
3.1.1 Enable acl control
conf/broker.conf
open inaclEnable=true
vim conf/broker.conf
Append at the bottom
3.1.2 Configure account password
Reviseconf/plain_acl.yml
Restart NameServer and Broker
Re-visit the panel and found an error
3.2 Passwords in the configuration panel
3.2.1 Create a config folder in the same directory as the dashboard.jar package
3.2.2 Upload application.properties
Upload the application.properties under the project to the config folder
3.2.3 Modify application.properties
Release the note and set the corresponding account password
result:
3.2.4 Restart the dashboard
For specific operations, refer to the article: SpringBoot jar package deployment
Revisit the panel and find that it can be accessed normally
3.3 Panel open account password
At present, a password has been set for RocketMQ, but there are still problems. There is no password set for the operation panel, and the operation panel has no password set. In practical applications, it is also very dangerous. The following explains the panel setting password:
3.3.1 Enable account and password access
Reviseapplication.properties
change into:
rocketmq.config.loginRequired=true
Revisit and find that an account password is required
The account password configuration file is:users.properties
path:
illustrate:
It is known that the default administrator account is admin
, and the password is admin
.
3.3.2 Change account password
It will users.properties
be uploaded to the config directory, and the modified content is
3.3.3 Modify the default user configuration file path
Reviseapplication.properties
vim application.properties
Modify it to:
rocketmq.config.dataPath=./config
3.3.4 Restart the dashboard
After restarting, use account zhangsan
, password: 123
login successfully.
So far, the RocketMQ deployment has been completed
Reference article: RocketMQ official website quick start