RocketMQ, Dashboard deployment and security settings

1. Start RocketMQ

1.1 Download RocketMQ

RocketMQ installation package download address: https://rocketmq.apache.org/download

image-20230812211334234

Create a rocketmq folder under the /opt folder to store rocketmq related files

cd /opt
mkdir rocketmq
cd rocketmq/

Copy the RocketMQ download path

image-20230812212341436

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

image-20230813002312327

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

image-20230813152634278

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

image-20230813152742574

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

image-20230813154820305

  • 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:

image-20230813160210939

1.2.2 Modify broker parameters

vim runbroker.sh

image-20230813160509019

  • -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:

image-20230813160610504

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:

image-20230814215834502

1.3.3.2 Test message reception

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

Successful example:

image-20230815102513753

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:

image-20230814220522423

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.shquick 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

image-20230814224704507

Download to the local or Linux environment (because I only have Maven locally, so download to the Windows environment)

image-20230814224855505

2.2 Maven packaging

After decompression, enter the folder

image-20230814225009203

Execute the Maven command to output the corresponding jar package

mvn clean package

2.3 Upload to Linux server

Upload targetthe files under the folder rocketmq-dashboard-1.0.0.jarto the server

image-20230814225223551

image-20230814225308186

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

image-20230814225640327

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.confopen inaclEnable=true

vim conf/broker.conf

Append at the bottom

image-202308142305488723.1.2 Configure account password

Reviseconf/plain_acl.yml

image-20230814232003165

Restart NameServer and Broker

Re-visit the panel and found an error

image-20230814234746516

3.2 Passwords in the configuration panel

3.2.1 Create a config folder in the same directory as the dashboard.jar package

image-20230814235138344

3.2.2 Upload application.properties

Upload the application.properties under the project to the config folder

image-20230814235226178

image-20230814235638553

3.2.3 Modify application.properties

Release the note and set the corresponding account password

image-20230814235346543

result:

image-20230814235535285

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

image-20230815000509925

change into:

rocketmq.config.loginRequired=true

Revisit and find that an account password is required

image-20230815000731296

The account password configuration file is:users.properties

path:

image-20230815002036146

illustrate:

image-20230815001101361

It is known that the default administrator account is admin, and the password is admin.

3.3.2 Change account password

It will users.propertiesbe uploaded to the config directory, and the modified content is

image-20230815001413186

3.3.3 Modify the default user configuration file path

Reviseapplication.properties

vim application.properties

image-20230815002119132

Modify it to:

rocketmq.config.dataPath=./config

3.3.4 Restart the dashboard

After restarting, use account zhangsan, password: 123login successfully.

image-20230815213015366

So far, the RocketMQ deployment has been completed

Reference article: RocketMQ official website quick start

Guess you like

Origin blog.csdn.net/weixin_43811294/article/details/132307717