ติดตั้ง Mattermost ระบบแชททีมงานบนเซิร์ฟเวอร์ตัวเอง
บริการแชทสำเร็จรูปแบบฟรีมักจำกัดประวัติข้อความย้อนหลัง ซึ่งเป็นปัญหาเมื่อต้องการค้นหาข้อตกลงที่คุยกันไว้เมื่อหลายเดือนก่อน Mattermost ทำงานบนเซิร์ฟเวอร์ของคุณเอง จึงเก็บประวัติได้ไม่จำกัดและข้อมูลไม่ออกนอกองค์กร
หน้าตาและการใช้งานคล้ายกับโปรแกรมแชทที่ทีมพัฒนาคุ้นเคย มีแอปสำหรับทุกแพลตฟอร์ม และเชื่อมกับระบบอื่นผ่าน Webhook ได้
สิ่งที่ต้องเตรียม
- Cloud VPS ที่มี RAM อย่างน้อย 2 GB
- โดเมนที่ชี้มาที่เซิร์ฟเวอร์
- บัญชี SMTP สำหรับส่งอีเมลเชิญและรีเซ็ตรหัสผ่าน
ขั้นตอนที่ 1: เตรียมไฟล์
sudo mkdir -p /opt/mattermost/{config,data,logs,plugins,client-plugins,bleve-indexes,db}
sudo chown -R 2000:2000 /opt/mattermost/{config,data,logs,plugins,client-plugins,bleve-indexes}
cd /opt/mattermost
sudo nano .env
DOMAIN=chat.example.com
POSTGRES_USER=mmuser
POSTGRES_PASSWORD=รหัสผ่านที่ยาวและสุ่ม
POSTGRES_DB=mattermost
sudo chmod 600 .env
sudo nano docker-compose.yml
services:
db:
image: postgres:16-alpine
restart: unless-stopped
volumes:
- ./db:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 10s
retries: 5
mattermost:
image: mattermost/mattermost-team-edition:latest
restart: unless-stopped
depends_on:
db:
condition: service_healthy
ports:
- "127.0.0.1:8065:8065"
volumes:
- ./config:/mattermost/config
- ./data:/mattermost/data
- ./logs:/mattermost/logs
- ./plugins:/mattermost/plugins
- ./client-plugins:/mattermost/client/plugins
- ./bleve-indexes:/mattermost/bleve-indexes
environment:
TZ: Asia/Bangkok
MM_SQLSETTINGS_DRIVERNAME: postgres
MM_SQLSETTINGS_DATASOURCE: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable&connect_timeout=10
MM_SERVICESETTINGS_SITEURL: https://${DOMAIN}
MM_BLEVESETTINGS_INDEXDIR: /mattermost/bleve-indexes
MM_FILESETTINGS_MAXFILESIZE: 104857600
sudo docker compose up -d
sudo docker compose logs -f mattermost
ขั้นตอนที่ 2: ตั้ง Nginx และ SSL
sudo nano /etc/nginx/sites-available/mattermost
upstream mattermost {
server 127.0.0.1:8065;
keepalive 32;
}
server {
listen 80;
server_name chat.example.com;
client_max_body_size 100M;
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_pass http://mattermost;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $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_read_timeout 600s;
}
location / {
proxy_pass http://mattermost;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $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_read_timeout 600s;
}
}
sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d chat.example.com --agree-tos -m [email protected] --redirect
บล็อกแยกสำหรับ WebSocket จำเป็น ไม่เช่นนั้นข้อความใหม่จะไม่ขึ้นจนกว่าจะรีเฟรชหน้า
ขั้นตอนที่ 3: ตั้งค่าครั้งแรก
เปิด https://chat.example.com บัญชีแรกที่สมัครจะกลายเป็นผู้ดูแลระบบอัตโนมัติ สร้างทีมแล้วเข้าหน้า System Console
สิ่งที่ควรตั้งทันที
- ปิดการสมัครด้วยอีเมลทั่วไป ที่ Authentication แล้ว Signup ตั้ง Enable Account Creation เป็น false แล้วเชิญคนด้วยลิงก์แทน
- จำกัดโดเมนอีเมลที่สมัครได้ เช่น
example.comเท่านั้น - เปิดการยืนยันตัวตนสองขั้นตอน
- ตั้งนโยบายเก็บข้อความย้อนหลังตามที่องค์กรกำหนด
ขั้นตอนที่ 4: ตั้งอีเมล
ใน System Console แล้ว Environment แล้ว SMTP
SMTP Server: smtp.example.com
SMTP Port: 587
Connection Security: STARTTLS
Enable SMTP Authentication: true
SMTP Username: [email protected]
SMTP Password: รหัสผ่าน
Notification From Address: [email protected]
กดปุ่ม Test Connection เพื่อยืนยัน อีเมลจำเป็นสำหรับการเชิญสมาชิกและรีเซ็ตรหัสผ่าน หากไม่ตั้งจะใช้งานลำบากมาก
ขั้นตอนที่ 5: เชื่อมกับระบบอื่นด้วย Webhook
ที่เมนู Integrations แล้ว Incoming Webhooks สร้างใหม่ เลือกช่องที่จะส่งเข้า แล้วคัดลอก URL
curl -X POST -H 'Content-Type: application/json' \
-d '{"text":"เซิร์ฟเวอร์ web1 ใช้ดิสก์เกิน 85% แล้ว","username":"monitor","icon_emoji":":warning:"}' \
https://chat.example.com/hooks/xxxxxxxxxxxxxxxxx
ใช้ร่วมกับระบบเฝ้าระวังได้ทันที เช่น ตั้งเป็น Contact point ใน Grafana หรือเรียกจากสคริปต์สำรองข้อมูลเมื่อเกิดข้อผิดพลาด
ส่งข้อความที่มีรูปแบบสวยงามด้วย attachment
curl -X POST -H 'Content-Type: application/json' -d '{
"attachments": [{
"color": "#FF0000",
"title": "เว็บไซต์ล่ม",
"text": "example.com ไม่ตอบสนองตั้งแต่ 14:05 น.",
"fields": [
{"short": true, "title": "เซิร์ฟเวอร์", "value": "web1"},
{"short": true, "title": "สถานะ", "value": "503"}
]
}]
}' https://chat.example.com/hooks/xxxxxxxxxxxxxxxxx
ขั้นตอนที่ 6: สำรองข้อมูล
sudo nano /usr/local/bin/mattermost-backup.sh
#!/bin/bash
set -euo pipefail
cd /opt/mattermost
source .env
DEST=/var/backups/mattermost
STAMP=$(date +%F-%H%M)
mkdir -p "$DEST"
docker compose exec -T db pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB" \
| gzip > "$DEST/db-$STAMP.sql.gz"
tar czf "$DEST/config-$STAMP.tar.gz" ./config
# ไฟล์แนบ ใช้ restic เพราะโตขึ้นเรื่อย ๆ
restic backup /opt/mattermost/data --tag mattermost
find "$DEST" -name '*.gz' -mtime +30 -delete
echo "mattermost backup ok: $STAMP"
ขั้นตอนที่ 7: อัปเดต
cd /opt/mattermost
sudo /usr/local/bin/mattermost-backup.sh
sudo docker compose pull
sudo docker compose up -d
sudo docker compose logs -f mattermost
อ่านบันทึกการเปลี่ยนแปลงก่อนเสมอ และอัปเดตทีละรุ่นหลักเช่นเดียวกับระบบอื่น
ปัญหาที่พบบ่อย
ข้อความใหม่ไม่ขึ้นจนกว่าจะรีเฟรช
WebSocket ไม่ทำงาน ตรวจบล็อก location ~ /api/v[0-9]+/(users/)?websocket$ ใน Nginx ตามขั้นตอนที่ 2
อัปโหลดไฟล์ไม่ได้
ตรวจสองที่ client_max_body_size ใน Nginx และ MM_FILESETTINGS_MAXFILESIZE ในคอนฟิก ต้องตั้งให้สอดคล้องกัน
ค้นหาข้อความภาษาไทยไม่เจอ
ตัวค้นหาเริ่มต้นแยกคำภาษาไทยได้ไม่ดี เปิด Bleve Search ใน System Console แล้ว Environment แล้ว Bleve ซึ่งตั้ง index dir ไว้แล้วในคอนฟิก แล้วสั่งสร้างดัชนีใหม่
สิทธิ์ของโฟลเดอร์ผิดพลาดตอนเริ่ม
คอนเทนเนอร์รันด้วยผู้ใช้ id 2000 ตั้งเจ้าของให้ถูกต้องด้วย sudo chown -R 2000:2000 /opt/mattermost/{config,data,logs,plugins,client-plugins}
ต้องการ Cloud VPS สำหรับระบบสื่อสารภายในองค์กร ติดต่อ THAI DATA CLOUD ได้ที่ https://thaidata.cloud/contact/
- Categories:
- Cloud
- Tags:
- Cloud
- Cloud Server
Related Posts
หมวดหมู่ที่น่าสนใจ
- Account Settings
- AD Server
- AI
- Alibaba Cloud
- Anti-Spam Gateway
- AWS Amazon Web Services
- Campaign
- CentOS/AlmaLinux
- Cloud
- Cloud Backup
- Cloud Communication
- Cloud Migration
- Cloud Security
- Cloud Server Management
- Cloud Solution
- Cloud Solution for Government
- Cloud Solutions by Industry
- Cloud Storage
- Cloud VPS App Plus +
- Cloud VPS DirectAdmin
- Cloud VPS Plesk
- CSR
- Cyber Security
- Cybersecurity
- Data Sovereignty
- Database Server
- DDoS
- Digital Tranformation
- Digital Transformation
- Direct Mail
- Directadmin
- Domainname
- Ecommerce
- ERP
- Generative AI
- Getting Started
- Google Cloud
- Google G Suite
- Huawei Cloud
- IT News
- Linux Server
- Managed Cloud Services
- Managed Service Provider
- Manual
- Microsoft
- Microsoft 365
- Microsoft Azure
- News
- On-premise
- Private Mail Server
- Promotion
- Recommend Solution (Enterprise)
- Server
- Sovereign Cloud
- THAI DATA CLOUD Platform
- Ubuntu
- Ubuntu
- Uncategorized
- VMware
- VPS Server
- Web Design
- Web Hosting
- Web Hosting (DirectAdmin)
- Web Hosting (Plesk)
- Web Technologies
- Windows Server
- Wordpress
- Zimbra
- เรื่องราวความประทับใจ
- โซลูชันสำหรับธุรกิจการผลิตและยานยนต์
- โซลูชันสำหรับธุรกิจการศึกษา
- โซลูชันสำหรับธุรกิจการเงิน
- โซลูชันสำหรับธุรกิจขนส่งและกระจายสินค้า
- โซลูชันสำหรับธุรกิจค้าปลีก
- โซลูชันสำหรับธุรกิจท่องเที่ยว
- โซลูชันสำหรับธุรกิจบริการสุขภาพและโรงพยาบาล
- โซลูชันสำหรับธุรกิจประกันภัย
- โซลูชันสำหรับธุรกิจพลังงานและสาธารณูปโภค
- โซลูชันสำหรับธุรกิจสื่อสารมวลชนและเอ็นเตอร์เทนเมนท์
- โซลูชันสำหรับธุรกิจอสังหาริมทรัพย์
- โซลูชันสำหรับธุรกิจเทคโนโลยี








