在1至3臺機器上安裝生產就緒的Mattermost系統。
完整的Mattermost安裝由三個主要組件組成:代理服務器,數據庫服務器和Mattermost服務器。 您可以在一臺機器上安裝所有組件,也可以在每臺機器上安裝每個組件。 如果您只有兩臺計算機,請在一臺計算機上安裝代理和Mattermost服務器,然后在另一臺計算機上安裝數據庫。
對于數據庫,您可以安裝MySQL或PostgreSQL。 代理是NGINX。
按以下順序安裝和配置組件。 請注意,您只需要一個數據庫,即MySQL或PostgreSQL。
- 安裝Ubuntu Server 16.04 LTS
- 安裝MySQL數據庫服務器
- 安裝PostgreSQL數據庫服務器
- 安裝Mattermost服務器
- 配置Mattermost服務器
- 在Mattermost服務器上配置TLS
- 安裝NGINX服務器
- 將NGINX配置為Mattermost服務器的代理
- 使用SSL和HTTP / 2配置NGINX
1. 安裝Ubuntu Server 16.04 LTS
在托管一個或多個組件的每臺機器上安裝64位版本的Ubuntu Server。
安裝Ubuntu Server 16.04
- 要安裝Ubuntu Server 16.04,請參閱Ubuntu安裝指南。
- 系統安裝完成后,確保是最新的安全補丁。 打開終端窗口并輸入以下命令:
sudo apt-get update
sudo apt-get upgrade
系統更新后,可以開始安裝構成Mattermost系統的組件。
2. 安裝MySQL數據庫服務器
安裝并設置數據庫以供Mattermost服務器使用。 您可以選擇安裝MySQL或PostgreSQL。
在Ubuntu Server 16.04上安裝MySQL
- 登錄到將要托管數據庫的服務器,并打開一個終端窗口。
- 安裝MySQL。
sudo apt-get install mysql-server
在安裝過程中,系統會提示您為MySQL根用戶創建一個密碼。 記下密碼,因為您將在下一步中使用密碼。
以root身份登錄到MySQL。
mysql -u root -p
當提示出現時,輸入安裝MySQL時創建的根密碼。創建Mattermost用戶'mmuser'。
mysql> create user 'mmuser'@'%' identified by 'mmuser-password';
- 使用比“mmuser-password”更安全的密碼。
- '%'表示mmuser可以從網絡上的任何機器連接。 但是,使用托管Mattermost的計算機的IP地址更安全。 例如,如果您在IP地址為10.10.10.2的計算機上安裝了Mattermost,請使用以下命令:
mysql> create user 'mmuser'@'10.10.10.2' identified by 'mmuser-password';
這里的mmuser-password
在后文還會用到,當時我換成了123456,導致認證MySQL失敗。
- 創建Mattermost數據庫。
mysql> create database mattermost;
- 授予用戶“mmuser”的訪問權限。
mysql> grant all privileges on mattermost.* to 'mmuser'@'%';
- 注銷MySQL。
mysql> exit
在安裝完數據庫并完成初始設置之后,您現在可以安裝Mattermost服務器。
3. 安裝PostgreSQL數據庫服務器
TODO
4. 安裝Mattermost服務器
在64位機器上安裝Mattermost Server。
假設該服務器的IP地址為10.10.10.2。
在Ubuntu上安裝Mattermost服務器
- 登錄到將要托管Mattermost Server的服務器并打開一個終端窗口。
- 下載最新版本的Mattermost服務器。 在下面的命令中,將X.X.X替換為要下載的版本:
wget https://releases.mattermost.com/X.X.X/mattermost-X.X.X-linux-amd64.tar.gz
- 提取Mattermost服務器文件。
tar -xvzf mattermost*.gz
- 將提取的文件移至
/opt
目錄。
sudo mv mattermost /opt
- 創建文件的存儲目錄。
sudo mkdir /opt/mattermost/data
存儲目錄將包含用戶發布到Mattermost的所有文件和圖像,因此您需要確保該驅動器足夠大以容納預期數量的上傳文件和圖像。
- 設置一個名為
mattermost
的系統用戶和組將運行此服務,并設置所有權和權限。
a. 創建Mattermost用戶和組:
sudo useradd --system --user-group mattermost
b. 將用戶和組mattermost設置為Mattermost文件的所有者:
sudo chown -R mattermost:mattermost /opt/mattermost
c. 給mattermost組寫入權限:
sudo chmod -R g+w /opt/mattermost
- 在文件
/opt/mattermost/config/config.json
中設置數據庫驅動程序。 在文本編輯器中打開文件并進行以下更改:-
如果您使用PostgreSQL:
- 將
DriverName
設置為postgres
- 將
DataSource
設置為以下值,用適當的值替換<mmuser-password>
和<host-name-or-IP>
:
"postgres://mmuser:<mmuser-password>@<host-name-or-IP>:5432/mattermost?sslmode=disable&connect_timeout=10"
- 將
-
如果您使用MySQL:
- 將
DriverName
設置為postgres
- 將
DataSource
設置為以下值,用適當的值替換<mmuser-password>
和<host-name-or-IP>
:
mmuser:<mmuser-password>@tcp(<host-name-or-IP>:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s
<mmuser-password>
換成mmuser-password
(基于上文設定:)),將<host-name-or-IP>
換成127.0.0.1
(因為我的Mattermost服務器和MySQL服務器安裝在一臺服務器上面)。 - 將
-
- 測試Mattermost服務器以確保一切正常。
a. 切換到bin
目錄:
cd /opt/mattermost/bin
b. 以用戶mattermost身份啟動Mattermost服務器:
sudo -u mattermost ./platform
當服務器啟動時,會顯示一些日志信息,Server is listening on :8065
。 您可以通過在終端窗口中按CTRL+C來停止服務器。 - 設置Mattermost使用systemd啟動和停止。
a. 創建一個systemd單元文件:
sudo touch /lib/systemd/system/mattermost.service
b. 在文本編輯器中以root身份打開單元文件,并將以下行復制到文件中:
[Unit]
Description=Mattermost
After=network.target
After=postgresql.service
Requires=postgresql.service
[Service]
Type=simple
ExecStart=/opt/mattermost/bin/platform
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target
如果你正在使用MySQL,請在[Unit]部分的2個地方用mysql.service替換postgresql.service。
c. 使systemd加載新的單元。
`sudo systemctl daemon-reload`
d. 檢查以確保裝置已裝入。
`sudo systemctl status mattermost.service`
您應該看到類似于以下的輸出:
● mattermost.service - Mattermost
Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
Active: inactive (dead)
e. 開始服務。
`sudo systemctl start mattermost.service`
f. 驗證Mattermost正在運行。
`curl http://localhost:8065`
您應該可以看到Mattermost服務器返回的HTML。
g. 設置Mattermost在機器啟動時啟動。
`sudo systemctl enable mattermost.service`
現在,Mattermost服務器已啟動并運行,您可以執行一些初始配置和設置。
5. 配置Mattermost服務器
創建System Admin用戶并設置Mattermost作為一般用途。
打開瀏覽器并導航到您的Mattermost實例。 例如,如果Mattermost服務器的IP地址是
10.10.10.2
,則請轉到http://10.10.10.2:8065
。創建第一個團隊和用戶。 系統中的第一個用戶具有
system_admin
角色,可以訪問系統控制臺。打開系統控制臺。 要打開系統控制臺,請單擊導航面板頂部的用戶名,然后在打開的菜單中單擊系統控制臺。
設置網站網址:
a. 在“系統控制臺”的GENERAL部分中,單擊Configuration。
b. 在Site URL字段中,設置用戶指向其瀏覽器的網址。 例如,https://mattermost.example.com。 如果您使用HTTPS,請確保您在Mattermost服務器或代理上設置TLS。-
設置電子郵件通知。
a. 在系統控制臺的NOTIFICATIONS部分中,單擊Email并進行以下更改:
- Set Enable Email Notifications to true
- Set Notification Display Name to No-Reply
- Set Notification From Address to {your-domain-name} For example, example.com
- Set SMTP Server Username to {SMTP-username} For example, admin@example.com
- Set SMTP Server Password to {SMTP-password}
- Set SMTP Server to {SMTP-server} For example, mail.example.com
- Set SMTP Server Port to 465
- Set Connection Security to TLS or STARTTLS, depending on what the SMTP server accepts.b. 點擊Test Connection。
c. 連接完成后,點擊Save。 設置文件和圖像存儲位置。
a. 在“系統控制臺”的FILES部分中,單擊Storage。
b. 如果您在本地存儲文件,請將File Storage System設置為Local File System,然后接受Local Storage Directory的默認值或輸入位置。 該位置必須是存在的目錄,并具有Mattermost服務器的寫入權限。 它可以是絕對路徑或相對路徑。 相對路徑是相對于mattermost
目錄。
c. 如果您將文件存儲在Amazon S3上,請將文件存儲系統設置為Amazon S3并為您的Amazon帳戶輸入適當的值。
d. 點擊Save。
- 用戶附加到消息的文件和圖像不存儲在數據庫中。 而是將它們存儲在您指定的位置。 您可以將文件存儲在本地文件系統或Amazon S3中。
- 確保該位置有足夠的可用空間。 所需的存儲量取決于用戶的數量以及用戶附加到郵件的文件的數量和大小。
- 查看系統控制臺中的其他設置,確保一切都按照您的要求進行。
- 重新啟動Mattermost服務。
在Ubuntu 14.04和RHEL 6.6上:
sudo restart mattermost
在Ubuntu 16.04, Debian Jessie, 和RHEL 7.1上:
sudo systemctl restart mattermost
6. 在Mattermost服務器上配置TLS
如果您希望用戶使用HTTPS連接,則有兩個選項:
- 在Mattermost服務器上設置TLS。
- 安裝代理(如NGINX)并在代理上設置TLS。
最簡單的方法是在Mattermost服務器上設置TLS,但如果您希望有超過200個用戶,請使用代理來獲得更好的性能。 代理服務器還提供標準的HTTP請求日志。
6.1 在Mattermost服務器上配置TLS:
-
System Console > General > Configuration。
a. Change the Listen Address setting to :443.
b. Change the Connection Security setting to TLS.
c. Change the Forward port 80 to 443 setting to true. - 激活
CAP_NET_BIND_SERVICE
功能,允許Mattermost綁定到低端口。
a. 打開終端窗口并切換到Mattermostbin
目錄。
cd /opt/mattermost/bin
b. 運行下列命令:
sudo setcap cap_net_bind_service=+ep ./platform
- 安裝安全證書。 您可以使用Let's Encrypt自動安裝和設置證書,也可以指定自己的證書。
-
要使用Let's Encrypt證書:
第一次客戶端嘗試連接到Mattermost服務器時檢索證書。 檢索客戶端嘗試訪問服務器的任何主機名的證書。
a. Change the Use Let’s Encrypt setting to true.
b. Restart the Mattermost server for these changes to take effect. - 指定自己的證書
a. Change the Use Let’s Encrypt setting to false.
b. Change the TLS Certificate File setting to the location of the certificate file.
c. Change the TLS Key File setting to the location of the private key file.
d. Restart the Mattermost server for these changes to take effect.
-
要使用Let's Encrypt證書:
7. 安裝NGINX服務器
在生產環境中,使用代理服務器來提高Mattermost的安全性和性能。
使用代理的主要好處如下:
- SSL termination
- HTTP to HTTPS redirect
- Port mapping
:80
to:8065
- Standard request logs
在Ubuntu服務器上安裝NGINX:
- 登錄到承載代理的服務器并打開一個終端窗口。
- 安裝NGINX.
sudo apt-get install nginx
- 安裝完成后,確認NGINX正在運行。
curl http://localhost
如果NGINX正在運行,您會看到以下輸出:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
.
.
.
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
您可以使用以下命令停止,啟動并重新啟動NGINX:
sudo service nginx stop sudo service nginx start sudo service nginx restart
下一步
- 映射完全限定的域名(FQDN),如mattermost.example.com指向NGINX服務器。
- 配置NGINX代理連接從互聯網到Mattermost服務器。
8. 將NGINX配置為Mattermost服務器的代理
NGINX使用/etc/nginx/sites-available
目錄中的文件進行配置。 您需要創建該文件,然后啟用它。 創建文件時,需要Mattermost服務器的IP地址和Mattermost網站的完全限定域名(FQDN)。
將NGINX配置為代理
- 登錄到承載NGINX的服務器并打開一個終端窗口。
- 為Mattermost創建一個配置文件。
sudo touch /etc/nginx/sites-available/mattermost
- 在文本編輯器中以root用戶身份打開
/etc/nginx/sites-available/mattermost
文件,并使用以下行替換其內容(如果有)。 確保您使用您自己的值作為server_name的Mattermost服務器IP地址和FQDN。
upstream backend {
server 10.10.10.2:8065;
}
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;
proxy_read_timeout 600s;
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;
}
}
- 刪除現有默認的啟用站點的文件。
sudo rm /etc/nginx/sites-enabled/default
- 啟用mattermost配置。
sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/mattermost
- 重啟NGINX。
在Ubuntu 14.04和RHEL 6.6:sudo service nginx restart
在Ubuntu 16.04, Debian Jessie,和RHEL 7.1上:sudo systemctl restart nginx
- 驗證你可以通過代理訪問Mattermost。
curl http://localhost
如果一切正常,您將看到Mattermost注冊頁面的HTML。 - 限制對端口8065的訪問。
默認情況下,Mattermost服務器接受來自網絡上每臺計算機的端口8065上的連接。 除了承載NGINX的機器和用于管理Mattermost服務器的機器之外,使用防火墻拒絕8065端口上的連接。 如果您在Amazon Web Services上安裝,則可以使用安全組來限制訪問。
現在NGINX已經安裝并運行了,你可以配置它使用SSL,它允許你使用HTTPS連接和HTTP/2協議。
11. 使用SSL和HTTP/2配置NGINX
使用SSL通過確保Mattermost客戶端和Mattermost服務器之間的通信被加密,從而提供更高的安全性。 它也允許你配置NGINX使用HTTP / 2協議。
盡管您可以配置不使用SSL的HTTP / 2,但Firefox和Chrome瀏覽器僅支持安全連接上的HTTP / 2。
您可以使用任何您想要的證書,但是這些說明將告訴您如何從Let's Encrypt(一個免費的證書頒發機構)下載并安裝證書。
配置SSL和HTTP/2:
- 登錄到承載NGINX的服務器并打開一個終端窗口。
- 安裝git。
如果你使用Ubuntu或者Debian:
sudo apt-get install git
如果你使用RHEL:
sudo yum install git
- 克隆GitHub上的Let's Encrypt存儲庫。
git clone https://github.com/letsencrypt/letsencrypt
- 切換到
letsencrypt
目錄。
cd letsencrypt
- 停止NGINX
Ubuntu 14.04和RHEL 6.6:
sudo service nginx stop
Ubuntu 16.04和RHEL 7.1:
sudo systemctl stop nginx
- 運行
netstat
以確保沒有任何內容正在偵聽端口80。
netstat -na | grep ':80.*LISTEN'
- 運行Let's Encrypt安裝程序。
./letsencrypt-auto certonly --standalone
出現提示時,輸入您的域名。 安裝完成后,您可以在/etc/letsencrypt/live
目錄中找到證書。 - 在文本編輯器中以root用戶身份打開文件
/etc/nginx/sites-available/mattermost
,并更新服務器部分,以將高亮顯示的行合并到以下示例中。 請務必在3個地方將{domain-name}替換為您自己的域名。
.
.
.
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 default_server;
server_name {domain-name} ;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name {domain-name} ;
ssl on;
ssl_certificate /etc/letsencrypt/live/{domain-name}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{domain-name}/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_set_header Upgrade $http_upgrade;
.
.
.
location / {
proxy_http_version 1.1;
.
.
.
- 重啟NGINX.
Ubuntu 14.04和RHEL 6.6:
sudo service nginx start
Ubuntu 16.04和RHEL 7.1:
sudo systemctl start nginx
- 檢查您的SSL證書設置是否正確。
- 通過訪問諸如https://www.ssllabs.com/ssltest/index.html的站點來測試SSL證書
- 如果關于鏈路或證書路徑丟失有錯誤,則可能缺少需要包含的中間證書。
- 配置
cron
,以便證書每個月都會自動更新
crontab -e
在以下行中,使用您自己的域名替換{domain-name}
@monthly /home/ubuntu/letsencrypt/letsencrypt-auto certonly --reinstall --nginx -d {domain-name} && sudo service nginx reload