1. 程式人生 > >mq(activemq kafka rocketmq)安裝配置筆記

mq(activemq kafka rocketmq)安裝配置筆記

ActiveMq

下載

http://activemq.apache.org/download.html 這裡下載最快
window直接用網頁下載,
linux 下 獲取真實路徑後 用wget 命令 下載
wget http://mirrors.hust.edu.cn/apache//activemq/5.15.7/apache-activemq-5.15.7-bin.tar.gz

安裝

解壓
tar -zxvf apache-activemq-5.15.7-bin.tar.gz

cd [activemq_install_dir]/bin
chmod 755 activemq

配置

maven 版本必須與伺服器版本一致

<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>activemq-all</artifactId>
  <version>5.15.7</version>
</dependency>

支援jdk8 以上版本

啟動

cd [activemq_install_dir]
bin/activemq start
OR
bin/activemq start > /tmp/smlog 2>&1 &;

  • 注: /tmp/smlog 可以改為其他檔名
    啟動以後不要關閉shell 視窗

除錯

  • window
    netstat -an|find "61616"
  • linux
    netstat -an|grep 61616
  • 訪問
    http://192.168.X.X:8161/admin/
    使用者名稱: admin ; 密碼 :admin
    注: 可以改( 在 conf/jetty-realm.properties 檔案中)
    更多資訊看 docs/WebConsole-README.txt

關閉

cd [activemq_install_dir]

  • window
    bin/activemq stop
  • linux
    ps -ef|grep activemq
    kill [PID]
    注: where [PID] is the process id of the ActiveMQ process.

參考

Kafka

下載

安裝

tar -xzf kafka_2.11-2.0.0.tgz
cd kafka_2.11-2.0.0

啟動與除錯 單個節點

先啟動

bin/zookeeper-server-start.sh config/zookeeper.properties

後啟動單個服務節點

bin/kafka-server-start.sh config/server.properties

建立topic

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic

檢視topic

bin/kafka-topics.sh --list --zookeeper localhost:2181
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test

傳送

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
輸入傳送的訊息
^C

接收

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
顯示接收的訊息
^C

啟動與除錯 新增兩個broker服務節點

先備份

cp config/server.properties config/server-1.properties
cp config/server.properties config/server-2.properties
vim config/server-1.properties:
    broker.id=1
    listeners=PLAINTEXT://:9093
    log.dirs=/tmp/kafka-logs-1

vim config/server-2.properties:

   broker.id=2
   listeners=PLAINTEXT://:9094
   log.dirs=/tmp/kafka-logs-2

bin/kafka-server-start.sh config/server-1.properties &
bin/kafka-server-start.sh config/server-2.properties &

檢視topic
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic

傳送
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic

輸入傳送的訊息
my test message 1
my test message 2
^C

接收
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic

顯示接收的訊息
my test message 1
my test message 2
^C

關閉

linux

ps aux | grep server-1.properties
kill -9 7564

window:

wmic process where “caption = ‘java.exe’ and commandline like ‘%server-1.properties%’” get processid
ProcessId
6016
taskkill /pid 6016 /f

參考

RocketMq

下載

下載rocketmq
wget http://mirrors.shu.edu.cn/apache/rocketmq/4.3.1/rocketmq-all-4.3.1-bin-release.zip

安裝

原始碼安裝

unzip rocketmq-all-4.3.2-source-release.zip
cd rocketmq-all-4.3.2/
mvn -Prelease-all -DskipTests clean install -U
cd distribution/target/apache-rocketmq

二進位制檔案安裝

解壓到當前目錄
unzip rocketmq-all-4.3.1-bin-release.zip
轉移到指定目錄
mv -d rocketmq rocketmq-all-4.3.1-bin-release
進入指定目錄
cd rocketmq

配置

`export NAMESRV_ADDR=linuxprobe.com:9876`

vim runserver.sh改小記憶體
vim runbroker.sh 改小記憶體

啟動

啟動名稱空間服務

> nohup sh bin/mqnamesrv &
> tail -f ~/logs/rocketmqlogs/namesrv.log
  The Name Server boot success...

啟動broker服務

> nohup sh bin/mqbroker -n localhost:9876 &
> tail -f ~/logs/rocketmqlogs/broker.log 

or

nohup sh bin/mqnamesrv >> namesrv.log 2>&1 &
nohup sh bin/mqbroker autoCreateTopicEnable=true >> broker.log 2>&1 &
nohup sh bin/mqbroker -n linuxprobe.com:9876 &

除錯

檢視日誌
tail -f ~/logs/rocketmqlogs/namesrv.log
tail -f ~/logs/rocketmqlogs/broker.log
傳送

export NAMESRV_ADDR=localhost:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= …
接收
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt…

關閉

sh bin/mqshutdown broker
The mqbroker(36695) is running…
Send shutdown request to mqbroker(36695) OK

sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running…
Send shutdown request to mqnamesrv(36664) OK

參考