Mattermost
- Mattermost 是一个开源、自托管的 Slack 替代品。作为专有 SaaS 消息传递的替代方案,Mattermost 将您的所有团队沟通集中在一个地方,使其可搜索并在任何地方访问。
本文介绍如何安装和配置 Mattermost 服务器。
安装
Mattermost 服务器可以通过两种方式安装
- 使用 Docker,按照 #使用 Docker 中描述的步骤操作;
- 使用软件包,按照 #使用软件包 中描述的步骤操作。
Electron 桌面客户端由 mattermost-desktop 软件包提供。
使用 Docker
通过使用 Docker,您无需手动安装数据库服务器和配置 Mattermost 依赖项。由于 docker 镜像捆绑了所有依赖项,因此可以减少您的工作量。
但是,缺点是您无法选择所需的数据库后端或 Web 服务器,而只能选择 docker 镜像中提供的那些,除非您自己制作镜像。
- 安装 Docker(包括
docker-compose
)。 - 下载源代码
$ git clone https://github.com/mattermost/mattermost-docker.git
- 编辑
docker-compose.yml
文件- 取消注释
args:
行。 - 对于团队版,取消注释行:
- edition=team
。 - 在部分中采用 UID/GID 以匹配
./volumes/app/mattermost/*
文件夹所有者的 UID/GID。 - 将端口转发语句添加为
app
部分的子项(例如,在build
和restart
之间)
- 取消注释
ports: - "127.0.0.1:8065:8000"
- 构建并启动 docker 容器
$ cd mattermost-docker $ docker-compose build $ docker-compose up -d
- 在浏览器中打开
https://127.0.0.1:8000/
。
请参阅官方指南,了解如何配置 TLS、电子邮件、启用企业功能以及使用 Docker Compose 使用多个服务器节点。
Mattermost 官方 Docker Hub 页面上也提供了一些 Docker 镜像。另请参阅 Mattermost Docker 镜像的存储库。
使用软件包
安装 mattermost 软件包,或 mattermost-gitAUR 以获取开发版本。
- 安装将创建
mattermost
用户和组。 - 配置发生在
/etc/webapps/mattermost/config.json
中,其中/etc/webapps/mattermost/
和/etc/webapps/mattermost/config.json
均归mattermost:mattermost
所有。 - 在递归归
mattermost:mattermost
所有的/var/lib/mattermost/
中,我们可以找到files
,一个文件夹,用于存储所有通过消息发布的用户文件、个人资料图片和团队图片;client
,一个与 webapp 客户端相关的文件夹,其中包含 webapp 在运行时重写的文件,以及plugins
子文件夹中,通过 webui 安装的 web 插件;plugins
,一个与插件(服务器部分)相关的文件夹。
- 在
/var/log/mattermost
中,一个在安装过程中动态创建的文件夹(参见tmpfiles.d),用于存储服务器日志为 json。/var/log/mattermost
和/var/log/mattermost/mattermost.log
均归mattermost:mattermost
所有。 - 其余不可变的 Mattermost 目录位于
/usr/share/webapps/mattermost/
,并且递归归root:root
所有。
继续#数据库设置。
数据库设置
Mattermost 需要数据库后端。如果您计划在同一台计算机上运行它,请首先安装 MySQL 或 PostgreSQL 作为数据库。
按照以下部分之一进行操作,然后继续#配置 Mattermost。
MySQL/MariaDB
$ mysql -u root -p
CREATE DATABASE mattermostdb; CREATE USER mmuser IDENTIFIED BY 'mmuser_password'; GRANT ALL ON mattermostdb.* TO mmuser;
PostgreSQL
1. 安装 和 配置 PostgreSQL。
2. 在 TCP 或 UNIX 套接字之间选择,并跳转到相应的部分。
使用 TCP 套接字
3. 以 postgres
用户身份连接到服务器时创建新用户(系统将提示您输入新用户的密码)
[postgres]$ createuser -P mmuser
4. 创建 Mattermost 数据库,由 mmuser
用户拥有
[postgres]$ createdb -O mmuser mattermostdb
5. PostgreSQL#配置 PostgreSQL 以允许远程主机访问
6. 验证它是否工作
$ psql --host=ip_address --dbname=mattermostdb --username=mmuser --password
使用 Unix 套接字
3. 以 postgres
用户身份连接到服务器时创建新用户
[postgres]$ createuser mattermost
4. 创建 Mattermost 数据库,由 mattermost
用户拥有
[postgres]$ createdb -O mattermost mattermostdb
5. 通过将以下行添加到 /var/lib/postgres/data/pg_hba.conf
来设置 Unix 套接字
local mattermostdb mattermost peer
6. 重启 postgresql.service
。
7. 验证它是否工作
[mattermost]$ psql --dbname=mattermostdb --username=mattermost
配置 Mattermost
Mattermost 在 /etc/webapps/mattermost/config.json
中配置。字符串需要用引号引起来。
您需要调整两个设置以适应您的数据库。
DriverName
设置:MySQL 使用 mysql
,PostgreSQL 使用 postgres
。
DataSource
- 对于 MySQL,将其设置为
mmuser:mmuser_password@unix(/run/mysqld/mysqld.sock)/mattermostdb?charset=utf8mb4,utf8
。 - 对于 PostgreSQL
- TCP 套接字:
postgres://mmuser:mmuser_password@127.0.0.1:5432/mattermostdb?sslmode=disable&connect_timeout=10
- Unix 套接字:
postgres:///mattermostdb?host=/run/postgresql
;确保在postgres:
之后有 3 个斜杠,mattermostdb
是数据库的名称,/run/postgresql
是包含 Unix 套接字的目录
- TCP 套接字:
mmuser_password
替换为用户的密码。启动/启用 mattermost.service
并打开 https://127.0.0.1:8065/。
设置 Mattermost
- 导航到您的 Mattermost 安装并创建一个团队和用户。
- 系统中的第一个用户将自动被授予
system_admin
角色,这使您可以访问系统控制台。 - 单击左上角的菜单按钮,然后选择系统控制台选项。
- 更新环境 > SMTP 设置以设置 SMTP 电子邮件服务。以下示例假定为 AmazonSES。
- 将SMTP 服务器设置为
email-smtp.us-east-1.amazonaws.com
- 将SMTP 服务器端口设置为
465
- 将启用 SMTP 身份验证设置为true
- 将SMTP 服务器用户名设置为
your_smtp_username
- 将SMTP 服务器密码设置为
your_smtp_password
- 将连接安全设置为TLS
- 保存设置
- 将SMTP 服务器设置为
- 更新站点配置 > 通知
- 将发送电子邮件通知设置为true
- 将通知显示名称设置为
No-Reply
- 将通知发件人地址设置为
mattermost@example.com
- 将支持电子邮件地址设置为可以接收电子邮件的真实地址
- 保存设置
- 通过将需要电子邮件验证更改为true来更新身份验证 > 电子邮件。
- 通过将将日志输出到控制台设置为false来更新环境 > 日志记录设置。
- 随意修改其他设置。
- 重启
mattermost.service
。
插件
默认情况下启用插件,但需要访问插件目录,该目录需要使用正确的所有者创建
$ mkdir /usr/share/webapps/mattermost/client/plugins $ chown mattermost:mattermost /usr/share/webapps/mattermost/client/plugins
技巧与诀窍
通过反向 Web 代理实现有效的 HTTPS
为了从不支持自签名 TLS 证书的 Android 和 iOS 应用程序安全地访问您的 Mattermost 服务器,您可以设置反向 Web 代理。
代理的主要好处是
- SSL 终止
- HTTP 到 HTTPS 重定向
- 端口映射 80 到 8065
- 标准请求日志
可以使用大多数 Web 服务器来实现代理。
nginx
- 安装并运行 nginx,最好是 nginx-mainline。
- 将您的域名(例如
mattermost.example.com
)指向服务器。 - 配置 nginx 以将来自互联网的连接代理到 Mattermost 服务器。创建并编辑 nginx 配置文件
/etc/nginx/sites-available/mattermost
。upstream backend { server 127.0.0.1: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.example.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://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_pass http://backend; } }
- 启用 mattermost 服务器
# mkdir /etc/nginx/sites-enabled # ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/mattermost
- 重启
nginx.service
。 - 验证您可以通过代理访问 Mattermost
$ curl https://127.0.0.1/
您应该看到一个标题为Mattermost
的页面。 - 设置 Let’s Encrypt。
Lighttpd2
用于 lighttpd2-gitAUR 的配置示例,以充当 Mattermost 的代理,假设您在 /etc/lighttpd2/certs/lighttpd2.pem
中有一个证书。
如果您想将代理转移到虚拟主机中,请参阅 mod_vhost。
/etc/lighttpd2/lighttpd.conf
setup { module_load [ "mod_accesslog", "mod_proxy", "mod_openssl" ]; openssl [ "listen" => "0.0.0.0:443", "listen" => "[::]:443", "pemfile" => "/etc/lighttpd2/certs/lighttpd2.pem", "options" => ["ALL", "NO_TICKET"], "verify" => true, "verify-any" => true, "verify-depth" => 9 ]; listen "0.0.0.0:80"; listen "[::]:80"; log ["debug" => "", default => "/var/log/lighttpd2/error.log"]; accesslog "/var/log/lighttpd2/access.log"; accesslog.format "%h %V %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}\""; static.exlude_extensions [ ".php", ".pl", ".fcgi", "~", ".inc" ]; } openssl.setenv "client-cert"; keepalive.timeout 360; docroot "/srv/http"; index [ "index.php", "index.html", "index.htm" ]; include "/etc/lighttpd2/mimetypes.conf"; proxy "127.0.0.1:8065";
测试翻译和拉取请求
您可以使用非官方脚本 mattermost-prepare-pkgbuild 来测试语言和拉取请求。