如何在 Ubuntu 22.04/23.04 上安装 Mattermost

Mattermost 是一个开源、自托管的聊天和协作平台,专为现代团队设计。Mattermost 是 Slack 的替代品。

在本教程中,我们将向您展示在 Ubuntu 22.04 上安装MattermostPostgreSQL 数据库服务器的完整步骤。

步骤 1:更新操作系统

使用以下命令将您的Ubuntu  22.04 操作系统更新 到最新版本:

# apt update && sudo apt upgrade -y

第二步:安装 Nginx 网络服务器

您可以apt 通过执行以下命令通过包管理器安装 Nginx。

# apt install nginx

您可以通过输入以下命令启动 Nginx 服务并将其配置为在启动时运行:

# systemctl start nginx
# systemctl enable nginx

Nginx 使用 命令验证服务的状态 systemctl status :

# systemctl status nginx

输出:

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running)
       Docs: man:nginx(8)
    Process: 5421 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 5422 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 5423 (nginx)
      Tasks: 2 (limit: 2196)
     Memory: 6.7M
        CPU: 327ms
     CGroup: /system.slice/nginx.service
             ├─5423 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             └─5424 "nginx: worker process"

第 3 步:安装 PostgreSQL 数据库服务器

运行 apt 命令进行安装:

# apt install postgresql postgresql-contrib

成功安装后,启用 PostgreSQL(在系统启动时自动启动),启动并使用以下命令验证状态:

# systemctl enable postgresql
# systemctl start postgresql
# systemctl status postgresql

接下来,运行下面的命令登录到上面刚刚安装的PostgreSQL:

su postgres
psql

然后,我们创建Mattermost数据库:

postgres=# CREATE DATABASE mattermostdb; 
postgres=# CREATE USER mattermost WITH PASSWORD 'Mattermost-Strong-Password'; 
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermostdb to mattermost; 
postgres=# \q

返回您的root用户帐户。

# exit

第 4 步:创建 mattermost 系统用户和组

我们需要设置一个名为 mattermost 的系统用户和组来运行服务。

# useradd --system --user-group mattermost

可以确认是系统用户,ID小于1000。

# id mattermost
uid=998(mattermost) gid=998(mattermost) groups=998(mattermost)

第 5 步:在 Ubuntu 22.04 上安装 Mattermost

默认情况下,Mattermost在 Ubuntu 22.04 基本存储库上不可用。请访问 官方发布 页面以获取最新版本。

运行以下命令将最新版本的 Mattermost 下载到您的 Ubuntu 系统:

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

/opt 使用 命令将下载的文件解压缩到 目录tar :

# tar xpvf mattermost-7.5.2-linux-amd64.tar.gz -C /opt

为 Mattermost 服务器创建数据存储目录。

# mkdir /opt/mattermost/data

为文件和目录设置正确的权限:

# chown mattermost:mattermost /opt/mattermost/ -R

第 6 步:配置 Mattermost 服务器

编辑配置文件以设置数据库驱动程序。

# nano /opt/mattermost/config/config.json

找到 SqlSettings部分并配置 PostgreSQL 数据库设置,如下所示:

"DriverName": "postgres",

"DataSource": "postgres://mattermost:Mattermost-Strong-Password@localhost:5432/mattermostdb?sslmode=disable&connect_timeout=10",

第 7 步:创建 Systemd 服务文件

创建用于启动/停止和重新启动服务的 systemd 单元 Mattermost 。

# nano /etc/systemd/system/mattermost.service

粘贴以下行:

[Unit]
Description=Mattermost
After=network.target
After=postgresql.service
BindsTo=postgresql.service

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

[Install]
  WantedBy=multi-user.target

重新加载系统守护进程并启动 Mattermost 服务:

# systemctl daemon-reload
# systemctl start mattermost
# systemctl enable mattermost

要确认一切正常,请检查服务状态:

# systemctl status mattermost

输出:

● mattermost.service - Mattermost
     Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: enabled)
     Active: active (running)
   Main PID: 4366 (mattermost)
      Tasks: 49 (limit: 2196)
     Memory: 539.5M
        CPU: 13.944s
     CGroup: /system.slice/mattermost.service
             ├─4366 /opt/mattermost/bin/mattermost
             ├─4395 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
             ├─4406 plugins/com.mattermost.calls/server/dist/plugin-linux-amd64
             ├─4419 plugins/playbooks/server/dist/plugin-linux-amd64
             ├─4427 plugins/focalboard/server/dist/plugin-linux-amd64
             └─4443 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64

第 8 步:为 Mattermost 配置 Nginx

然后,创建一个虚拟主机配置文件:

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

将以下代码添加到文件中:

server {
        listen 80;

        server_name mattermost.your-domain.com;
        root /opt/mattermost;

        error_log /var/log/nginx/mattermost.error;
        access_log /var/log/nginx/mattermost.access;

               location / {

        proxy_pass http://localhost:8065;

    }
}

请记住替换 your-domain.com 为您的服务器的域名。

保存并退出配置文件。

启用新的配置文件。

# 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

第 9 步:最重要的设置和配置

现在打开您的网络浏览器并转到 http://mattermost.your-domain.com ,您将看到以下屏幕:

Mattermost 创建账户

接下来,您将被带到团队创建页面:

Mattermost 创建团队

单击 Create a team按钮创建您的第一个团队:

最重要的团队

然后您将被要求为团队设置一个公共 URL:

Mattermost 团队 URL

单击 完成按钮打开 Mattermost 仪表板:

最重要的仪表板

评论和结论

就是这样。您已经成功Mattermost在 Ubuntu 22.04 上安装了 Nginx。有关更多信息,您可以查看Mattermost 官方文档

如果您有任何问题,请在下面发表评论。

类似文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注