HalNiの雑記

備忘録を兼ねて。サーバマシンとかネットワークとか

openSUSE で Mattermost Server を構築する ( openSUSE Leap 15.4 )

openSUSE 上に Mattermost Server を構築する

以下の公式ドキュメントに記載されている構築手順は Ubuntu/Debian RHEL のみであるため、参考程度に参照しつつopenSUSE上での構築を試行したときのログ
Deploy Mattermost — Mattermost documentation
結果としては問題なく動作可能である

作業環境:

openSUSE Leap 15.4
- mariadb-10.6.10-150400.3.17.1.x86_64
- mattermost : 7.9.1 (Build Enterprise Ready: false)

データベースの有効化
mysql ではなく mariadb をインストールして有効化

sudo zypper install mariadb
sudo systemctl enable --now mariadb

halni@localhost:~> sudo zypper install mariadb
Loading repository data...
Reading installed packages...
'mariadb' is already installed.
No update candidate for 'mariadb-10.6.10-150400.3.17.1.x86_64'. The highest available version is already installed.     ★ インストール済  
Resolving package dependencies...
Nothing to do.
halni@localhost:~>

halni@localhost:~> systemctl status mariadb
○ mariadb.service - MariaDB database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
     Active: inactive (dead)
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
halni@localhost:~> sudo systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
halni@localhost:~>

データベースの初期設定
mariadbの初期設定を行う

sudo mysql_secure_installation

基本は推奨設定のまま変更せず、パスワードだけ新規作成を行う

halni@localhost:~> sudo mysql_secure_installation
...(略)...
Enter current password for root (enter for none):
...(略)... 
Switch to unix_socket authentication [Y/n]
...(略)...
Change the root password? [Y/n]
New password:
Re-enter new password:
...(略)...
Remove anonymous users? [Y/n]
...(略)...
Disallow root login remotely? [Y/n]
...(略)...
Remove test database and access to it? [Y/n]
...(略)...
Reload privilege tables now? [Y/n]
...(略)...
halni@localhost:~>

次にrootユーザでmariadbの管理ユーザを作成する

公式ドキュメントに則った

  • 管理ユーザ mmuser
  • パスワード mmuser-password
  • データベース mattermost

で設定を行う場合、

CREATE USER 'mmuser'@'%' IDENTIFIED BY 'mmuser-password';
CREATE DATABASE mattermost;
GRANT ALL PRIVILEGES ON mattermost.* TO 'mmuser'@'%';

となる

lrwxrwxrwx 1 root root           7 Oct 17 15:31 mysql -> mariadb

halni@localhost:~> sudo mariadb
MariaDB [(none)]> CREATE USER 'mmuser'@'%' IDENTIFIED BY 'mmuser-password';
MariaDB [(none)]> CREATE DATABASE mattermost;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermost.* TO 'mmuser'@'%';
MariaDB [(none)]> EXIT
Bye
halni@localhost:~>

Mattermost の tarイメージをダウンロード
Mattermost の tarイメージのダウンロードを行う
記事作成時点の最新版は 7.9.1 であっため指定している
注意点として、有償サポートを使用しない場合は Team Edition をダウンロードする必要がある

halni@localhost:~> wget https://releases.mattermost.com/7.9.1/mattermost-team-7.9.1-linux-amd64.tar.gz  

...(略)...

2023-03-25 12:17:33 (62.2 MB/s) - ‘mattermost-team-7.9.1-linux-amd64.tar.gz’ saved [424042343/424042343]

halni@localhost:~>

ダウンロードした tarballを展開し、作成されたmattermostディレクトリを /opt配下に移動させる
またこのタイミングでデータ用ディレクトリを作成しておく

tar -xvf mattermost-team-7.9.1-linux-amd64.tar.gz
sudo mv mattermost /opt
sudo mkdir /opt/mattermost/data

halni@localhost:~> tar -xvf mattermost-team-7.9.1-linux-amd64.tar.gz
...(略)...
halni@localhost:~> sudo mv mattermost /opt
halni@localhost:~> ls /opt/
mattermost
halni@localhost:~> sudo mkdir /opt/mattermost/data
halni@localhost:~>

ユーザを作成、使用ディレクトリを設定

sudo useradd --system --user-group mattermost
sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost

halni@localhost:~> sudo useradd --system --user-group mattermost
halni@localhost:~> sudo chown -R mattermost:mattermost /opt/mattermost
halni@localhost:~> sudo chmod -R g+w /opt/mattermost

設定ファイルを編集
今回はデータベースに MariaDB (MySQL) を使用するため修正が必要になる

If you’re using MySQL:

Set "DriverName" to "mysql" Set "DataSource" to the following value, replacing <mmuser-password> and <host-name-or-IP> with the appropriate values. Also make sure that the database name is mattermost instead of mattermost_test: "mmuser:<mmuser-password>@tcp(<host-name-or-IP>:3306)/mattermost?charset=utf8mb4,utf8&writeTimeout=30s"

halni@localhost:~> sudo vim /opt/mattermost/config/config.json
-    "DriverName": "postgres",
-    "DataSource": "postgres://mmuser:mostest@localhost/mattermost_test?sslmode=disable\u0026connect_timeout=10\u0026binary_parameters=yes",
+    "DriverName": "mysql",
+    "DataSource": "mmuser:mmuser-password@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&writeTimeout=30s",

ユーザを切り替えて実行

halni@localhost:~> sudo su mattermost
mattermost@localhost:/home/halni> cd /opt/mattermost
mattermost@localhost:/opt/mattermost> bin/mattermost

...(略)...  

localhostへアクセスすると、アカウント設定画面が表示される

アカウント作成画面が表示される

管理者アカウントとワークスペースを作成すると、チャンネルが使用可能になる

Slack風の見慣れた画面が立ち上がる

後設定
動作することが確認出来たら、mattermostのsystemdへの登録とポート開放を行う

sudo vim /etc/systemd/system/mattermost.service
sudo chmod 644 /etc/systemd/system/mattermost.service
sudo systemctl daemon-reload
sudo systemctl enable --now mattermost

sudo firewall-cmd --add-port=8065/tcp --permanent
sudo firewall-cmd --reload

halni@localhost:~> sudo vim /etc/systemd/system/mattermost.service
halni@localhost:~> cat /etc/systemd/system/mattermost.service
[Unit]
Description=Mattermost-Server service
After=syslog.target network.target mariadb.service

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

[Install]
WantedBy=multi-user.target
halni@localhost:~> ls -l /etc/systemd/system/mattermost.service
-rw-r--r-- 1 root root 346 Mar 25 15:14 /etc/systemd/system/mattermost.service
halni@localhost:~>
halni@localhost:~> sudo chmod 644 /etc/systemd/system/mattermost.service
[sudo] password for root:
halni@localhost:~> sudo systemctl daemon-reload
halni@localhost:~> systemctl status mattermost.service
○ mattermost.service - Mattermost-Server service
     Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: disabled)
     Active: inactive (dead)
halni@localhost:~> sudo systemctl enable --now mattermost
Created symlink /etc/systemd/system/multi-user.target.wants/mattermost.service → /etc/systemd/system/mattermost.service.
halni@localhost:~>

halni@localhost:~> sudo firewall-cmd --add-port=8065/tcp --permanent
success
halni@localhost:~> sudo firewall-cmd --reload
success
halni@localhost:~>

HTTPS通信の有効化
Mattermost Serverへの通信をSSLで保護する
とりあえずオレオレ自己署名のSSL証明書を使用した

openssl genrsa 2048 > server.key
openssl req -new -key server.key > server.csr
openssl x509 -days 3650 -req -sha256 -signkey server.key < server.csr > server.crt

halni@localhost:~/Documents> openssl genrsa 2048 > server.key
Generating RSA private key, 2048 bit long modulus (2 primes)
.........................................+++++
......................................................+++++
e is 65537 (0x010001)
halni@localhost:~/Documents> openssl req -new -key server.key > server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
halni@localhost:~/Documents> openssl x509 -days 3650 -req -sha256 -signkey server.key < server.csr > server.crt
Signature ok
subject=C = AU, ST = Some-State, O = Internet Widgits Pty Ltd
Getting Private key
halni@localhost:~/Documents> ls
server.crt  server.csr  server.key

作成した server.crt・server.key をそれぞれMattermost のシステムコンソールから登録
環境 → ウェブサーバー 内の 接続のセキュリティーTLS に変更、TLS証明書/鍵ファイルのあるパスを入力する

3項目の設定だけで動作する

あとはルータにポート開放の設定を入れると完成

以上で別ネットワーク環境からでも(一応)アクセス可能になる