欢迎 on it road

配置 Mattermost 服务的自动启动

使 Mattermost 服务在 Linux 启动时自动启动。
我们需要创建一个 Systemd 服务单元。

使用 vim 编辑器并为 Mattermost 创建一个 Systemd 服务单元。

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

在此文件中添加以下指令。

[Unit]
Description=Mattermost
After=syslog.target network.target postgresql.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

启用并启动 Mattermost 服务。

# systemctl enable --now mattermost.service
Created symlink /etc/systemd/system/multi-user.target.wants/mattermost.service -> /etc/systemd/system/mattermost.service.

在 CentOS/RHEL 8 上安装 MySQL 数据库服务器

Mattermost 需要一个后端数据库服务器来存储其数据。
它支持 MySQL 和 PostgreSQL 数据库。

我们可以安装 PostgreSQL 数据库服务器以与 XMPP 服务器一起使用。

但是,我们正在安装 MariaDB 数据库服务器,它是 MySQL 的一个著名分支。

如果我们已经有一个正在运行的数据库服务器,那么我们可以跳过此步骤并在该服务器上创建 Mattermost 数据库。

MariaDB 服务器在标准 yum 存储库中可用,因此我们可以在 dnf 命令的帮助下安装它。

# dnf install -y mariadb-server

启用并启动 MariaDB 数据库服务。

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service -> /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service -> /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service -> /usr/lib/systemd/system/mariadb.service.

由于我们已经安装了新的 MariaDB 服务器,因此,我们需要执行 MySQL 实例的初始配置。

使用以下 Linux 命令配置 MySQL 实例。

# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
 ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

以 root 数据库用户身份连接 MySQL 服务器。

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

创建一个新的数据库用户,该用户将拥有 Mattermost 软件数据库。

MariaDB [(none)]> create user 'mmuser'@'localhost' identified by 'mmpwd';
Query OK, 0 rows affected (0.001 sec)

现在创建最重要的数据库。

MariaDB [(none)]> create database mattermost;
Query OK, 1 row affected (0.001 sec)

授予 mmuser 对mattermost 数据库的完全权限。

MariaDB [(none)]> grant all privileges on mattermost.* to 'mmuser'@'localhost';
Query OK, 0 rows affected (0.001 sec)

从 mysql shell 退出。

MariaDB [(none)]> exit
Bye

配置 Linux 防火墙

虽然,Mattermost 服务已启动,但仍无法从网络客户端访问。
我们必须允许 Linux 防火墙中的默认服务端口,以便它可以接受来自网络客户端的传入流量。

为此,我们可以使用 firewall-cmd 命令。

# firewall-cmd --permanent --add-port=8065/tcp
success
# firewall-cmd --reload
success
在 CentOS/RHEL 8 上安装 Mattermost 聊天服务器

Mattermost 是一款开源、自托管的团队聊天和协作软件。
Mattermost 是一个免费的 Slack 替代品。

它是一个开源、自托管的服务器,具有团队聊天、文件共享、搜索、集成和协作功能。
Mattermost 有开源版和企业版。

在本文中,我们将学习如何在 CentOS/RHEL 8 上安装此 XMPP 服务器。

访问 Mattermost Web UI

在 Web 浏览器中打开 URL http://mattermost-02.onitroad.com:8065/。

因为我们是第一次访问 Mattermost Web UI,因此它要求注册电子邮件地址并在云上创建一个用户帐户。

我们需要创建一个团队进行协作和聊天。

提供团队名称并单击“下一步>”。

团队已创建。
记下团队 URL 并将其发给团队成员。

现在,我们可以到达 Mattermost 仪表板。
现在控制权在我们手中,根据要求自定义 Mattermost 聊天服务器。

在 CentOS/RHEL 8 上安装 Mattermost 聊天服务器

要下载 Mattermost,请访问其官方网站并获取最新版本的 URL。

通过使用 wget 命令,直接在 Linux CLI 下载最新版本的 Mattermost 软件。

# cd /tmp
# wget https://releases.mattermost.com/5.28.1/mattermost-5.28.1-linux-amd64.tar.gz

在 tar 命令的帮助下解压缩下载的 tar包。

# tar xvf mattermost-5.28.1-linux-amd64.tar.gz

解压后,将最重要的目录(从 tar包 中解压出来的)移动到 /opt 目录。

# mv mattermost /opt/

为 Mattermost 应用程序创建一个数据目录。

# mkdir /opt/mattermost/data

创建一个 Linux 用户来拥有 Mattermost 软件和内存中的进程。

# cd
# useradd -r -U mattermost

调整 /opt/mattermost 目录的文件权限和 SELinux 文件上下文。

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

Mattermost 配置位于 /opt/mattermost/config/config.json 中。

我们需要编辑此配置文件以根据环境更新设置。

# vi /opt/mattermost/config/config.json

查找并设置以下与 Mattermost 后端数据库相关的指令。
我们可以在“SqlSettings”配置块下找到它们。

"DriverName": "mysql",
"DataSource": "mmuser:mmpwd@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",

查找并设置以下指令。
我们可以在“ServiceSettings”配置块下找到它。

"SiteURL": "http://mattermost-02.onitroad.com",

请确保 Linux 服务器的主机名是可解析的。
我们可以配置权威 DNS 服务器,也可以简单地使用本地 DNS 解析器。

在这里,我们使用本地 DNS 解析器。

# vi /etc/hosts

其中添加以下条目。

192.168.1.232  mattermost-02 mattermost-02.onitroad.com

已安装并配置 Mattermost 软件。
我们可以使用以下命令对其进行测试。

# cd /opt/mattermost/
# sudo -u mattermost ./bin/mattermost

Mattermost 服务已启动并监听默认端口,例如:8065.

日期:2020-09-17 00:16:40 来源:oir作者:oir