Обновим систему до актуального состояния
sudo apt-get update
sudo apt-get upgrade -y
Установим необходимые зависимости
sudo apt-get install git
sudo apt-get install docker.io
sudo apt-get install docker-compose
Теперь добавьте своего пользователя в группу Docker. А после запустите и включите docker для запуска при загрузке.
sudo usermod -aG docker $USER
newgrp docker
sudo systemctl start docker && sudo systemctl enable docker
В этом руководстве у нас будет в общей сложности 3 контейнера docker, то есть веб-приложение, база данных и самые важные серверные контейнеры
Создавайте локальные каталоги томов для хранения данных.
sudo mkdir -pv /srv/mattermost/volumes/app/mattermost/{data,logs,config,plugins,client-plugins}
sudo chown -R 2000:2000 /srv/mattermost/
Теперь клонируем Docker контейнер Mattermost из репозитория git.
git clone https://github.com/mattermost/mattermost-docker.git
cd mattermost-docker
Файл docker-compose.yml состоит из 3 частей: базы данных, самого важного сервера и веб-приложения.
Откройте файл YAML и выйдите из 3 частей, как показано ниже:
nano docker-compose.yml
В файле внесите следующие изменения.
Теперь отредактируйте конфигурацию контейнера базы данных, заменив ее соответствующим образом.
...
db:
build: db
read_only: true
restart: unless-stopped
volumes:
- /srv/mattermost/var/lib/postgresql/data:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
environment:
- POSTGRES_USER=mmuser
- POSTGRES_PASSWORD=Passw0rd
- POSTGRES_DB=mattermost
В команде замените Passw0rd на предпочитаемый вами пароль для создаваемой базы данных PostgreSQL. В секции volumes не забудьте указать рабочий каталог /srv/mattermost/var/lib/postgresql/data:/var/lib/postgresql/data
Теперь мы перейдем к тому же файлу YAML и подготовим контейнер для Mattermost сервера.
.......
app:
build:
context: app
# uncomment following lines for team edition or change UID/GID
args:
- edition=team
# - PUID=1000
# - PGID=1000
# - MM_VERSION=5.31
# restart: unless-stopped
volumes:
- /srv/mattermost/volumes/app/mattermost/config:/mattermost/config:rw
- /srv/mattermost/volumes/app/mattermost/data:/mattermost/data:rw
- /srv/mattermost/volumes/app/mattermost/logs:/mattermost/logs:rw
- /srv/mattermost/volumes/app/mattermost/plugins:/mattermost/plugins:rw
- /srv/mattermost/volumes/app/mattermost/client-plugins:/mattermost/client/plugins:rw
- /etc/localtime:/etc/localtime:ro
Необходимо заменить лицензию на team (edition=team), а в секции volumes указать всем каталогам путь относительно /srv/mattermost/
environment:
# set same as db credentials and dbname
- MM_USERNAME=mmuser
- MM_PASSWORD=Passw0rd
- MM_DBNAME=mattermost
MM_SQLSETTINGS_DATASOURCE=postgres://mmuser:Passw0rd@db:5432/mattermost?sslmode=disable&connect_timeout=10
Здесь два раза необходимо заменить Passw0rd на указанный нами ранее.
Оставшаяся часть файла YAML предназначена для предоставления веб-контейнера.
web:
build: web
ports:
- "8001:8080"
- "4430:8443"
read_only: true
restart: unless-stopped
volumes:
# This directory must have cert files if you want to enable SSL
# - ./volumes/web/cert:/cert:ro
- /etc/localtime:/etc/localtime:ro
cap_drop:
- ALL
Меняем значение портов на 8001 и 4430. И комитим строку для SSL. Так как этим у нас будет заниматься Nginx.
docker-compose up -d
Теперь получите доступ к веб-интерфейсу в браузере, используя URL-адрес http://domain-name:8001 или http://IP_Address:8001. И завершите первоначальную настройку.
Для того чтобы можно было обращаться к нашему сайту через HTTPS, установим Nginx
sudo apt-get install nginx
Создадим файл конфигурации для Mattermost.
sudo nano /etc/nginx/conf.d/mattermost.conf
с содержимым:
server {
listen 80;
listen [::]:80;
server_name mattermost.example.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://localhost:8001/;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Где mattermost.example.com адрес для работы Mattermost, а http://localhost:8001/ адрес из запущенного Docker контейнера.
Даем файлу необходимые права
sudo chown www-data:www-data /etc/nginx/conf.d/mattermost.conf
sudo chmod 755 /etc/nginx/conf.d/mattermost.conf
Если в основном файле настроек Nginx у вас не было указано сайта, то закомментируйте все строки(символ #)
sudo nano /etc/nginx/sites-available/default
Проверить настройки можно командой
sudo nginx -t
Запустите Nginx службу
sudo systemctl start nginx
sudo systemctl enable nginx
Либо перезагрузите ее, если она была запущена ранее
sudo systemctl restart nginx
С помощью Let's Encrypt можно бесплатно установить доверенные SSL-сертификаты на любое доменное имя. Для начала, вам необходимо установить сертификат-бота.
sudo apt install certbot python3-certbot-nginx
Запускаем процесс получение сертификатов
sudo certbot --nginx
Пример ответов:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): admin@example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: example.com
2: mattermost.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1 2
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
http-01 challenge for mattermost.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/dtc1.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/mattermost.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/mattermost.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://example.com and
https://mattermost.example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
https://www.ssllabs.com/ssltest/analyze.html?d=mattermost.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
Your cert will expire on 2022-06-02. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
- We were unable to subscribe you the EFF mailing list because your
e-mail address appears to be invalid. You can try again later by
visiting https://act.eff.org.
После этого обновите страницу, и сайты перейдут на https
Добавим поддержку API в файл конфигурации для Mattermost.
sudo nano /etc/nginx/conf.d/mattermost.conf
и добавим содержимое:
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://localhost:8001;
}
И заменим содержимое location /:
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://localhost:8001/;
}
Проверить настройки можно командой
sudo nginx -t
Перезапускаем Nginx службу
sudo systemctl restart nginx
Все готово.