在Ubuntu 16.04 LTS安裝Mattermost(二)

 在Ubuntu 16.04 LTS安裝Mattermost(一)

 在Ubuntu 16.04 LTS安裝Mattermost(二)


配置Mattermost

    創建系統管理員用戶,設置Mattermost的一般用途

    .打開瀏覽器,導航到Mattermost實例.比如:Mattermost服務器IP地址爲10.10.10.10,然後訪問http://10.10.10.10:8065.

    .創建第一個團隊和用戶,第一個用戶是系統管理員(system_admin)角色,有權限訪問系統控制檯

    .打開系統控制檯.點擊導航面板頂部的用戶名,在打開的菜單中,點擊系統控制檯-System Console

    .設置網站URL:

        a.在System Console的GENERAL部分,點擊Configuration.

        b.在Site URL字段中,設置用戶使用瀏覽器訪問的URL.比如:https://mattermost.example.com.

            如果你使用HTTPS,確保在Mattermost服務或者proxy服務設置了TLS

    .設置郵件提醒

        a.在System Console的NOTIFICATIONS部分,點擊Email,然後執行下面幾個步驟

            設置 Enable Email Notification爲 true

            設置Notification Display Name爲 No-Reply

            設置Notification From Address爲{域名},比如, [email protected]

            設置SMTP Server Username爲{SMTP-用戶名},比如,[email protected]

            設置SMTP Server Password爲{SMTP-密碼}

            設置SMTP Server爲{SMTP-服務器} 比如:smtp-mail.outlook.com

            設置SMTP Server Port爲465

            設置Connection Security 爲TLS或者STARTTLS

        b.點擊Test Connection.

        c.連接成功後,點擊Save

           

    .設置文件和圖片存儲位置

        提示:與消息相關的文件和圖片並沒有存儲在數據庫.他們存儲在你所指定的路徑.你可以存儲在本地文件系統或者Amazon S3.

        a.在System Console中的FILES部分,點擊Storage

        b.如果存儲在本地,設置File Storage System爲 Local File System,可以接受默認的Local Storage DIrectory或者輸入指定路徑.這個路徑必須是存在的,並且Mattermost有寫權限.可以是絕對路徑或者相對路徑.相對路徑是相對於mattermost目錄的.

        c.如果存儲在Amazon S3,設置File Storage System爲Amazon S3並且輸入你Amazon賬號

        d.點擊Save保存

    .重啓Mattermost使配置生效

    sudo systemctl restart mattermost


配置TLS

    如果你想要使用HTTPS訪問Mattermost,有兩種選擇

    1.在Mattermost服務器上設置TLS

    2.安裝代理,例如NGINX,然後在代理上設置TLS

    最簡單的選擇是在Mattermost服務器上設置TLS,但是,如果你想要支持200個以上的用戶,使用proxy會有更好的性能和安全.代理服務器也提供了標準的HTTP請求日誌.

    在Mattermost服務器上配置TLS

        .在System Consle > General > Configuration

            a.設置Listem Address爲:443

            b.設置Connection Security爲TLS

            c. 設置Forward port 80 to 443爲true

        .激活CAP_NET_BIND_SERVICE能力,允許Mattermost綁定小數值端口.

            cd  /opt/mattermost/bin

            sudo setcap  cap_net_bind_service==+ep ./platform

        .安裝安全證書

            你可以使用Let's Encrypt自動安裝設置證書,或者指定你自己的證書

             a.使用Let's Encrypt

                設置User Let's Encrypt爲true

                重啓Mattermost,使配置生效

            b.使用自己的證書

                設置User Let's Encrypt爲false

                設置TLS Certificate File 爲證書文件的路徑

                設置TLS Key File爲 私鑰文件的路徑

                重啓Mattermost使這些配置生效               

   在NGINX 代理上設置TLS  

    使用代理的好處: 

        SSL終端 

        HTTP到HTTPS重定向  

        端口映射 :80到:8065  

        標準請求日誌

    .安裝NGINX   

        sudo apt-get install nginx

        驗證是否安裝成功,可以執行下面命令

        curl http://localhost

        如果正常運行,會有下面打印顯示

    <!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服務器

    配置從互聯網到Mattermost服務器的NGINX代理連接

.配置NGINX爲代理

    sudo touch /etc/nginx/sites-available/mattermost

.以root用戶打開/etc/nginx/sites-available/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;
   }
}

    .刪除已存在的默認sites-enabled文件 

        sudo  rm /etc/nginx/sites-enabled/default

    .啓用mattermost配置

    sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/mattermost

   . 重啓nginx使配置生效

        sudo systemctl restart nginx

    .  配置生效後,執行下面命令會看到Mattermost   signup頁面

        curl http://localhost ,

    .限制8065端口的訪問權限

        默認情況下,Mattermost服務器的8065端口接收來自網絡上所有機器的連接.現使用防火牆拒絕所有機器連接8065端口,除了NGINX服務器以及管理Mattermost的服務器.如果你安裝在Amazon Web Services,可以使用安全組來限制訪問


   . 配置SSL和HTTP/2

      你可以使用你想要的任何證書,但在這裏只展示如何從Let's Encrypt下載和安裝證書,免費的證書授權

        a.安裝git 

            sudo apt-get install git

        b.下載

            git clone https://github.com/letsencrypt/letsencrypt

        c.切換目錄

            cd letsencryp

        d.停止NGINX

            sudo service nginx stop 或者 sudo systemctl stop nginx

        e,確保沒有監聽80端口

            netstat -na | grep ':80.*LISTEN'

        f.安裝letscrypt

            ./letsencrypt-auto certonly --standalone

            提示時,輸入你的域名.安裝完成後,你可以在/etc/letsencrypt/live目錄下找到證書

   g.以root用戶打開/etc/nginx/sites-available/mattermost,更新 下面加粗的幾行,確保域名已經切換成

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;

   

h.重啓NGINX

sudo systemctl restart NGINX

i.檢查SSL證書是否安裝正確

    通過訪問https://www.ssllabs.com/ssltest/index.html來測試SSL證書

如果丟失鏈或證書路徑有錯誤,則可能需要缺少中間證書。

j .配置cron,每個月自動更新證書

crontab -e

用你的域名替換掉{domain-name}

    @monthly /home/ubuntu/letsencrypt/letsencrypt-auto certonly --reinstall --nginx -d {domain-name} && sudo service nginx reload






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章