文章目录
NSQ简介
NSQ是由四个重要组件构成:
- nsqd:一个负责接收、排队、转发消息到客户端的守护进程
- nsqlookupd:管理拓扑信息并提供最终一致性的发现服务的守护进程
- nsqadmin:一套Web用户界面,可实时查看集群的统计数据和执行各种各样的管理任务
- utilities:常见基础功能、数据流处理工具,如nsq_stat、nsq_tail、nsq_to_file、nsq_to_http、nsq_to_nsq、to_nsq
NSQ搭建
下载和解压安装包,再安装包里bin文件下的nsq*文件复制到/bin下,方便部署
$ apt update
$ mkdir nsq
$ cd nsq
$ wget https://github.com/nsqio/nsq/releases/download/v1.2.1/nsq-1.2.1.linux-amd64.go1.16.6.tar.gz
$ tar -xvf nsq-1.2.1.linux-amd64.go1.16.6.tar.gz
$ cd nsq-1.2.1.linux-amd64.go1.16.6/bin/
$ cp nsq* /bin
$ mkdir -p /var/lib/nsqadmin
$ mkdir -p /var/lib/nsqd/data
$ mkdir -p /var/lib/nsqlookupd
单节点搭建
服务器IP:10.0.24.248
#创建systemd关于nsqlookupd的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqlookupd.service
[Unit]
Description=NSQLookupD
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqlookupd
ExecStart=/usr/bin/nsqlookupd
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqlookupd && systemctl restart nsqlookupd
#创建systemd关于节点的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqd.service
[Unit]
Description=NSQD
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqd
ExecStart=/usr/bin/nsqd --data-path /var/lib/nsqd/data -broadcast-address 10.0.24.248 -lookupd-tcp-address 10.0.24.248:4160
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqd && systemctl restart nsqd
#创建systemd关于Web界面的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqadmin.service
[Unit]
Description=NSQDADMIN
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqadmin
ExecStart=/usr/bin/nsqadmin -lookupd-http-address 10.0.24.248:4161
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqadmin && systemctl restart nsqadmin
集群搭建
在三台服务器(10.0.24.249,10.0.24.250,10.0.24.251)下分别执行以下脚本。
以10.0.24.249为主节点,搭建WEB管理界面和节点服务nsqlookupd,其他节点lookupd-tcp-address地址指向的lookupd服务器IP地址
10.0.24.249服务器上执行以下脚本
#创建systemd关于nsqlookupd的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqlookupd.service
[Unit]
Description=NSQLookupD
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqlookupd
ExecStart=/usr/bin/nsqlookupd
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqlookupd && systemctl restart nsqlookupd
#创建systemd关于节点的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqd.service
[Unit]
Description=NSQD
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqd
ExecStart=/usr/bin/nsqd --data-path /var/lib/nsqd/data -broadcast-address 10.0.24.249 -lookupd-tcp-address 10.0.24.249:4160
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqd && systemctl restart nsqd
#创建systemd关于Web界面的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqadmin.service
[Unit]
Description=NSQDADMIN
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqadmin
ExecStart=/usr/bin/nsqadmin -lookupd-http-address 10.0.24.249:4161
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqadmin && systemctl restart nsqadmin
10.0.24.250上执行以下脚本
#创建systemd关于节点的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqd.service
[Unit]
Description=NSQD
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqd
ExecStart=/usr/bin/nsqd --data-path /var/lib/nsqd/data -broadcast-address 10.0.24.250 -lookupd-tcp-address 10.0.24.249:4160
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqd && systemctl restart nsqd
10.0.24.251上执行以下脚本
#创建systemd关于节点的配置文件
$ cat <<EOF | sudo tee /etc/systemd/system/nsqd.service
[Unit]
Description=NSQD
After=network.target
[Service]
WorkingDirectory=/var/lib/nsqd
ExecStart=/usr/bin/nsqd --data-path /var/lib/nsqd/data -broadcast-address 10.0.24.251 -lookupd-tcp-address 10.0.24.249:4160
ExecReload=/bin/kill -HUP $MAINPID
Type=simple
KillMode=process
Restart=on-failure
RestartSec=10s
User=root
[Install]
WantedBy=multi-user.target
EOF
#启动nsq
$ systemctl daemon-reload && systemctl enable nsqd && systemctl restart nsqd
参考链接
Linux/Windows下快速搭建和配置NSQ
NSQ go实现的,部署简单