如何在 Ubuntu 20.04 上安装 Mattermost 团队消息系统如何在 Ubuntu 20.04 上安装 Mattermost 团队消息系统如何在 Ubuntu 20.04 上安装 Mattermost 团队消息系统如何在 Ubuntu 20.04 上安装 Mattermost 团队消息系统
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

如何在 Ubuntu 20.04 上安装 Mattermost 团队消息系统

发表 admin at 2025年2月28日
类别
  • 未分类
标签

本教程适用于这些操作系统版本

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 20.04(Focal Fossa)

在此页

  1. 先决条件
  2. 开始
  3. 安装和配置 MariaDB
  4. 安装和配置 Mattermost
  5. 为 Mattermost 创建一个 Systemd 服务文件
  6. 将 Nginx 配置为反向代理
  7. 使用 Lets Encrypt SSL 保护 Mattermost
  8. 访问 Mattermost 网络界面
  9. 结论

Mattermost 是一个开源和自托管的消息传递应用程序,用于聊天、文件共享、搜索和集成。它是 Slack 聊天的替代方案,可将您所有的团队沟通集中在一个地方。它使用 React 和 Golang 编写,后端使用 PostgreSQL 或 MySQL 数据库。它提供了一组丰富的功能,包括推送通知、无限搜索历史记录、自定义表情符号、Webhooks 和命令、活动目录、多节点数据库部署支持、论坛、讨论区等等。

在本教程中,我们将向您展示如何在 Ubuntu 20.04 上使用 Nginx 安装 Mattermost 和 Lets Encrypt SSL。

先决条件

  • 一台运行 Ubuntu 20.04 的服务器。
  • 用您的服务器 IP 指向的有效域名。
  • 在服务器上配置了根密码。

入门

首先,建议使用最新版本更新您的系统包。您可以通过运行以下命令来更新它们:

apt-get update -y

更新所有包后,通过运行以下命令安装其他所需的依赖项:

apt-get install curl wget vim git unzip gnupg2 -y

安装所有必需的软件包后,您可以继续下一步。

安装和配置 MariaDB

Mattermost 使用 MySQL/MariaDB 作为数据库后端。所以必须在你的服务器中安装 MariaDB 服务器。如果没有安装,可以使用以下命令安装:

apt-get install mariadb-server -y

安装 MariaDB 服务器后,使用以下命令登录 MariaDB:

mysql

登录后,使用以下命令为 Mattermost 创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE mattermostdb;
MariaDB [(none)]> CREATE USER 'mattermost'@'%' IDENTIFIED BY 'password';

接下来,使用以下命令将所有权限授予 Mattermost:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mattermost'@'%';

接下来,使用以下命令刷新权限并退出 MariaDB shell:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

配置 MariaDB 数据库后,您可以继续下一步。

安装和配置 Mattermost

首先,您需要从其官方网站下载最新版本的 Mattermost。您可以使用以下命令下载它:

wget https://releases.mattermost.com/5.24.2/mattermost-5.24.2-linux-amd64.tar.gz

下载后,使用以下命令解压缩下载的文件:

tar -xvzf mattermost-5.24.2-linux-amd64.tar.gz

接下来,将提取的目录复制到 /opt:

cp -r mattermost /opt

接下来,为 Mattermost 创建一个数据目录:

mkdir /opt/mattermost/data

接下来,您需要创建一个单独的用户来运行 Mattermost。您可以使用以下命令创建它:

useradd --system --user-group mattermost

接下来,将 mattermost 目录的所有权更改为 mattermost 并使用以下命令授予适当的权限:

chown -R mattermost:mattermost /opt/mattermost
chmod -R g+w /opt/mattermost

接下来,编辑 Mattermost 默认配置文件并定义您的数据库设置和站点 URL。

nano /opt/mattermost/config/config.json

根据您的需要更改以下行:

    "SiteURL": "https://mattermost.linuxbuz.com",

    "DriverName": "mysql",
    "DataSource": "mattermost:(localhost:3306)/mattermostdb?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",

完成后保存并关闭文件。

为 Mattermost 创建系统服务文件

接下来,您需要创建一个 systemd 服务文件来管理 Mattermost 服务。您可以使用以下命令创建它:

nano /lib/systemd/system/mattermost.service

添加以下行:

[Unit]
Description=Mattermost
After=network.target
After=mysql.service
Requires=mysql.service

[Service]
Type=notify
User=mattermost
Group=mattermost
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
LimitNOFILE=49152

[Install]
WantedBy=mariadb.service

保存并关闭文件,然后使用以下命令重新启动 systemd 守护进程:

systemctl daemon-reload

接下来,启动 Mattermost 服务并使用以下命令使其在系统重启时启动:

systemctl start mattermost
systemctl enable mattermost

接下来,使用以下命令验证 Mattermost 服务的状态:

systemctl status mattermost

您应该得到以下输出:

? mattermost.service - Mattermost
     Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-08-01 09:12:52 UTC; 17s ago
   Main PID: 4106 (mattermost)
      Tasks: 20 (limit: 2353)
     Memory: 85.9M
     CGroup: /system.slice/mattermost.service
             ??4106 /opt/mattermost/bin/mattermost
             ??4198 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64

Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.131499,"caller":"mlog/sugar.go:19","msg":"Sent notification of ne>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.1841655,"caller":"jobs/workers.go:73","msg":"Starting workers"}
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.1842792,"caller":"bleveengine/bleve.go:267","msg":"UpdateConf Ble>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.1930475,"caller":"jobs/schedulers.go:74","msg":"Starting schedule>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.20063,"caller":"app/web_hub.go:83","msg":"Starting websocket hubs>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2099638,"caller":"app/license.go:37","msg":"License key from http>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2205582,"caller":"app/server.go:525","msg":"Starting Server..."}
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2208374,"caller":"app/server.go:594","msg":"Server is listening o>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2211802,"caller":"commands/server.go:106","msg":"Sending systemd >
Aug 01 09:12:52 ubunt4 systemd[1]: Started Mattermost.

此时,Mattermost 正在运行并监听 8065 端口。

配置 Nginx 作为反向代理

接下来,您需要将 Nginxx 配置为 Mattermost 的反向代理。首先,使用以下命令安装 Nginx 包:

apt-get install nginx -y

安装后,使用以下命令创建 Nginx 虚拟主机配置文件:

nano /etc/nginx/sites-available/mattermost.conf

添加以下行:

upstream mattermost {
   server localhost: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.linuxbuz.com;

   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://mattermost;
   }

   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://mattermost;
   }
}

保存并关闭文件,然后使用以下命令激活虚拟主机配置:

ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.conf

接下来,验证 Nginx 是否存在任何配置错误:

nginx -t

您应该得到以下输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

最后,重新启动 Nginx 服务以应用更改:

systemctl restart nginx

使用 Lets Encrypt SSL 保护 Mattermost

首先,您需要在系统中安装 Certbot 客户端来管理 Lets Encrypt SSL。您可以使用以下命令安装它:

apt-get install python3-certbot-nginx -y

安装 Certbot 后,运行以下命令为您的网站安装 Lets Encrypt SSL。

certbot --nginx -d mattermost.linuxbuz.com

您将被要求提供一个有效的电子邮件地址并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mattermost.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/mattermost.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

键入 2 并按 Enter 以在您的域上安装 Lets Encrypt SSL。安装后,您应该看到以下输出:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/mattermost.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://mattermost.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=mattermost.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mattermost.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mattermost.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-10-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

访问 Mattermost Web 界面

现在,打开您的 Web 浏览器并输入 URL https://mattermost.linuxbuz.com。您将被重定向到 Mattermost 注册屏幕:

提供您的电子邮件地址、姓名、密码,然后单击“创建帐户”按钮。您应该看到以下屏幕:

单击创建团队按钮。您应该看到以下屏幕:

提供您的团队名称,然后单击“下一步”按钮。您应该看到以下屏幕:

提供您的团队 URL,然后单击“完成”按钮。您应该会看到 Mattermost 欢迎屏幕:

单击“跳过教程”按钮。您应该在以下屏幕中看到 Mattermost 仪表板:

结论

在本指南中,您学习了如何在 Ubuntu 20.04 服务器上安装 Mattermost Team Messaging 应用程序。您还学习了如何将 Nginx 配置为反向代理并使用 Lets Encrypt SSL 保护它。您现在可以探索 Mattermost 服务并与您的团队一起工作。

©2015-2025 Norria support@norria.com