웹사이트 검색

Ubuntu 22.04에 Mattermost 팀 메시징 시스템을 설치하는 방법


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 20.04(Focal Fossa)

이 페이지에서

  1. 전제 조건
  2. 1단계 - 방화벽 구성\n
  3. 2단계 - PostgreSQL 설치
  4. 3단계 - PostgreSQL 구성
  5. 4단계 - Mattermost 다운로드
  6. 5단계 - Mattermost에 대한 시스템 사용자 생성 및 권한 구성\n
  7. 6단계 - Systemd 단위 파일 만들기
  8. 7단계 - Nginx 설치
  9. 8단계 - SSL 설치
  10. 9단계 - Nginx 구성
  11. 10단계 - Mattermost 서버에 액세스
  12. 11단계 - Mattermost 서버 구성
    1. 이메일 알림 구성

    Mattermost는 채팅, 파일 공유, 프로젝트 관리 및 워크플로우 오케스트레이션에 사용되는 오픈 소스 메시징 플랫폼입니다. Go 언어로 작성되었습니다. 클라우드 호스팅 솔루션과 자체 호스팅 서버로 제공됩니다. Slack 및 기타 전문 플랫폼의 대안입니다. 서버에서 호스팅하는 기능을 통해 통신 및 민감한 데이터를 제어할 수 있습니다.

    이 자습서에서는 Ubuntu 22.04 서버에 Mattermost Team Messaging System을 설치하는 방법을 배웁니다.

    전제 조건

    • A server running Ubuntu 22.04 with a minimum of 2 GB of RAM for up to 1000 users.

    • A non-root user with sudo privileges.

    • The Uncomplicated Firewall(UFW) is enabled and running.

    • A Fully Qualified domain name pointed to the server. For our tutorial, we will be using the domain mattermost.example.com.

    • Everything is updated.

      $ sudo apt update && sudo apt upgrade
      

    1단계 - 방화벽 구성

    패키지를 설치하기 전 첫 번째 단계는 HTTP 및 HTTPS 연결을 허용하도록 방화벽을 구성하는 것입니다.

    방화벽의 상태를 확인하십시오.

    $ sudo ufw status
    

    다음과 같은 내용이 표시되어야 합니다.

    Status: active
    
    To                         Action      From
    --                         ------      ----
    OpenSSH                    ALLOW       Anywhere
    OpenSSH (v6)               ALLOW       Anywhere (v6)
    

    포트 8065는 Mattermost에 필요합니다. 이 포트는 설치를 확인하기 위해 일시적으로만 열면 됩니다. 나중에 제거하겠습니다.

    $ sudo ufw allow 8065
    

    HTTP 및 HTTP 포트를 허용합니다.

    $ sudo ufw allow http
    $ sudo ufw allow https
    

    상태를 다시 확인하여 확인하십시오.

    $ sudo ufw status
    Status: active
    
    To                         Action      From
    --                         ------      ----
    OpenSSH                    ALLOW       Anywhere
    80/tcp                     ALLOW       Anywhere
    443                        ALLOW       Anywhere
    8065                       ALLOW       Anywhere
    OpenSSH (v6)               ALLOW       Anywhere (v6)
    80/tcp (v6)                ALLOW       Anywhere (v6)
    443 (v6)                   ALLOW       Anywhere (v6)
    8065 (v6)                  ALLOW       Anywhere (v6)
    

    2단계 - PostgreSQL 설치

    Mattermost는 MySQL 및 PostgreSQL 서버 모두에서 작동할 수 있지만 PostgreSQL이 권장되는 선택입니다.

    Ubuntu 22.04는 PostgreSQL의 안정적인 최신(v14) 버전과 함께 제공됩니다. 단일 명령으로 설치할 수 있습니다.

    $ sudo apt install postgresql postgresql-contrib
    

    MySQL의 버전을 확인하십시오.

    $ psql --version
    psql (PostgreSQL) 14.4 (Ubuntu 14.4-0ubuntu0.22.04.1)
    

    3단계 - PostgreSQL 구성

    PostgreSQL은 설치 중에 Linux 사용자 계정 postgres를 생성합니다. PostgreSQL 셸은 이 계정을 사용하여 액세스할 수 있습니다.

    PostgreSQL 셸에 로그인합니다.

    $ sudo -u postgres psql
    

    Mattermost 데이터베이스를 생성합니다.

    postgres=# CREATE DATABASE mattermostdb;
    

    Mattermost 데이터베이스 사용자를 생성합니다. mmuser-password를 원하는 더 강력한 암호로 바꾸십시오.

    postgres=# CREATE USER mmuser WITH PASSWORD 'mmuser-password';
    

    데이터베이스에 대한 모든 권한을 사용자에게 부여합니다.

    postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
    

    셸에 \\q를 입력하여 PostgreSQL 셸을 종료합니다.

    postgres=# \q
    

    편집을 위해 /etc/postgresql/{version}/main/pg_hba.conf 파일을 엽니다.

    $ sudo nano /etc/postgresql/{version}/main/pg_hba.conf
    

    다음 줄을 찾으십시오.

    # "local" is for Unix domain socket connections only
    local   all             all                                     peer
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            scram-sha-256
    # IPv6 local connections:
    host    all             all             ::1/128                 scram-sha-256
    

    위 줄에서 peerscram-sha-256 값을 trust로 변경합니다.

    # "local" is for Unix domain socket connections only
    local   all             all                                     trust
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            trust
    # IPv6 local connections:
    host    all             all             ::1/128                 trust
    

    Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.

    PostgreSQL 서비스를 다시 시작하여 변경 사항을 활성화하십시오.

    $ sudo systemctl restart postgresql
    

    Mattermost SQL 사용자에 연결할 수 있는지 확인합니다.

    $ psql --dbname=mattermost --username=mmuser --password
    

    비밀번호를 입력하라는 메시지가 표시됩니다. 입력하면 PostgreSQL 셸에 로그인됩니다. \\q를 입력하여 셸을 종료합니다.

    Password:
    psql (14.4 (Ubuntu 14.4-0ubuntu0.22.04.1))
    Type "help" for help.
    
    mattermost-> \q
    

    4단계 - Mattermost 다운로드

    최신 버전의 Mattermost 서버를 다운로드합니다. 이 튜토리얼을 작성할 당시 사용 가능한 최신 버전은 7.0.1입니다.

    $ wget https://releases.mattermost.com/7.0.1/mattermost-7.0.1-linux-amd64.tar.gz
    

    아카이브를 추출하십시오.

    $ tar -xvzf mattermost*.gz
    

    추출된 파일을 /opt 디렉터리로 이동합니다.

    $ sudo mv mattermost /opt
    

    Mattermost 서버의 데이터 저장소 디렉터리를 만듭니다.

    $ sudo mkdir /opt/mattermost/data
    

    5단계 - Mattermost에 대한 시스템 사용자 생성 및 권한 구성

    편집을 위해 구성 파일 /opt/mattermost/config/config.json을 엽니다.

    $ sudo nano /opt/mattermost/config/config.json
    

    SiteURL 변수를 설치에 사용할 도메인 이름으로 설정합니다.

    "SiteURL": "https://mattermost.example.com",
    

    SqlSettings 아래에서 변수 DriverName을 찾아 해당 값을 mysql로 변경합니다.

    "DriverName": "mysql",
    

    변수 DataSource를 다음 값으로 설정합니다. mmuser를 SQL 사용자 이름으로, YourPassword23!를 SQL 암호로, mattermostdb를 데이터베이스 이름으로 바꿉니다. , 4단계에서 구성했습니다.

    "DataSource": "mmuser:(localhost:3306)/mattermostdb?charset=utf8mb4,utf8&writeTimeout=30s",
    

    이 시점에서 구성할 수 있는 다른 많은 설정이 있지만 설치 후 수행하는 것이 더 쉬울 것입니다. 지금은 이 두 가지 설정만 필수입니다.

    Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.

    Mattermost 서버에 대한 시스템 사용자 및 그룹을 만듭니다.

    $ sudo useradd --system --user-group mattermost
    

    Mattermost 디렉터리의 소유권을 새로 만든 사용자 및 그룹으로 변경합니다.

    $ sudo chown -R mattermost:mattermost /opt/mattermost
    

    디렉터리의 mattermost 그룹에 쓰기 권한을 부여합니다.

    $ sudo chmod -R g+w /opt/mattermost
    

    Mattermost 디렉터리로 전환합니다.

    $ cd /opt/mattermost
    

    Mattermost 서버를 mattermost 사용자로 시작합니다.

    $ sudo -u mattermost ./bin/mattermost
    

    서버가 시작되고 많은 로그 정보가 생성됩니다. Server is listening on [::]:8065 줄이 나타날 때까지 기다립니다. 브라우저에서 URL http://:8065를 방문하면 다음과 같은 로그인 페이지가 표시됩니다.

    Ctrl + C를 눌러 서버를 중지합니다. 설치를 구성하기 위해 나중에 이 내용으로 돌아갑니다.

    6단계 - Systemd 단위 파일 생성

    다음 단계는 Mattermost에 대한 시스템 파일을 만드는 것입니다.

    편집할 단위 파일을 만들고 엽니다.

    $ sudo nano /lib/systemd/system/mattermost.service
    

    다음 코드를 붙여넣습니다.

    [Unit]
    Description=Mattermost
    After=network.target
    After=postgresql.service
    BindsTo=postgresql.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
    

    Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.

    systemd 데몬을 다시 로드하여 서비스 파일을 로드합니다.

    $ sudo systemctl daemon-reload
    

    Mattermost 서비스를 시작합니다.

    $ sudo systemctl start mattermost
    

    서비스 상태를 확인합니다.

    ? mattermost.service - Mattermost
         Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
         Active: active (running) since Mon 2022-07-11 01:24:46 UTC; 20s ago
       Main PID: 23628 (mattermost)
          Tasks: 48 (limit: 2241)
         Memory: 448.2M
            CPU: 14.929s
         CGroup: /system.slice/mattermost.service
                 ??23628 /opt/mattermost/bin/mattermost
                 ??23651 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
                 ??23656 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64
                 ??23662 plugins/com.mattermost.calls/server/dist/plugin-linux-amd64
                 ??23668 plugins/com.mattermost.apps/server/dist/plugin-linux-amd64
                 ??23674 plugins/playbooks/server/dist/plugin-linux-amd64
                 ??23683 plugins/focalboard/server/dist/plugin-linux-amd64
     ....
    

    서비스를 활성화합니다.

    $ sudo systemctl enable mattermost
    

    7단계 - Nginx 설치

    Ubuntu 22.04는 이전 버전의 Nginx와 함께 제공됩니다. 최신 버전을 설치하려면 공식 Nginx 저장소를 다운로드해야 합니다.

    Nginxs 서명 키를 가져옵니다.

    $ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
    

    Nginxs 안정 버전용 리포지토리를 추가합니다.

    $ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg arch=amd64] \
    http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list
    

    시스템 리포지토리를 업데이트합니다.

    $ sudo apt update
    

    Nginx를 설치합니다.

    $ sudo apt install nginx
    

    설치를 확인하십시오.

    $ nginx -v
    nginx version: nginx/1.22.0
    

    8단계 - SSL 설치

    SSL 인증서를 생성하려면 Certbot을 설치해야 합니다. Ubuntus 저장소를 사용하여 Certbot을 설치하거나 Snapd 도구를 사용하여 최신 버전을 가져올 수 있습니다. 우리는 Snapd 버전을 사용할 것입니다.

    Ubuntu 22.04는 기본적으로 Snapd가 설치된 상태로 제공됩니다. 다음 명령을 실행하여 Snapd 버전이 최신인지 확인하십시오.

    $ sudo snap install core
    

    Certbot을 설치합니다.

    $ sudo snap install --classic certbot
    

    다음 명령을 사용하여 /usr/bin 디렉토리에 대한 심볼릭 링크를 생성하여 Certbot 명령을 실행할 수 있는지 확인하십시오.

    $ sudo ln -s /snap/bin/certbot /usr/bin/certbot
    

    다음 명령을 실행하여 SSL 인증서를 생성합니다.

    $ sudo certbot certonly --standalone --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m  -d mattermost.example.com
    

    위의 명령은 서버의 /etc/letsencrypt/live/mattermost.example.com 디렉토리에 인증서를 다운로드합니다.

    Diffie-Hellman 그룹 인증서를 생성합니다.

    $ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
    

    편집을 위해 /etc/letsencrypt/renewal/mattermost.example.com.conf 파일을 엽니다.

    $ sudo nano /etc/letsencrypt/renewal/mattermost.example.com.conf
    

    하단에 다음 코드를 붙여넣습니다.

    pre_hook = systemctl stop nginx
    post_hook = systemctl start nginx
    

    Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.

    Certbot의 독립 실행형 옵션을 사용하여 SSL 인증서를 생성했습니다. 갱신 중에 Nginx를 종료해야 함을 의미하는 인증서를 생성하기 위해 웹 서버를 실행합니다. pre_hook 및 post_hook 명령은 갱신 전후에 실행되어 Nginx 서버를 자동으로 종료하고 다시 시작하므로 수동 개입이 필요하지 않습니다.

    SSL 갱신이 제대로 작동하는지 확인하려면 프로세스를 시험 실행하십시오.

    $ sudo certbot renew --dry-run
    

    오류가 표시되지 않으면 모든 설정이 완료된 것입니다. 인증서가 자동으로 갱신됩니다.

    9단계 - Nginx 구성

    편집을 위해 /etc/nginx/nginx.conf 파일을 엽니다.

    $ sudo nano /etc/nginx/nginx.conf
    

    include /etc/nginx/conf.d/*.conf; 줄 앞에 다음 줄을 추가합니다.

    server_names_hash_bucket_size  64;
    

    Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.

    편집을 위해 /etc/nginx/conf.d/monica.conf 파일을 만들고 엽니다.

    $ sudo nano /etc/nginx/conf.d/mattermost.conf
    

    다음 코드를 붙여넣습니다. mattermost.example.com을 도메인 이름으로 바꿉니다. client_max_body_size의 값이 Monica에서 파일의 기본 업로드 크기인 10MB로 설정되어 있는지 확인하십시오. 앞서 PHP로 설정한 값과 동일합니다.

    upstream backend {
       server 127.0.0.1:8065;
       keepalive 32;
    }
    
    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   mattermost.example.com;
      return 301 https://$server_name$request_uri;
    }
    
    server {
       listen 443 ssl http2;
       server_name    mattermost.example.com;
    
       http2_push_preload on; # Enable HTTP/2 Server Push
    
       ssl_certificate /etc/letsencrypt/live/mattermost.example.com/fullchain.pem;
       ssl_certificate_key /etc/letsencrypt/live/mattermost.example.com/privkey.pem;
       ssl_trusted_certificate /etc/letsencrypt/live/mattermost.example.com/chain.pem;
       ssl_session_timeout 1d;
    
       # Enable TLS versions (TLSv1.3 is required upcoming HTTP/3 QUIC).
       ssl_protocols TLSv1.2 TLSv1.3;
    
       # Enable TLSv1.3's 0-RTT. Use $ssl_early_data when reverse proxying to
       # prevent replay attacks.
       #
       # @see: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_early_data
       ssl_early_data on;
    
       ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384';
       ssl_prefer_server_ciphers on;
       ssl_session_cache shared:SSL:50m;
       # HSTS (ngx_http_headers_module is required) (15768000 seconds = six months)
       add_header Strict-Transport-Security max-age=15768000;
       # OCSP Stapling ---
       # fetch OCSP records from URL in ssl_certificate and cache them
       ssl_stapling on;
       ssl_stapling_verify on;
       ssl_dhparam /etc/ssl/certs/dhparam.pem;
    
       add_header X-Early-Data $tls1_3_early_data;
    
       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;
           client_body_timeout 60;
           send_timeout 300;
           lingering_timeout 5;
           proxy_connect_timeout 90;
           proxy_send_timeout 300;
           proxy_read_timeout 90s;
           proxy_http_version 1.1;
           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_http_version 1.1;
           proxy_pass http://backend;
       }
    }
    
    # This block is useful for debugging TLS v1.3. Please feel free to remove this
    # and use the `$ssl_early_data` variable exposed by NGINX directly should you
    # wish to do so.
    map $ssl_early_data $tls1_3_early_data {
      "~." $ssl_early_data;
      default "";
    }
    

    Ctrl + X를 누르고 메시지가 표시되면 Y를 입력하여 파일을 저장합니다.

    캐시 디렉터리에 Nginx 권한을 부여합니다.

    $ sudo chown -R nginx:nginx /var/cache/nginx
    

    Nginx 구성을 확인합니다.

    $ sudo nginx -t
    

    Nginx 서버를 다시 시작합니다.

    $ sudo systemctl restart nginx
    

    10단계 - Mattermost 서버에 액세스

    브라우저에서 URL https://mattermost.example.com을 열면 5단계와 같이 가입 페이지가 표시됩니다. 계정 세부 정보를 입력하면 다음과 같이 설정됩니다. 시스템 관리자.

    더 진행하기 전에 공개 URL을 통해 Mattermost에 액세스할 수 있도록 구성했으므로 포트 8065를 닫아야 합니다. 따라서 열린 포트는 보안 위험이 있습니다.

    $ sudo ufw delete allow 8065
    

    다음으로 팀 생성 페이지로 이동합니다.

    팀 만들기 버튼을 클릭하여 첫 번째 팀을 만듭니다.

    다음으로 팀의 공개 URL을 설정하라는 메시지가 표시됩니다.

    Finish 버튼을 클릭하여 Mattermost 대시보드를 엽니다.

    11단계 - Mattermost 서버 구성

    config.json 파일을 사용하거나 대시보드의 시스템 콘솔을 사용하여 Mattermost를 구성할 수 있습니다. 훨씬 더 쉽기 때문에 대시보드를 통해 수행할 것입니다. 왼쪽 상단 모서리에 있는 제품 버튼을 클릭한 다음 시스템 콘솔 옵션을 선택합니다.

    서버에 대한 모든 것을 구성할 수 있는 시스템 콘솔 대시보드로 이동합니다.

    이메일 알림 구성

    메시징 시스템의 가장 중요한 기능 중 하나는 이메일 알림입니다.

    첫 번째 단계는 알림을 활성화하는 것입니다. System Console >> Site Configuration >> Noficiations 메뉴로 이동하여 다음 옵션을 설정합니다.

    • 이메일 알림 활성화를 true로 설정\n
    • 알림 표시 이름을 답장 없음으로 설정\n
    • 알림 발신 주소를 [email 와 같은 것으로 설정합니다.\n
    • 지원 이메일 주소를 [email 와 같이 설정합니다.\n

    다음 단계는 SMTP를 활성화하는 것입니다. System Console >> Environment >> SMTP 메뉴로 이동하여 다음 옵션을 설정합니다. 가이드에서는 Amazon SES 메일러를 사용하고 있습니다.

    • SMTP 서버를 {SMTP-server}로 설정
    • SMTP 서버 포트를 465로 설정
    • SMTP 인증 사용을 true로 설정
    • SMTP 서버 사용자 이름을 {SES-username}으로 설정
    • SMTP 서버 암호를 {SES-Key}로 설정\n
    • SMTP 서버가 수락하는 항목에 따라 연결 보안을 TLS 또는 STARTTLS로 설정\n

    Test Connection 버튼을 클릭하여 SMTP 설정을 확인합니다.

    더 많은 설정을 구성해야 합니다. 완료한 후 변경 사항을 적용하려면 터미널에서 서버를 다시 시작해야 합니다.

    $ sudo systemctl restart mattermost
    

    결론

    이것으로 Ubuntu 22.04 서버에 Mattermost Team Messaging 시스템을 설치하고 구성하는 방법에 대한 자습서를 마칩니다. 질문이 있으시면 아래 의견에 게시하십시오.