preface

  • The prerequisite to learning a component is to install it
  • RocketMQ has several deployment modes: single-machine deployment, multi-master deployment, multi-master multi-slave deployment, and Dleger deployment
  • Because this is learning, only single-machine deployment is recommended
  • There are two single-machine deployment modes
    • Local download and run (recommended for first installation)
    • Docker container deployment (recommended for the second time and later)

1. Local installation

1. Prepare

  • Install the JDK 8 +
  • Install Maven 3.2 X +
  • Install git

2. Install Rocket MQ

1. Download and decompress

# download$wget HTTP: / / https://archive.apache.org/dist/rocketmq/4.7.0/rocketmq-all-4.7.0-bin-release.zip# decompression$unzip rocketmq - all - 4.7.1 - source - the zipCopy the code

2. Compile RocketMQ source code using Maven

$ cdRocketmq -all-4.7.1-source-release $mvn-prelease - all-dskiptests clean install -uCopy the code

3. Modify the file capacity

Ps: Since the default configuration for broker startup is 8GB 8GB 4g, if your server memory can meet the above requirements, there is no need to modify the following files: ROCketMQ after 4.7 the following files are in distribution.

# Modify the bin/runserver.sh file
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:PermSize=128m -XX:MaxPermSize=320m"
 
Change the bin/runbroker.sh file
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
 
# Modify the tools.sh file
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:PermSize=128m -XX:MaxPermSize=128m" 
Copy the code

3. Start rocketmq

1. Start the nameserver

Start redirection log file print, run in the background
mkdir logs
nohup bin/mqnamesrv 1>logs/ng.log 2>logs/ng-err.log &

The JPS command is used to check whether the startup is successful
$jps

29516 NamesrvStartup  # indicates that NamesRV started successfully
5982 Jps

Copy the code

2. Start the broker

# Modify the broker. Conf node
vim conf/broker.conf
# addNamesrvAddr = Public IP address :9876 brokerIP1 = Public IP addressStart redirection log, confirm port, start automatic node creation, set configuration to specified file, background runNohup sh bin/mqbroker 1>/root/utils/rocketmq-all-4.7.0-bin-release/logs/mq.log -n 127.0.0.1:9876 autoCreateTopicEnable=true- c/root/utils/rocketmq - all - 4.7.0 - bin - release/conf/broker. Conf# the JPS view
$jps
8448 Jps
29515 BrokerStartup # successful startup
29516 NamesrvStartup
Copy the code

4. The simulation

1. Simulate the producer

$exportNAMESRV_ADDR = 127.0.0.1:9876$sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer 
Copy the code

2. Simulated consumers

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
Copy the code

5. Close the

mqshutdown namesrv       Close # nameserver
mqshutdown broker          # close the broker
Copy the code

6. Connect to RocketMQ through the console

1. Download

git clone https://github.com/apache/rocketmq-externals.git
Copy the code

2. The configuration

cd rocketmq-exxternals/rocketmq-console/
# Modify the Maven project resource file
$vimSRC/main/resource/application. The properties for server port = 9877 rocketmq. Config. NamesrvAddr = 127.0.0.1:9876Copy the code

3. Pack and run

# check the address
$pwd
~ /rocketmq-exxternals/rocketmq-console/

$mvn clean package -Dmaven.test.skip=true
$java- jar target/rocketmq - the console - ng - 2.0.0. Jar > logs/console log &Copy the code

Possible problems

1. If nohup is blank, exit

The maximum capacity, such as Xms, of sh in bin is not configured

2.closeChannel: close the connection to remote address[] result: true

The reference address of port 10909 is not opened

2. Docker container deployment

The project address

1. Download

# Drop down items
git clone https://github.com/apache/rocketmq-docker.git

# enter
$cd rocketmq-externals-master/rocketmq-docker/image-build
$shThe build - image. Sh RMQ - 4.7.1$cd.$shStage. Sh 4.7.1Copy the code

2. Prepare the configuration file

1. Prepare the broker.conf file

vim broker.conf brokerClusterName = DefaultCluster brokerName = broker-a brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH namesrvAddr = Public IP :9876 brokerIP1 = public IPCopy the code

2. Prepare the docker-comemage. yml file

vim docker-rocketmq-compose.yml
 
version: '3.5'Services: rmqnamesrv: image: apacherocketmq/rocketmq: 4.7.1 container_name: rmqnamesrv ports: - 9876:9876 volumes: - /opt/logs:/opt/logs - /opt/store:/opt/storecommand: sh mqnamesrv networks: RMQ: aliases: - rmqnamesrv rmqbroker: image: apacherocketmq/rocketmq: 4.7.1 container_name: rmqbroker ports: - 10909:10909 - 10911:10911 volumes: - / opt/logs: / opt/logs/opt/store: / opt/store - / home/data/rocketmq/broker. Conf: / opt/rocketmq 4.7.1 / conf/broker. Conf environment: TZ: Asia/Shanghai NAMESRV_ADDR:"rmqnamesrv:9876"
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms512m -Xmx512m -Xmn512m"
    command: sh mqbroker rmqnamesrv:9876 -c broker.conf  autoCreateTopicEnable=true
    depends_on:
      - rmqnamesrv
    networks:
      rmq:
        aliases:
          - rmqbroker
  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      - 9877:8080
    environment:
        JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=true"
    depends_on:
      - rmqnamesrv
    networks:
      rmq:
        aliases:
          - rmqconsole
networks:
  rmq:
    name: rmq
    driver: bridge
Copy the code

3. The installation

docker-compose -f docker-rocketmq-compose.yml up -d
Copy the code

4. Check the

  • Check whether the IP address 9877 is set successfully

Refer to the article

Docker installation and deployment rocketMQ single machine RocketMQ learning installation and deployment and basic explanation

conclusion

  • Thanks for seeing it to the end