Administrator
发布于 2022-01-10 / 465 阅读
0
0

Centos7-安装nsq消息队列

Centos7-安装nsq

1、安装Go运行环境

可查看:https://www.itcdz.cn/archives/centos7-安装go语言环境

2、下载nsq安装包

nsq-1.2.1.linux-amd64.go1.16.6.tar
二进制下载路径:https://github.com/nsqio/nsq/releases
参考文档:https://nsq.io/overview/quick_start.html
#将下载好的安装包上传到系统目录

3、安装

#解压到系统目录
tar -zxvf nsq-1.2.1.linux-amd64.go1.16.6.tar -C /usr/local/

4、启动

#启动nsqlookupd (nohup 后台启动)
nohup ./nsqlookupd > /dev/null 2>&1 &

#启动nsqd (nohup 后台启动)
nohup ./nsqd --lookupd-tcp-address=127.0.0.1:4160 > /dev/null 2>&1 &

#启动nsqadmin (nohup 后台启动)
nohup ./nsqadmin --lookupd-http-address=127.0.0.1:4161 > /dev/null 2>&1 &

#启动日志查看:bin目录会自动生成nohup日志
tail -f nohup.out

#结合一起执行
nohup ./nsqlookupd & nohup ./nsqd --lookupd-tcp-address=127.0.0.1:4160 & nohup ./nsqadmin --lookupd-http-address=127.0.0.1:4161 & tail -f nohup.out

5、消息测试

#启动nsq_to_file,将消息写入/tmp文件的日志文件,文件名默认由主题topic+主机+日期时间戳组成
nohup ./nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161

#使用curl命令,发布一条消息,返回OK
curl -d 'hello world 1' 'http://127.0.0.1:4151/pub?topic=test'

浏览器方问web界面:http://192.168.2.100:4171/,

#发布更多消息到:nsqd
curl -d 'hello world 2' 'http://127.0.0.1:4151/pub?topic=test'
curl -d 'hello world 3' 'http://127.0.0.1:4151/pub?topic=test'

6、nsq相关端口

1.外网访问必须开放4150(TCP Producer),4151(HTTP Producer),4160,4161,4171(管理页面)四个端口

2.nsqlookupd 监听两个端口:
  4160 TCP 用于接收nsqd的广播,记录nsqd的地址以及监听TCP/HTTP端口等。
  4161 HTTP 用于接收客户端发送的管理和发现操作请求(增删话题,节点等管理查看性操作等)。当Consumer进行连接时,返回对应存在Topic的nsqd列表。

3.nsqd监听两个端口: 
  4151 HTTP Producer使用HTTP协议的curl等工具生产数据;Consumer使用HTTP协议的curl等工具消费数据;
  4150 TCP Producer使用TCP协议的nsq-j等工具生产数据;Consumer使用TCP协议的nsq-j等工具消费数据;

4.nsqadmin监听一个端口 
  4171 HTTP 用于管理页面
  使用地址http://xxx.xxx.xxx.xxx:4171打开管理页面

7、停止nsq

#nsq_shutdown.sh
#服务停止
ps -ef | grep nsq| grep -v grep | awk '{print $2}' | xargs kill -2

参考:https://www.cnblogs.com/chevin/p/11054860.html
https://www.cnblogs.com/linkstar/p/10341685.html


评论