117.info
人生若只如初见

CentOS消息推送服务如何搭建

在CentOS上搭建消息推送服务有多种选择,以下提供两种常见的消息推送服务搭建方法:使用 Gotify 以及使用 Rocket.Chat。

使用 Gotify 搭建消息推送服务

  1. 下载并解压 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
    
  2. 运行 Gotify 服务

    运行 Gotify 服务,默认会占用 80 端口。

    ./gotify-linux-amd64
    
  3. 配置 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
    
  4. 配置 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;
        }
    }
    
  5. 重启 Nginx 服务

    sudo systemctl restart nginx
    
  6. 访问网页版进行配置

    配置的服务地址端口是 80,那么访问 https://xx.com:18080 地址进入登录界面,默认的用户名密码是 admin/admin。需要点 APPS——CREATE APPLICATION 新建应用,获得令牌 Token。创建后拿到该应用的 token。

使用 Rocket.Chat 搭建消息推送服务

  1. 准备工作

    • 系统要求:CentOS 7 或更高版本。至少 1GB 的 RAM(建议 2GB 以上)。一个指向服务器 IP 地址的域名(例如 linuxidc.com)。Nginx 已安装并配置 SSL 证书(推荐使用 Let’s Encrypt 免费证书)。
    • 开放端口:确保服务器防火墙开放 3000 端口,以便外部访问 Rocket.Chat 服务器。
  2. 安装必要软件包

    更新系统并安装依赖包:

    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
    
  3. 下载并安装 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
    
  4. 配置 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
    
  5. 配置 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
    
  6. 访问和配置 Rocket.Chat

    访问服务器:打开浏览器,访问 http://your_domain.com:3000,按照页面提示完成初始配置,包括管理员账户信息等。

以上是在 CentOS 上搭建消息推送服务的两种常见方法,你可以根据自己的需求进行选择。

未经允许不得转载 » 本文链接:https://www.117.info/ask/fe70dAzsNAwZQAlU.html

推荐文章

  • 如何通过centos配置sftp端口

    在CentOS上配置SFTP端口,通常需要编辑SSH服务器的配置文件sshd_config。以下是详细步骤: 登录到CentOS服务器:
    使用SSH客户端(如PuTTY)登录到你的CentO...

  • centos中aliases如何影响脚本执行

    在 CentOS 系统中,aliases 是 shell 的一个功能,它允许用户为常用的命令或命令组合创建简短的别名。这些别名通常在用户的 shell 配置文件(如 ~/.bashrc 或 ~/...

  • centos pgadmin安全配置要点

    在CentOS系统上配置PgAdmin的安全性是确保数据库管理工具使用安全、防止未授权访问和数据泄露的关键步骤。以下是一些关键的安全配置要点:
    修改默认密码 Po...

  • VirtualBox在CentOS如何共享文件夹

    在VirtualBox中设置CentOS虚拟机共享文件夹的步骤如下: 安装必要的软件包:
    在CentOS虚拟机中,首先需要安装一些必要的软件包。打开终端并执行以下命令:<...

  • Ubuntu Java环境如何优化

    优化Ubuntu上的Java环境可以从多个方面入手,包括安装合适的JDK版本、配置环境变量、调整JVM参数以及监控和调优Java应用。以下是详细的步骤和建议:
    安装和...

  • LNMP在Debian上的安装步骤是什么

    LNMP是指Linux系统下Nginx+MySQL+PHP这种网站服务器架构,以下是LNMP在Debian上的安装步骤:
    一、安装Nginx 更新软件包列表: sudo apt update 安装Nginx:...

  • ubuntu informix故障怎么排查

    在Ubuntu系统上排查Informix故障时,可以参考以下步骤和工具:
    故障排查步骤 确认问题: 详细记录问题表现,包括错误消息、系统行为异常的具体情况、问题发...

  • 如何用ifconfig配置Debian DNS服务器

    在Debian系统中,ifconfig命令主要用于配置网络接口的IP地址、子网掩码等参数,而不是直接用于配置DNS服务器。但是,你可以通过修改网络接口的配置文件来间接地设...