+
This commit is contained in:
257
Ubuntu.md
257
Ubuntu.md
@ -2350,190 +2350,6 @@ print
|
||||
?
|
||||
1.
|
||||
sudo update-rc.d autostart.script remove
|
||||
****************************************************************************************************
|
||||
Установка HAProxy на Ubuntu 20.04 по https://itsecforu.ru/2019/07/15/⏳-настройка-балансировщика-нагрузки-h/
|
||||
sudo apt-get update && sudo apt-get install haproxy -y
|
||||
Создаём резервную копию файла:
|
||||
sudo cp /etc/haproxy/haproxy.cfg{,.bak}
|
||||
Редактируем конфигурацию (Описание конфигурационного файла HAProxy https://habr.com/ru/sandbox/34354/)
|
||||
mcedit /etc/haproxy/haproxy.cfg
|
||||
В конец файла добавляем пока только для перенаправления (для балансироки больше IP адресов):
|
||||
|
||||
frontend frontend-http
|
||||
bind *:80
|
||||
mode http
|
||||
|
||||
# ACL для определения запросов на проверку Let's Encrypt
|
||||
acl is_certbot path_beg /.well-known/acme-challenge/
|
||||
|
||||
# Если это не запрос Let's Encrypt, перенаправляем на HTTPS
|
||||
http-request redirect scheme https code 301 unless is_certbot
|
||||
|
||||
# Отправляем запросы Let's Encrypt на backend-certbot
|
||||
use_backend backend-certbot if is_certbot
|
||||
|
||||
|
||||
frontend LOADBALANCER-01
|
||||
bind *:80
|
||||
bind *:443 ssl crt /etc/haproxy/ssl/mqtt.kz.pem crt /etc/ssl/certs/bigfoottrade_kz.pem
|
||||
mode http #режим работы HAProxy, в http режиме происходит анализ Layer 7 трафика
|
||||
option httpclose #Закрывает пассивные соединения
|
||||
|
||||
acl v_geoserver2 hdr(host) -i geoserver2.ccalm.org
|
||||
use_backend geoserver2_ccalm_org if v_geoserver2
|
||||
|
||||
#Перенаправление одной страницы по адресу http://geoserver2.ccalm.org/data/ на другой backend
|
||||
acl v_geo_data hdr(host) -i geoserver2.ccalm.org/data
|
||||
use_backend WEBSERVERS-01 if v_geo_data
|
||||
|
||||
|
||||
default_backend WEBSERVERS-01
|
||||
|
||||
backend WEBSERVERS-01
|
||||
balance roundrobin
|
||||
server web10 127.0.0.1:8081 check inter 5s ssl verify none
|
||||
option httpchk
|
||||
|
||||
backend geoserver2_ccalm_org
|
||||
balance roundrobin
|
||||
server web1 192.168.0.90:80 check
|
||||
option httpchk
|
||||
|
||||
listen stats
|
||||
bind *:8989
|
||||
stats enable
|
||||
stats uri /
|
||||
stats realm Haproxy\ Statistics
|
||||
stats auth igor:i123456
|
||||
|
||||
frontend f-RabbitMQ
|
||||
mode tcp
|
||||
bind 10.1.7.73:21000
|
||||
default_backend b-RabbitMQ
|
||||
|
||||
backend b-RabbitMQ
|
||||
mode tcp
|
||||
server srv1 10.10.16.21:20000
|
||||
|
||||
Для перенаправления незащищённого HTTP трафика можно: xxxxxxxxxxxxxxx
|
||||
|
||||
Для использования SSL и перенаправляние по обычному сокету для начала нужно настроить pem файл объеденив crt и key (и незабыть изменить порт Apache с 433)
|
||||
cat /etc/ssl/certs/bigfoottrade_kz.crt /etc/ssl/certs/bigfoottrade_kz_ca.crt /etc/ssl/private/bigfoottrade_kz.key > /etc/haproxy/ssl/bigfoottrade_kz.pem
|
||||
cat AAA_Certificate_Services.crt GoGetSSL_RSA_DV_CA.crt istransit_kz.crt istransit_kz.key > istransit_kz.pem
|
||||
|
||||
SSLCertificateFile
|
||||
SSLCertificateKeyFile
|
||||
|
||||
Для включения WEB статистики на 9000 порту добавить в конец конфигурации:
|
||||
listen stats
|
||||
bind *:8989
|
||||
stats enable
|
||||
stats uri /stats
|
||||
stats realm Haproxy\ Statistics
|
||||
stats auth igor:i123456
|
||||
Тестирую файл конфигурации:
|
||||
haproxy -f /etc/haproxy/haproxy.cfg -c
|
||||
Перезагружаем:
|
||||
sudo systemctl restart haproxy
|
||||
И теперь должно открываться но адресу: http://data.ccalm.org:8989/
|
||||
Обязательно проверить как установился SSL чекером: https://www.leaderssl.ru/tools/ssl_checker
|
||||
|
||||
****************************************************************************************************
|
||||
Бесплатный SSL сертификат Let’s Encrypt для HAPROXY https://serversforhackers.com/c/letsencrypt-with-haproxy
|
||||
На новой убунте по моему уже не обязательно выполнять так как новая версия уже есть в репозитории: sudo add-apt-repository -y ppa:certbot/certbot
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y certbot
|
||||
|
||||
Для удаления PPA нужно выполнить:
|
||||
sudo apt-get remove certbot
|
||||
sudo add-apt-repository --remove ppa:certbot/certbot
|
||||
apt-get install -f
|
||||
apt autoremove
|
||||
|
||||
Если включён файрволл то разрешаем порт:
|
||||
sudo ufw allow 9080/tcp
|
||||
Проверяем что автообновление в certbot работает для этого выполняем команду:
|
||||
sudo systemctl status certbot.timer
|
||||
Затем пытаемся выполнить пробный прогон при помощи команды:
|
||||
sudo certbot renew --dry-run
|
||||
|
||||
Согласно инструкции модифицируем конфигурационный файл haproxy добавив во frontend это:
|
||||
# ACL for detecting Let's Encrypt validtion requests
|
||||
acl is_certbot path_beg /.well-known/acme-challenge/
|
||||
use_backend backend-certbot if is_certbot
|
||||
|
||||
А также ещё один backend:
|
||||
# Certbot backend
|
||||
# Contains certbot stand-alone webserver
|
||||
backend backend-certbot
|
||||
mode http
|
||||
server certbot 127.0.0.1:9080
|
||||
|
||||
Перезагрузить и выполнить команду:
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d git.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d ru.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d rug.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d kz.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d kzg.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d locust.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d test.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d data.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d geoserver2.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d geoserver.ccalm.org --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d stations.istt.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d uspdmanager.istt.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d tourist.istt.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d monitoring.infracos.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d aistransit.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d istransit.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d test.istransit.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d main.istransit.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d transit.istt.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d geovizor.com --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d mqtt.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d observer.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d rigor.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d pal.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d elektronnaya-ochered.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
certbot certonly --rsa-key-size 2048 --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 -d mcp.kz --email irigm@mail.ru --agree-tos --non-interactive
|
||||
|
||||
После генерации файлы будут в:
|
||||
/etc/letsencrypt/live/geoserver2.ccalm.org/fullchain.pem
|
||||
/etc/letsencrypt/live/geoserver2.ccalm.org/privkey.pem
|
||||
|
||||
Для обновления создаём файл /etc/letsencrypt/renew.sh (по моему этот скрипт не нужен так как рабтает сервис certbot.timer):
|
||||
#!/bin/bash
|
||||
certbot renew --standalone --preferred-challenges http --http-01-address 127.0.0.1 --http-01-port 9080 --post-hook "/etc/haproxy/prepare.sh" --quiet
|
||||
|
||||
Но для HAProxy нужно чтобы 2 файла были объединены поэтому добавляю спец скрипт /etc/haproxy/prepare.sh:
|
||||
#!/bin/bash
|
||||
|
||||
# Loop through all Let's Encrypt certificates
|
||||
for CERTIFICATE in `find /etc/letsencrypt/live/* -type d`; do
|
||||
|
||||
CERTIFICATE=`basename $CERTIFICATE`
|
||||
|
||||
# Combine certificate and private key to single file
|
||||
cat /etc/letsencrypt/live/$CERTIFICATE/fullchain.pem /etc/letsencrypt/live/$CERTIFICATE/privkey.pem > /etc/haproxy/ssl/$CERTIFICATE.pem
|
||||
|
||||
done
|
||||
systemctl reload haproxy.service
|
||||
|
||||
Обновляем конфигурацию HAProxy добавив в frontend:
|
||||
bind *:443 ssl crt /etc/haproxy/ssl/mqtt.kz.pem
|
||||
|
||||
Устанавливаем права
|
||||
chmod +x /etc/haproxy/renew.sh
|
||||
chmod +x /etc/haproxy/prepare.sh
|
||||
И добавляем задание в cron "crontab -e" ниже текст это раз в 24 часа в 00:00:00 ночи:
|
||||
0 0 * * * /bin/sh /etc/letsencrypt/renew.sh
|
||||
|
||||
****************************************************************************************************
|
||||
Подключение стронних SSL сертификатов, допустим с gogetssl.com
|
||||
После покупки сертификата в .pem файл нужно переписать такие ключи и сертификаты как:
|
||||
@ -4412,76 +4228,3 @@ server:
|
||||
sudo systemctl restart smbd
|
||||
sudo systemctl enable smbd
|
||||
|
||||
****************************************************************************************************
|
||||
Туннелирование SSH через HTTP при помощи https://github.com/larsbrinkhoff/httptunnel:
|
||||
sudo apt-get install httptunnel
|
||||
|
||||
Настроил haproxy примерно так, чтобы проверялся параметр "mybiglogfile" для редиректа:
|
||||
|
||||
frontend frontend-http
|
||||
bind *:80
|
||||
mode http
|
||||
|
||||
acl v_tunnel url_param(mybiglogfile) -m found
|
||||
use_backend httptunnel_backend if v_tunnel
|
||||
|
||||
http-request redirect scheme https code 301 unless { ssl_fc } || v_tunnel
|
||||
|
||||
Если есть проксирование через Nginx то добавляем в конфигурацю это:
|
||||
proxy_http_version 1.1;
|
||||
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 Connection "";
|
||||
proxy_pass_request_body on;
|
||||
|
||||
Проверить нет ли редиректо можно так:
|
||||
curl -I http://192.168.200.81/index.html?mybiglogfile=all
|
||||
curl -I http://locust.kz/index.html?mybiglogfile=all
|
||||
|
||||
На сервере запустил прослушку на 9999 и перенаправление на 22:
|
||||
sudo hts -F 127.0.0.1:22 9999
|
||||
Для остановки
|
||||
ps aux | grep hts
|
||||
sudo kill 1854
|
||||
|
||||
Можно запустить как сервис так sudo mcedit /etc/systemd/system/httptunnel.service:
|
||||
[Unit]
|
||||
Description=HTTP Tunnel Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=hts -F 127.0.0.1:22 9999
|
||||
Restart=always
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
Потом:
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable httptunnel
|
||||
sudo systemctl start httptunnel
|
||||
sudo systemctl status httptunnel
|
||||
tail -f /var/log/syslog | grep --line-buffered "htc"
|
||||
|
||||
На клиенте запускаем локальный порт также указал 9999 а ключь
|
||||
htc -F 9999 --base-uri /index.html?mybiglogfile=all 192.168.200.81:80
|
||||
htc -F 9999 --base-uri /index.html?mybiglogfile=all locust.kz:80
|
||||
|
||||
Для остановки
|
||||
ps aux | grep htc
|
||||
Потом
|
||||
sudo kill 783
|
||||
|
||||
Пробую подключиться после настройки тунеля:
|
||||
ssh igor@127.0.0.1 -p 9999
|
||||
****************************************************************************************************
|
||||
Установка Gotify через докер контейнер
|
||||
sudo apt update && sudo apt install -y docker.io docker-compose
|
||||
sudo mkdir -p /opt/gotify
|
||||
cd /opt/gotify
|
||||
Создадим конфигурацию:
|
||||
sudo nano /opt/gotify/docker-compose.yml
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user