initial commit
This commit is contained in:
123
README.md
Normal file
123
README.md
Normal file
@@ -0,0 +1,123 @@
|
||||
# NSQ 服务安装指南
|
||||
|
||||
本目录包含了为NSQ服务创建systemd服务文件的配置,用于设置开机自启动。
|
||||
|
||||
## 文件说明
|
||||
|
||||
- `nsqlookupd.service` - NSQ查找服务配置
|
||||
- `nsqd.service` - NSQ守护进程服务配置
|
||||
- `nsqadmin.service` - NSQ管理界面服务配置
|
||||
- `install-services.sh` - 自动安装脚本
|
||||
|
||||
## 安装步骤
|
||||
|
||||
### 方法1:使用自动安装脚本(推荐)
|
||||
|
||||
1. 确保二进制文件已放置在 `/usr/share/nsq/` 目录下
|
||||
2. 给脚本添加执行权限:
|
||||
```bash
|
||||
chmod +x install-services.sh
|
||||
```
|
||||
3. 以root权限运行安装脚本:
|
||||
```bash
|
||||
sudo ./install-services.sh
|
||||
```
|
||||
|
||||
### 方法2:手动安装
|
||||
|
||||
1. 创建nsq用户(如果不存在):
|
||||
```bash
|
||||
sudo useradd -r -s /bin/false -d /var/lib/nsq nsq
|
||||
```
|
||||
|
||||
2. 创建必要的目录:
|
||||
```bash
|
||||
sudo mkdir -p /var/lib/nsq /var/log/nsq
|
||||
sudo chown -R nsq:nsq /var/lib/nsq /var/log/nsq
|
||||
```
|
||||
|
||||
3. 复制服务文件到systemd目录:
|
||||
```bash
|
||||
sudo cp *.service /etc/systemd/system/
|
||||
```
|
||||
|
||||
4. 重新加载systemd配置:
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
```
|
||||
|
||||
5. 启用服务开机自启动:
|
||||
```bash
|
||||
sudo systemctl enable nsqlookupd.service
|
||||
sudo systemctl enable nsqd.service
|
||||
sudo systemctl enable nsqadmin.service
|
||||
```
|
||||
|
||||
## 服务管理
|
||||
|
||||
### 启动服务
|
||||
```bash
|
||||
sudo systemctl start nsqlookupd nsqd nsqadmin
|
||||
```
|
||||
|
||||
### 停止服务
|
||||
```bash
|
||||
sudo systemctl stop nsqlookupd nsqd nsqadmin
|
||||
```
|
||||
|
||||
### 重启服务
|
||||
```bash
|
||||
sudo systemctl restart nsqlookupd nsqd nsqadmin
|
||||
```
|
||||
|
||||
### 查看服务状态
|
||||
```bash
|
||||
sudo systemctl status nsqlookupd nsqd nsqadmin
|
||||
```
|
||||
|
||||
### 查看服务日志
|
||||
```bash
|
||||
# 查看nsqlookupd日志
|
||||
sudo journalctl -u nsqlookupd -f
|
||||
|
||||
# 查看nsqd日志
|
||||
sudo journalctl -u nsqd -f
|
||||
|
||||
# 查看nsqadmin日志
|
||||
sudo journalctl -u nsqadmin -f
|
||||
```
|
||||
|
||||
## 服务配置说明
|
||||
|
||||
### nsqlookupd.service
|
||||
- 默认端口:TCP 4160, HTTP 4161
|
||||
- 依赖:网络服务
|
||||
- 自动重启:是
|
||||
|
||||
### nsqd.service
|
||||
- 默认端口:TCP 4150, HTTP 4151
|
||||
- 依赖:nsqlookupd服务
|
||||
- 自动重启:是
|
||||
- 启动参数:`--lookupd-tcp-address=127.0.0.1:4160`
|
||||
|
||||
### nsqadmin.service
|
||||
- 默认端口:HTTP 4171
|
||||
- 依赖:nsqlookupd服务
|
||||
- 自动重启:是
|
||||
- 启动参数:`--lookupd-http-address=127.0.0.1:4161`
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保二进制文件路径正确(`/usr/share/nsq/`)
|
||||
2. 服务将以`nsq`用户身份运行,确保该用户有适当的权限
|
||||
3. 服务启动顺序:nsqlookupd → nsqd → nsqadmin
|
||||
4. 所有服务都配置了自动重启功能
|
||||
5. 日志输出到systemd journal
|
||||
|
||||
## 故障排除
|
||||
|
||||
如果服务启动失败,请检查:
|
||||
1. 二进制文件是否存在且有执行权限
|
||||
2. 端口是否被占用
|
||||
3. 用户权限是否正确
|
||||
4. 查看服务日志:`journalctl -u 服务名 -f`
|
BIN
bin/nsq_stat
Executable file
BIN
bin/nsq_stat
Executable file
Binary file not shown.
BIN
bin/nsq_tail
Executable file
BIN
bin/nsq_tail
Executable file
Binary file not shown.
BIN
bin/nsq_to_file
Executable file
BIN
bin/nsq_to_file
Executable file
Binary file not shown.
BIN
bin/nsq_to_http
Executable file
BIN
bin/nsq_to_http
Executable file
Binary file not shown.
BIN
bin/nsq_to_nsq
Executable file
BIN
bin/nsq_to_nsq
Executable file
Binary file not shown.
BIN
bin/nsqadmin
Executable file
BIN
bin/nsqadmin
Executable file
Binary file not shown.
1
bin/nsqd.dat
Normal file
1
bin/nsqd.dat
Normal file
@@ -0,0 +1 @@
|
||||
{"topics":[{"name":"core.device.online","paused":false,"channels":[{"name":"default","paused":false},{"name":"DeviceManagement","paused":false}]},{"name":"core.device.offline","paused":false,"channels":[{"name":"DeviceManagement","paused":false}]},{"name":"core.device.alarm","paused":false,"channels":[{"name":"default","paused":false},{"name":"DeviceManagement","paused":false}]}],"version":"1.3.0"}
|
BIN
bin/nsqlookupd
Executable file
BIN
bin/nsqlookupd
Executable file
Binary file not shown.
BIN
bin/to_nsq
Executable file
BIN
bin/to_nsq
Executable file
Binary file not shown.
46
install-services.sh
Normal file
46
install-services.sh
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NSQ服务安装脚本
|
||||
# 此脚本将安装NSQ服务并设置开机自启动
|
||||
|
||||
echo "开始安装NSQ服务..."
|
||||
|
||||
# 检查是否为root用户
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "请使用root权限运行此脚本"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# 拷贝二进制文件
|
||||
echo "拷贝二进制文件..."
|
||||
# 创建nsq目录
|
||||
if [ ! -d "/usr/share/nsq" ]; then
|
||||
echo "创建nsq目录..."
|
||||
mkdir -p /usr/share/nsq
|
||||
fi
|
||||
cp ./bin/nsqlookupd /usr/share/nsq/
|
||||
cp ./bin/nsqd /usr/share/nsq/
|
||||
cp ./bin/nsqadmin /usr/share/nsq/
|
||||
|
||||
|
||||
# 复制服务文件到systemd目录
|
||||
echo "安装服务文件..."
|
||||
cp nsqlookupd.service /etc/systemd/system/
|
||||
cp nsqd.service /etc/systemd/system/
|
||||
cp nsqadmin.service /etc/systemd/system/
|
||||
|
||||
|
||||
# 重新加载systemd配置
|
||||
echo "重新加载systemd配置..."
|
||||
systemctl daemon-reload
|
||||
|
||||
# 启用服务开机自启动
|
||||
echo "启用服务开机自启动..."
|
||||
systemctl enable nsqlookupd.service
|
||||
systemctl enable nsqd.service
|
||||
systemctl enable nsqadmin.service
|
||||
|
||||
|
||||
echo "启动服务..."
|
||||
systemctl restart nsqlookupd nsqd nsqadmin
|
14
nsqadmin.service
Normal file
14
nsqadmin.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=NSQ Admin Web Interface
|
||||
After=network.target nsqlookupd.service
|
||||
Requires=nsqlookupd.service
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
WorkingDirectory=/usr/share/nsq
|
||||
ExecStart=/usr/share/nsq/nsqadmin --lookupd-http-address=127.0.0.1:4161
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
14
nsqd.service
Normal file
14
nsqd.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=NSQ Daemon
|
||||
After=network.target nsqlookupd.service
|
||||
Requires=nsqlookupd.service
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
WorkingDirectory=/usr/share/nsq
|
||||
ExecStart=/usr/share/nsq/nsqd --lookupd-tcp-address=127.0.0.1:4160
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
13
nsqlookupd.service
Normal file
13
nsqlookupd.service
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=NSQ Lookup Daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
WorkingDirectory=/usr/share/nsq
|
||||
ExecStart=/usr/share/nsq/nsqlookupd
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Reference in New Issue
Block a user