安装Mattermost(聊天室)
安装Mattermost(聊天室)
介绍:mattermost 是一个具有团队协作沟通交流的开源工具,它由Go和React编写,支持中文简体。
项目地址:https://github.com/mattermost/mattermost-server
<可选>:安装go环境
官网下载安装包
下载地址:https://studygolang.com/dl/
版本选择:go1.18.2.linux-amd64.tar.gz
$ wget https://studygolang.com/dl/golang/go1.18.2.linux-amd64.tar.gz
$ tar xf go*.linux-amd64.tar.gz -C /usr/local # 解压至"/usr/local"目录
$ sudo vim ~/.profile # 添加go环境变量
-- >
export PATH=$PATH:/usr/local/go/bin
$ source ~/.profile # 执行更新环境变量
$ go version # 验证go是否成功安装
-- >
go version go1.18 linux/amd64
1.安装、配置数据库
根据mattermost 官网安装文档,提供了两种数据库连接方式。
官网文档:https://docs.mattermost.com/install/install-tar.html
1.1方案一:mysql
$ apt-get update
$ apt-get upgrade
$ apt-get install mysql-server
$ vim /etc/mysql/mysql.conf.d/mysqld.cnf # 修改mysql配置文件,允许非本地ip访问
-- >
bind-address = 127.0.0.1 将ip修改为0.0.0.0
$ systemctl restart mysql # 重启mysql服务
$ systemctl status mysql
$ mysql -h 127.0.0.1 -u root -p # 创建用户、密码、数据库、赋予权限
mysql> create user 'mmuser'@'%' identified by 'mmuser-password'
mysql> create database mattermost default charset utf8 collate utf8_general_ci;
mysql> grant all privileges on mattermost.* to 'mmuser'@'%' with grant option;
mysql> flush privileges;
mysql> exit
1.2方案二:postgresql
$ sudo apt update
$ sudo apt install postgresql postgresql-contrib
修改配置文件postgresql.conf
$ vim /etc/postgresql/12/main/postgresql.conf
-- >
# - Connection Settings -
# listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
将 # listen_addresses = 'localhost'
修改为 listen_addresses = '*' 或'192.168.2.10'(如果是多个网卡,则此处修改为某一网卡的固定ip)
修改配置文件pg_hba.conf
$ vim /etc/postgresql/12/main/pg_hba.conf
-- >
# IPv4 local connections:
#host all all 127.0.0.1/32 md5 # 将此行注释掉
host all all 0.0.0.0/0 md5 # 新增此行
# IPv6 local connections:
host all all ::1/128 md5
$ service postgresql restart # 重启postgresql服务
设置pgsql用户名、密码,pgSQL数据默认会创建一个postgres的数据库用户作为数据库的管理员,密码是随机的
$ sudo -u postgres psql # 使用postgres 用户登录
postgres=# ALTER USER postgres WITH PASSWORD 'mmuser-password'; # 修改密码为mmuser-password
postgres=# create database mattermost_test; # 创建"mattermost_test"数据库
postgres=# \q # 退出PostgreSQL psql客户端
pgsql其他操作:
$ sudo passwd -d postgres # 清空指定用户'PostgreSQL'的密码
passwd: password expiry information changed.
2.安装、配置mattermost
2.1下载mattermost 安装文件
$ wget https://releases.mattermost.com/6.7.0/mattermost-6.7.0-linux-amd64.tar.gz # 下载最新版本的 Mattermost 服务器
$ tar -xvzf mattermost*.gz # 提取 Mattermost 服务器文件
$ sudo mv mattermost /opt # 将提取的文件移动到/opt目录
$ sudo mkdir /opt/mattermost/data # 创建文件的存储目录
$ sudo useradd --system --user-group mattermost # 创建Mattermost用户和组
$ sudo chown -R mattermost:mattermost /opt/mattermost # 将用户和组mattermost设置为 Mattermost 文件的所有者
$ sudo chmod -R g+w /opt/mattermost # 给 '所属组' 授予 '写入' 权限
2.2修改mattermost 配置文件
2.2.1修改配置文件连接至 mysql数据库
设置 "DriverName" 为 "mysql" ,
设置 "DataSource" 中的mmuser 、 <mmuser-password> 和tcp(<host-name-or-IP>:3306) 的值:
"mmuser:<mmuser-password>@tcp<host-name-or-IP>:3306/mattermost?charset=ytf8mb4,utf8&readTimeout=30s&writeTimeout=30s",
修改后
$ vim /opt/mattermost/config/config.json # 修改配置文件
-- >
# (大约在129行)
"DriverName": "mysql",
"DataSource": "mmuser:mmuser-password@tcp(localhost:3306)/mattermost?charset=ytf8mb4,utf8&readTimeout=30s&writeTimeout=30s",
2.2.2修改配置文件连接至 PostgreSQL 数据库
设置 "DriverName" 为 "postgres" ,
设置 "DataSource" 中的mmuser 、 <mmuser-password> 和<host-name-or-IP> 的值:
"postgres://mmuser:<mmuser-password>@<host-name-or-IP>:5432/mattermost?sslmode=disable&connect_timeout=10",
修改后
$ vim /opt/mattermost/config/config.json # 修改配置文件
-- >
# (大约在129行)
"DriverName": "postgres",
"DataSource": "postgres://mmuser:<mmuser-password>@<host-name-or-IP>:5432/mattermost?sslmode=disable&connect_timeout=10&binary_parameters=yes",
启动 mattermost 服务,测试其是否可以正常运行(web端口为8065,一般访问地址为:http://127.0.0.1:8065)
$ cd /opt/mattermost # 切换到 Mattermost 目录
$ sudo -u mattermost bin/mattermost # 以用户 mattermost 启动 Mattermost 服务器
2.3设置mattermost自启动系统服务
$ sudo touch /lib/systemd/system/mattermost.service # 创建systemd服务
$ sudo vim /lib/systemd/system/mattermost.service # 编辑内容
-- >
# 将以下内容复制到文件中
[Unit]
Description=Mattermost
After=network.target
After=mysql.service
BindsTo=mysql.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
$ sudo systemctl daemon-reload # 使用systemd加载新服务
$ sudo systemctl status mattermost.service # 查看mattermost服务状态
-- >
mattermost.service - Mattermost
Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
Active: inactive (dead)
$ sudo systemctl start mattermost.service # 启动服务
$ curl http://localhost:8065 # 验证mattermost是否正在运行,正常情况下会获取到html信息
$ sudo systemctl enable mattermost.service # 设置mattermost服务在开机时自启

浙公网安备 33010602011771号