Operations 10 min read

Integrating Mattermost with GitLab for ChatOps: Installation, Configuration, and Usage Guide

This guide explains how to set up Mattermost and integrate it with GitLab to enable ChatOps, covering concepts like NoOps, the DevOps lifecycle, detailed installation steps for Mattermost, MySQL, Nginx proxy configuration, webhook creation, slash command setup, and testing procedures.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Integrating Mattermost with GitLab for ChatOps: Installation, Configuration, and Usage Guide

ChatOps is a modern work style that combines people, tools, and discussions to boost productivity and accelerate development, while NoOps represents the next evolution of DevOps where automation handles monitoring, recovery, and operations.

Mattermost is an open‑source messaging platform built for development teams, offering private‑cloud deployment, extensive DevOps tool integrations (Jira, Jenkins, GitLab, etc.), and features that unify people, tools, system data, and automation across the DevOps lifecycle (Plan, Code, Build, Test, Release, Deploy, Monitor).

Mattermost Installation

The Mattermost server can be deployed on Ubuntu, CentOS, Windows, Docker, or Kubernetes; this guide uses CentOS. After downloading the server package, it is extracted to /opt/mattermost , a dedicated system user is created, and appropriate permissions are set.

Database Installation

# 下载源
wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum localinstall mysql57-community-release-el7-9.noarch.rpm

# 安装 mysql
yum install mysql-community-server
systemctl start mysqld.service
systemctl enable mysqld

# 连接数据库
grep 'temporary password' /var/log/mysqld.log
mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password42!';
mysql> create user 'mmuser'@'%' identified by 'mmuser-password';
mysql> create database mattermost;
mysql> grant all privileges on mattermost.* to 'mmuser'@'%';

Mattermost Server Setup

wget https://releases.mattermost.com/X.X.X/mattermost-X.X.X-linux-amd64.tar.gz
tar -xvzf *.gz
mv mattermost /opt
mkdir /opt/mattermost/data

## 添加系统用户
useradd --system --user-group mattermost
chown -R mattermost:mattermost /opt/mattermost
chmod -R g+w /opt/mattermost

## 编辑数据库配置 (config.json)
# SiteURL
"SiteURL": "http://mattermost.idevops.site",
# 数据库设置
"DriverName": "mysql",
"DataSource": "dbuser:dbpasswd@tcp(localhost:3306)/dbname?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"

## 测试启动
cd /opt/mattermost
sudo -u mattermost ./bin/mattermost   # should show "Server is listening on :8065"

## 添加 systemd 服务
vim /etc/systemd/system/mattermost.service
[Unit]
Description=Mattermost
After=syslog.target network.target mysqld.service

[Service]
Type=notify
WorkingDirectory=/opt/mattermost
User=mattermost
ExecStart=/opt/mattermost/bin/mattermost
PIDFile=/var/spool/mattermost/pid/master.pid
TimeoutStartSec=3600
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

chmod 664 /etc/systemd/system/mattermost.service
systemctl daemon-reload
systemctl enable mattermost
systemctl start mattermost
curl http://localhost:8065

Nginx Proxy Configuration

upstream backend {
    server xxxxxxxx:8065;
    keepalive 32;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;

server {
    listen 80;
    server_name mattermost.xxxxx.site;

    location ~ /api/v[0-9]+/(users/)?websocket$ {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        client_max_body_size 50M;
        proxy_set_header Host $http_host;
        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 $scheme;
        proxy_set_header X-Frame-Options SAMEORIGIN;
        proxy_buffers 256 16k;
        proxy_buffer_size 16k;
        client_body_timeout 60;
        send_timeout 300;
        lingering_timeout 5;
        proxy_connect_timeout 90;
        proxy_send_timeout 300;
        proxy_read_timeout 90s;
        proxy_pass http://backend;
    }

    location / {
        client_max_body_size 50M;
        proxy_set_header Connection "";
        proxy_set_header Host $http_host;
        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 $scheme;
        proxy_set_header X-Frame-Options SAMEORIGIN;
        proxy_buffers 256 16k;
        proxy_buffer_size 16k;
        proxy_read_timeout 600s;
        proxy_cache mattermost_cache;
        proxy_cache_revalidate on;
        proxy_cache_min_uses 2;
        proxy_cache_use_stale timeout;
        proxy_cache_lock on;
        proxy_http_version 1.1;
        proxy_pass http://backend;
    }
}

GitLab Project Event Notification

Configure a Mattermost incoming webhook URL in GitLab (Project Settings → Integrations → Mattermost) and enable the desired events. Provide the webhook URL, optional username, and optionally enable notifications only for broken pipelines.

Enable Slash Commands

In GitLab, go to Project Settings → Integrations → Mattermost slash commands, copy the provided token, then in Mattermost enable the corresponding slash command and paste the token.

Testing

After configuration, create a merge request or issue in GitLab; the notification should appear in the selected Mattermost channel. Use the /gitlab issue create devopstest command in Mattermost to create an issue directly from chat.

Overall, this tutorial demonstrates how to deploy Mattermost, configure its database and reverse proxy, integrate it with GitLab via webhooks and slash commands, and leverage ChatOps to streamline DevOps workflows.

DockerIntegrationDevOpsGitLabnginxChatOpsMattermost
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.