1. 程式人生 > 實用技巧 >騰訊訊息佇列CMQ部署與驗證

騰訊訊息佇列CMQ部署與驗證

環境

IP 備註
192.168.1.66 node1 前置機
192.168.1.110 node2
192.168.1.202 node3

架構圖

元件介紹

元件 監聽埠
access 12000/120001
pushserver 50012
nameserver 80
broker 11011/11012/11013/11014
barad 11112
ctsdb 9201
oss 80
master 9992
moni 9999
accessGW 80

CMP依賴VIP:

準備工作

3臺8*16伺服器
安裝文件: 
物料包(元件物料包和python指令碼) :https://cmq-1255613487.cos.ap-chengdu.myqcloud.com/install_cmq/CMQ-ALL.zip

安裝[192.168.1.66] 前端元件:

#安裝
#[root@node_66 ~]# ls
CMQ-1.0.2-軟體包.tar.gz

mkdir -p /opt/tmp
tar xf CMQ-1.0.2-軟體包.tar
cp -r v1.0.0/cmq_console/precomponent/*  /opt/tmp/

#安裝cmq_console元件
cd /opt/tmp/

#執行部署[填寫內網IP]
sh pre_component_install.sh 192.168.1.66 192.168.1.66

#---------------------------------------------------------------------------

#安裝 auth access 元件
#將 cmq_console/auth-access 目錄下所有檔案拷貝到 /opt/tmp 目錄下,並進入此目錄

cp -r /root/v1.0.0/cmq_console/auth-access/* /opt/tmp
sh access_auto_install.sh 192.168.1.66 192.168.1.66

#提示:
#backup script to /opt/script
#cp: cannot stat ‘./*.md’: No such file or directory   報錯忽略


#安裝cmq_backserver

cp -r /root/v1.0.0/cmq_backserver /opt/tmp
cd /opt/tmp/cmq_backserver


## 指令碼內容 vim 1.sh
#-------------------------------------------------------------------#
cat >1.sh<<eof
#!/bin/bash
ip_a=192.168.1.66 # 根據上面的部署圖修改為a、b、c三個節點的ip
ip_b=192.168.1.160
ip_c=192.168.1.202
password=123456   # 節點的登入密碼修改
coreNum=6 # 節點的核數減2
#dbhost=192.168.1.66
sed -i "s/^passwd=.*/passwd=${password}\r/" config.txt
sed -i "s/^routeProxy=.*/routeProxy=${ip_c}\r/" config.txt
sed -i "s/^access=.*/access=${ip_b} ${ip_c}\r/" config.txt
sed -i "s/^pushServer=.*/pushServer=${ip_b}\r/" config.txt
sed -i "s/^broker=.*/broker=${ip_a} ${ip_b} ${ip_c}\r/" config.txt
sed -i "s/^monitor=.*/monitor=${ip_a} ${ip_c}\r/" config.txt
sed -i "s/^master=.*/master=${ip_a} ${ip_b}\r/" config.txt
sed -i "s/^oss=.*/oss=${ip_b}\r/" config.txt
sed -i "/^coreNum=.*/d" config.txt
sed -i "/^oss=.*/a\\coreNum=${coreNum}\r" config.txt
sed -i "s/^barad=.*/barad=${ip_c}\r/" config.txt
sed -i "s/^ctsdb=.*/ctsdb=${ip_a} ${ip_b} ${ip_c}\r/" config.txt
sed -i "s/^jvmMem=.*/jvmMem=4g\r/" config.txt
sed -i "s/^indexTtl=.*/indexTtl=30\r/" config.txt
sed -i "s/^metricTtl=.*/metricTtl=7\r/" config.txt
sed -i "s/^nameserverVip=.*/nameserverVip=${ip_c}\r/" config.txt
sed -i "s/^baradIp=.*/baradIp=${ip_c}\r/" config.txt
sed -i "s/^ctsdbIp=.*/ctsdbIp=${ip_a}\r/" config.txt
sed -i "s/^dbhost=.*/dbhost=${ip_a}\r/" config.txt
eof
#-------------------------------------------------------------------#

#執行修改
sh -x 1.sh 


# 執行安裝
sh install_all.sh config.txt



#此時訪問 :http://192.168.1.66/  已經可以開啟控制檯,但是沒什麼卵用,啥都沒有,後臺都還沒裝
預設賬號: qcloudAdmin
預設密碼: qcloudAdmin

開啟web頁面 http://192.168.1.66/

問題解決:

問題1: Connect to 172.16.33.42:80 [/172.16.33.42] failed: connect timed out

解決: 進入http://[IP]/tsf-manager/action-path?rid=1

搜尋cmq,改為oss元件IP

[root@node_66 ~]# cd /opt/tmp/cmq_backserver
[root@node_66 cmq_backserver]# grep oss config.txt
#oss=172.16.66.198 172.16.67.224
oss=192.168.1.110

修改IP:

搜尋修改monitor:

確定barad IP monitor的IP需要改為barad的IP

[root@node_66 cmq_backserver]# grep barad config.txt
barad=192.168.1.202
baradIp=192.168.1.202

完成結果:

CMQ使用:

新建倉庫:
新建倉庫使用的是access節點IP grep access config.txt

http://[ip]/cmq-manager/zone

[root@node_66 simple_demo]# grep access  /opt/tmp/cmq_backserver/config.txt 
access=192.168.1.160 192.168.1.202

建立結果:

兩個主題倉庫,操作一樣,埠不變,ip用另一個access節點的ip

建立叢集:

配置結果

向 queue新增節點

新增節點首先新增前置機
192.168.1.66

向topoc新增節點

初始化推送節點

初始化推送節點使用 pushServer ip
[root@node_66 simple_demo]# grep pushServer /opt/tmp/cmq_backserver/config.txt
pushServer=192.168.1.160

埠 50012

[這個圖丟了 方法一樣的 過濾出來改為初始化節點IP接可以了]

新增接入層註冊access [也是pushserver節點IP]

新增佇列

[root@node_66 simple_demo]# grep pushServer /opt/tmp/cmq_backserver/config.txt
pushServer=192.168.1.160

[root@node_66 simple_demo]# grep access /opt/tmp/cmq_backserver/config.txt
access=192.168.1.160 192.168.1.202

新增主題:

新增完成後如圖:

新增節點後 出現版本號才算成功
新增完成後,直到 **出現版本號** 才算註冊成功,多在運營端重新整理一下會發現版本號出現,這個版本號可能需要10-30分鐘出現,基於伺服器配置

信令伺服器新增

建立佇列:

http://IP/cmq/index

進入 SDK 目錄

#先得到nameserver ip
[root@node_66 simple_demo]# grep nameserver /opt/tmp/cmq_backserver/config.txt
nameserverVip=192.168.1.202


#解壓python_sdk_private.tar.gz檔案,然後進入解壓的 sdk/simple_demo/ 目錄下,修改cmq_sample_queue.py 檔案

[root@node_66 opt]# cd /root/v1.0.0/SDK/
[root@node_66 SDK]# tar xf python_sdk_private.tar.gz
[root@node_66 simple_demo]# cd /root/v1.0.0/SDK/sdk/simple_demo


#替換為nameserver的IP 這個IP通過網頁上的信令伺服器管理中看到的 namserver ip地址
[root@node_66 simple_demo]# 
sed -i "s/^nameserver =.*/nameserver = 'http:\/\/192.168.1.202'/" /root/v1.0.0/SDK/sdk/simple_demo/cmq_sample_queue.py

# 執行以下命令替換建立的queue的名稱,這裡剛建立的是queue_test 
sed -i "s/^queue_name=.*/queue_name='queue'/" cmq_sample_queue.py

## 向佇列傳送訊息:
python ./cmq_sample_queue.py

然後通過頁面檢視傳送訊息狀態:

測試主題模式

同樣先在客戶端新建主題,新增訂閱者,然後進入控制檯
http://ip/cmq/topic?rid=1

進入 simple_demo/ 目錄下,執行以下命令修改引數,引數來源和佇列一樣

cd /root/v1.0.0/SDK/
cd /root/v1.0.0/SDK/sdk/simple_demo
#查詢
[root@node_66 simple_demo]# grep nameserver /opt/tmp/cmq_backserver/config.txt
nameserverVip=192.168.1.202
#修改
sed -i "s/^nameserver =.*/nameserver = 'http:\/\/192.168.1.202'/" /root/v1.0.0/SDK/sdk/simple_demo/cmq_sample_topic.py

[root@node_66 simple_demo]# grep 'nameserver = ' /root/v1.0.0/SDK/sdk/simple_demo/cmq_sample_topic.py
nameserver = 'http://192.168.1.202'

# 執行以下命令修改topic的名稱,這裡剛建立的是topic
vim /root/v1.0.0/SDK/sdk/simple_demo/cmq_sample_topic.py
找到:topic_name ="topic"
改為:topic_name ="topic"

[root@node_66 simple_demo]# grep queue_name /root/v1.0.0/SDK/sdk/simple_demo/cmq_sample_queue.py
queue_name='queue'
    my_queue = my_account.get_queue(queue_name)


# 執行命令向主題傳送資訊,Ctrl+C停止 python ./cmq_sample_topic.py
python ./cmq_sample_topic.py

測試:

此時去看伺服器堆積是否正常

壓力測試

# 在部署機節點安裝壓測工具 
yum install httpd-tools -y

# 進入simple_demo目錄下 
cd /root/v1.0.0/SDK/sdk/simple_demo


# 先修改sendmsg.txt的queueName和appid 
echo 'clientRequestId=1231231231&Nonce=37&Timestamp=1563198200&msgBody=my_message+is+1563198200&uin=0&Action=SendMessage&SignatureMethod=HmacSHA1&appId=1&delaySeconds=0&queueName=queue&RequestClient=SDK_Python_1.3' >sendmsg.txt

其中queueName=test 就是佇列名稱:queue

所以需要改為


# 再修改batchsendmsg.txt的queueName和appid 
# 執行壓測,nameserver-ip進行替換 ,命令不能執行請先安裝工具: yum install -y httpd-tools
# 壓測時應該選擇 barad 的IP 進行壓測,grep barad /opt/tmp/cmq_backserver/config.txt
ab -k -n 500000 -c 500 -p sendmsg.txt -T application/json  "http://192.168.1.202/v2/index.php"



appid查詢:
http://192.168.1.66/cmq-manager/queue?rid=1&userAppId=1

appId=1
Name=queue

清空佇列:

解除安裝ACCESS

######################################################
#!/bin/sh
# Host Login Info
user=`sed '/^user=/!d;s/.*=//' $1 | sed 's/\r//g'`
passwd=`sed '/^passwd=/!d;s/.*=//' $1 | sed 's/\r//g'`
sshPort=`sed '/^sshPort=/!d;s/.*=//' $1 |sed 's/\r//g'`

# DB Info
dbhost=`sed '/^dbhost=/!d;s/.*=//' $1 | sed 's/\r//g'`
dbport=`sed '/^dbport=/!d;s/.*=//' $1 | sed 's/\r//g'`
dbuser=`sed '/^dbuser=/!d;s/.*=//' $1 | sed 's/\r//g'`
dbpasswd=`sed '/^dbpasswd=/!d;s/.*=//' $1 | sed 's/\r//g'`

# Component IP List
cmq_nameserver=`sed '/^routeProxy=/!d;s/.*=//' $1 | sed 's/\r//g'`
cmq_access=`sed '/^access=/!d;s/.*=//' $1 | sed 's/\r//g'`
cmq_moni=`sed '/^monitor=/!d;s/.*=//' $1 | sed 's/\r//g'`
#cmq_moni2=`sed '/^monitor2=/!d;s/.*=//' $1 | sed 's/\r//g'`
cmq_master=`sed '/^master=/!d;s/.*=//' $1 | sed 's/\r//g'`
#cmq_master2=`sed '/^master2=/!d;s/.*=//' $1 | sed 's/\r//g'`
cmq_oss=`sed '/^oss=/!d;s/.*=//' $1 | sed 's/\r//g'`
cmq_publisher=`sed '/^pushServer=/!d;s/.*=//' $1 | sed 's/\r//g'`
cmq_broker=`sed '/^broker=/!d;s/.*=//' $1 | sed 's/\r//g'`



# Barad Info
barad=`sed '/^barad=/!d;s/.*=//' $1 | sed 's/\r//g'`
ctsdb=`sed '/^ctsdb=/!d;s/.*=//' $1 | sed 's/\r//g'`
jvmMem=`sed '/^jvmMem=/!d;s/.*=//' $1 | sed 's/\r//g'`
indexTtl=`sed '/^indexTtl=/!d;s/.*=//' $1 | sed 's/\r//g'`
metricTtl=`sed '/^metricTtl=/!d;s/.*=//' $1 | sed 's/\r//g'`

yum=$barad" "$ctsdb

baradList=${barad// /,}
ctsdbList=${ctsdb// /,}

# Some Vip
nameserverVip=`sed '/^nameserverVip=/!d;s/.*=//' $1 | sed 's/\r//g'`
baradIp=`sed '/^baradIp=/!d;s/.*=//' $1 | sed 's/\r//g'`
ctsdbIp=`sed '/^ctsdbIp=/!d;s/.*=//' $1 | sed 's/\r//g'`
ctsdbVport=`sed '/^ctsdbVport=/!d;s/.*=//' $1 | sed 's/\r//g'`

# Directory Of Component
targetDir=`sed '/^targetDir=/!d;s/.*=//' $1 | sed 's/\r//g'`
packageTmpDir='/opt/cmqTmp/'
packageDir=`pwd`'/package'

for moduleName in cmq_oss cmq_moni cmq_master cmq_broker cmq_access cmq_nameserver cmq_publisher yum barad ctsdb;
#for moduleName in cmq_access; 
#for moduleName in barad; 
#for moduleName in cmq_publisher; 
#for moduleName in cmq_moni; 
#for moduleName in ctsdb; 
#for moduleName in cmq_master; 
#for moduleName in cmq_nameserver; 
#for moduleName in cmq_oss; 
#for moduleName in cmq_broker; 
do
iplist=`eval echo '$'"$moduleName"`
for host in $iplist;
do
./onlineUninstall.sh $host $user $passwd $packageDir $packageTmpDir $targetDir$moduleName $moduleName $sshPort $dbhost $dbport $dbuser $dbpasswd $cmq_moni $cmq_master $baradIp $nameserverVip $jvmMem $indexTtl $metricTtl $baradList $ctsdbList $ctsdbIp $ctsdbVport
done
done
######################################################

註釋: for moduleName in cmq_oss cmq_moni cmq_master cmq_broker cmq_access cmq_nameserver cmq_publisher yum barad ctsdb; 行
取消註釋: #for moduleName in cmq_access; 行 改為 for moduleName in cmq_access; 

修改結果:
#for moduleName in cmq_oss cmq_moni cmq_master cmq_broker cmq_access cmq_nameserver cmq_publisher yum barad ctsdb; 
for moduleName in cmq_access;



#執行解除安裝操作:
sh uninstall_all.sh config.txt

錯誤問題重現:

#解除安裝了一個元件然後檢視日誌和執行結果
cd /root/v1.0.0/SDK/sdk/simple_demo
python ./cmq_sample_topic.py

進入日誌/data/cmq_nameserver/log

192.168.1.202伺服器進入目錄監控日誌:

cd /data/cmq_access/log/
[root@node_202 log]# tailf  /data/cmq_nameserver/log/*
2021/01/09 17:28:29 requestId: 8649737934421390396, clientIP: 192.168.1.66, scheme: http, arg: clientRequestId: 1231231231; appId:1; Action: PublishMessage; topicName: topic;
2021/01/09 17:28:29 ResponseVipVport, url:http://192.168.1.202:12001, req.host: 192.168.1.202
2021/01/09 17:28:29 ResponseVipVport, clinent_ip: 192.168.1.66, ipHash: 3232279594, proxy_idx: 194
2021/01/09 17:28:29 ResponseVipVport, addr: http://192.168.1.202:12001 has found in vipProxyArr
2021/01/09 17:28:29 $$$, ResponseVipVport, Dial error: dial tcp 192.168.1.202:12001: connect: connection refused
2021/01/09 17:28:29 http: proxy error: dial tcp 192.168.1.202:12001: connect: connection refused
2021/01/09 17:28:29 ResponseVipVport finish request, requestId: 8649737934421390396

恢復元件:

註釋:
# ./cmq_db_init.sh $dbhost $dbport $dbuser $dbpasswd
# for moduleName in cmq_oss cmq_moni cmq_master cmq_broker cmq_access cmq_nameserver cmq_publisher yum barad ctsdb; 
第一行註釋是為了不重新初始化資料庫,避免資料丟失
第二行不重灌所有元件

啟用:
for moduleName in cmq_access;

#執行安裝元件:
sh install_all.sh config.txt



驗證傳送訊息:
cd /root/v1.0.0/SDK/sdk/simple_demo
python ./cmq_sample_topic.py

驗證恢復後的元件是否正常