在CentOS上搭建消息推送服务有多种选择,以下提供两种常见的消息推送服务搭建方法:使用 Gotify 以及使用 Rocket.Chat。
使用 Gotify 搭建消息推送服务
-
下载并解压 Gotify
在开源项目的版本里下载最新的安装文件。这里选取的是Version 2.4.0版本。
wget https://github.com/gotify/server/releases/download/v2.4.0/gotify-linux-amd64.zip unzip gotify-linux-amd64.zip chmod +x gotify-linux-amd64
-
运行 Gotify 服务
运行 Gotify 服务,默认会占用 80 端口。
./gotify-linux-amd64
-
配置 Gotify
下载
config.yml
文件。wget -O config.yml https://raw.githubusercontent.com/gotify/server/master/config.example.yml
配置文件默认可以配置 http 端口,也可以配置 https 端口,一般前面都是有 nginx 服务,所以这里只需要配置 http 端口即可。
port: 9080 database: dialect: sqlite3 connection: data/gotify.db
-
配置 Nginx 代理服务
编辑 Nginx 配置文件,添加以下内容:
upstream gotify { set the port to the one you are using in gotifyserver 127.0.0.1:9080; } server { listen 18080; # Here goes your domain / subdomain server_name push.example.com; location / { # We set up the reverse proxy proxy_pass http://gotify; proxy_http_version 1.1; # Ensuring it can use websockets proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto http; proxy_redirect http:// $scheme://; # The proxy must preserve the host because gotify verifies the host with the origin proxy_set_header Host $http_host; # These sets the timeout so that the websocket can stay alive proxy_connect_timeout 1m; proxy_send_timeout 1m; proxy_read_timeout 1m; } }
-
重启 Nginx 服务
sudo systemctl restart nginx
-
访问网页版进行配置
配置的服务地址端口是 80,那么访问
https://xx.com:18080
地址进入登录界面,默认的用户名密码是admin/admin
。需要点APPS——CREATE APPLICATION
新建应用,获得令牌 Token。创建后拿到该应用的 token。
使用 Rocket.Chat 搭建消息推送服务
-
准备工作
- 系统要求:CentOS 7 或更高版本。至少 1GB 的 RAM(建议 2GB 以上)。一个指向服务器 IP 地址的域名(例如
linuxidc.com
)。Nginx 已安装并配置 SSL 证书(推荐使用 Let’s Encrypt 免费证书)。 - 开放端口:确保服务器防火墙开放 3000 端口,以便外部访问 Rocket.Chat 服务器。
- 系统要求:CentOS 7 或更高版本。至少 1GB 的 RAM(建议 2GB 以上)。一个指向服务器 IP 地址的域名(例如
-
安装必要软件包
更新系统并安装依赖包:
sudo yum update sudo yum install curl gcc make epel-release GraphicsMagick
安装 Node.js 和 npm:
curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash sudo yum install nodejs npm
安装 MongoDB:
curl -sL https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/getPackage/mongodb-org-4.0.20.rpm | sudo yum install -y sudo systemctl start mongod sudo systemctl enable mongod
-
下载并安装 Rocket.Chat
下载 Rocket.Chat 最新版本:
curl -L https://releases.rocket.chat/latest/download | tar xzf - -C /tmp cd /tmp/bundle/programs/server && npm install unsafeperm sudo mv /tmp/bundle /opt/Rocket.Chat
-
配置 Rocket.Chat 服务
创建系统用户和目录权限:
sudo useradd -M rocketchat sudo usermod -aG rocketchat rocketchat sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat
创建 systemd 单元文件:
sudo tee /lib/systemd/system/rocketchat.service <
启动并设置开机自启动:
sudo systemctl enable rocketchat sudo systemctl start rocketchat
-
配置 Nginx 反向代理(可选)
编辑 Nginx 配置文件:
sudo vi /etc/nginx/conf.d/rocketchat.conf
添加以下内容:
upstream chat { server localhost:3000; keepalive 8; } server { listen 80; server_name your_domain.com; location / { proxy_set_header XRealIP $remote_addr; proxy_set_header XForwardedFor $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginXProxy true; proxy_pass http://chat; proxy_redirect off; } }
重启 Nginx:
sudo systemctl restart nginx
-
访问和配置 Rocket.Chat
访问服务器:打开浏览器,访问
http://your_domain.com:3000
,按照页面提示完成初始配置,包括管理员账户信息等。
以上是在 CentOS 上搭建消息推送服务的两种常见方法,你可以根据自己的需求进行选择。