Показаны сообщения с ярлыком haproxy. Показать все сообщения
Показаны сообщения с ярлыком haproxy. Показать все сообщения

суббота, 29 февраля 2020 г.

LetsEncrypt with HAProxy

LetsEncrypt with HAProxy
lxc launch ubuntu:18.04 haprx
lxc config device add haprx myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:localhost:80
#lxc config device remove haprx myport80
lxc config device add haprx myport443 proxy listen=tcp:0.0.0.0:443 connect=tcp:localhost:443
#lxc config device remove haprx myport443
lxc exec haprx -- sudo --user ubuntu --login
sudo apt update && sudo apt upgrade
sudo apt install haproxy
sudo systemctl enable haproxy
sudo systemctl start haproxy
sudo nano /etc/hosts

Добавить

127.0.0.1 localhost
10.91.211.107 web1.lxd
10.91.211.95 web2.lxd
10.91.211.176 gitlab.lxd
10.91.211.10 wordpress.lxd
10.91.211.37 wiki.lxd

Сохранить.


sudo nano /etc/haproxy/haproxy.cfg


-----


Сохранить.

sudo add-apt-repository -y ppa:certbot/certbot
sudo apt-get update
sudo apt-get install -y certbot
sudo systemctl stop haproxy

Первый раз создаем сертификаты вручную используя порт 80 (stop haproxy)

sudo certbot certonly --standalone -d web1.vt.info -d web2.vt.info -d gitlab.vt.info -d wordpress.vt.info -d wiki.vt.info --non-interactive --agree-tos --email admin@vt.info --http-01-port=80

Ниже обратить внимание что путь к папке сертификатами
/etc/letsencrypt/live/web1.vt.info/

Задан в первом  -d web1.vt.info !!!

HAProxy нужен ssl-сертификат, чтобы быть одним файлом в определенном формате:

sudo su -c "cat /etc/letsencrypt/live/web1.vt.info/fullchain.pem /etc/letsencrypt/live/web1.vt.info/privkey.pem > /etc/letsencrypt/live/web1.vt.info/vt.info.pem"

sudo systemctl start haproxy


Далее будем обновляться (можно попробовать):

sudo certbot renew --tls-sni-01-port=8888

Для автоматизации сделаем скрипт:

sudo nano /opt/update-certs.sh

#!/usr/bin/env bash

# Renew the certificate
certbot renew --force-renewal --tls-sni-01-port=8888
#certbot renew --tls-sni-01-port=8888

# Concatenate new cert files, with less output (avoiding the use tee and its output to stdout)
bash -c "cat /etc/letsencrypt/live/web1.vesuchet.info/fullchain.pem /etc/letsencrypt/live/web1.vesuchet.info/privkey.pem > /etc/letsencrypt/live/web1.vesuchet.info/vesuchet.info.pem"

# Reload  HAProxy
service haproxy reload

Сохранить.

четверг, 2 января 2020 г.

Установка DokuWiki в lxd

Install DokuWiki Wiki Software on Ubuntu 16.04 | 18.04 | 18.10 with Apache2, PHP 7.2
How to Install DokuWiki on Ubuntu 18.04 LTS
Установка DokuWiki
Установка DokuWiki на Debian/Ubuntu на Nginx с авторизацией LDAP (AD) и установкой плагинов
Как развернуть DokuWiki on Ubuntu 18.04 Server
Часто задаваемые вопросы


Запись А wiki.examle.com host  в DNS домена example.com

На хосте lxd :

$ lxc launch ubuntu:18.04 wiki
$ lxc exec wiki -- sudo --user ubuntu --login
$ sudo apt update
$ sudo apt upgrade
$ sudo locale-gen en_US ru_RU en_US.UTF-8 ru_RU.UTF-8
$ sudo timedatectl set-timezone Europe/Moscow
$ sudo apt install mc cadaver -y
$ sudo apt install apache2 -y
#$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php -y
$ sudo apt update
$ sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-sqlite3 php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-tidy php7.2-intl php7.2-json php7.2-curl php7.2-zip -y
$ sudo nano /etc/php/7.2/apache2/php.ini

memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = Europe/Moscow

$ sudo systemctl restart apache2.service

$ cd /var/www/html/
$ sudo git clone --branch stable https://github.com/splitbrain/dokuwiki.git
$ sudo chown -R www-data:www-data /var/www/html/dokuwiki/
$ sudo chmod -R 755 /var/www/html/dokuwiki/


Обратить внимание, запись А wiki.example.com host  в домен example.com
 ServerName wiki.example.com

$ sudo nano /etc/apache2/sites-available/dokuwiki.conf

<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/dokuwiki
     ServerName wiki.example.com
     #ServerAlias www.example.com

     <Directory /var/www/html/dokuwiki/>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

     <Directory /var/www/html/dokuwiki/>
            RewriteEngine on
            RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*) index.php [PT,L]
    </Directory>
</VirtualHost>

Сохранить.

$ sudo a2ensite dokuwiki.conf
$ sudo a2enmod rewrite

$ exit

$ lxc list
| wiki        | RUNNING | 10.91.219.37 (eth0)  |

Далее в контейнере haproxy:

$ lxc exec haproxy -- sudo --user ubuntu --login

$ sudo nano /etc/hosts

10.91.219.37 wiki.lxd

$ sudo nano /etc/haproxy/haproxy.cfg
...
acl host_wiki hdr(host) -i wiki.example.com
...
use_backend subdomain5 if host_wiki
...
acl web_wiki hdr(host) -i wiki.example.com
...
use_backend subdomain5 if web_wiki
...
backend subdomain5
balance leastconn
http-request set-header X-Client-IP %[src]
#redirect scheme https if !{ ssl_fc }
server wordpress wiki.lxd:80 check

Сохранить.

$ sudo systemctl restart haproxy

https://wiki.example.com/install.php

https://wiki.example.com/doku.php

После успешной установки:

$ lxc exec wiki -- sudo --user ubuntu --login
$ sudo rm /var/www/html/dokuwiki/install.php
$ exit

Настроим backup

$ nano /home/user/backup_wiki_lxd.sh

#!/usr/bin/env bash
set -ex
lxc stop wiki
BACKUP_DIR=/home/user/backup
#HOSTS=$(lxc list -c n --format csv)
HOSTS=wiki
for HOST in ${HOSTS}

do
    BACKUP_NAME=${HOST}-$(date +"%Y-%m-%d")

    lxc snapshot ${HOST} auto-backup
    lxc publish ${HOST}/auto-backup --alias ${BACKUP_NAME}
    #lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz
    lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}
    lxc image delete ${BACKUP_NAME}
    lxc delete ${HOST}/auto-backup
done
lxc start wiki

Сохранить.

$ chmod +x /home/user/backup_wiki_lxd.sh

$ crontab -e

00 4 * * * sh /home/user/backup_wiki_lxd.sh


Сохранить.



пятница, 13 декабря 2019 г.

Установка nextcloud в контейнер lxd

Putting the snap behind a reverse proxy
cadaver
How to download a file from owncloud with curl, wget

lxc launch ubuntu:18.04 web2
lxc exec web2 -- sudo --user ubuntu --login
sudo apt update
sudo apt upgrade
sudo apt install mc
sudo dpkg-reconfigure locales
sudo dpkg-reconfigure tzdata
sudo dpkg-reconfigure keyboard-configuration
sudo snap find nextcloud
sudo snap install nextcloud
exit
lxc list
| web2        | RUNNING | 10.91.211.95 (eth0)  |      | PERSISTENT | 0         |
lxc exec haproxy -- sudo --user ubuntu --login
sudo nano /etc/hosts
10.91.211.95 web2.lxd
Сохранить.
sudo reboot


lxc exec web2 -- sudo --user ubuntu --login
$ sudo nextcloud.occ config:system:set overwritehost --value="web2.mydomain.com"
$ sudo nextcloud.occ config:system:set overwriteprotocol --value="https"

https://web2.mydomain.com/remote.php/webdav/


sudo apt install cadaver
cadaver https://web2.mydomain.com/remote.php/webdav/

Использование cadaver в скриптах:

nano dl_8.3.15.1778.sh

#!/bin/bash
rm -f  ~/.netrc
cat > ~/.netrc <<EOF
machine web2.mydomain.com
login user
password password
EOF
chmod 600 ~/.netrc
rm -f  ~/setup-1c/dist/dat
cat > ~/setup-1c/dist/dat <<EOF
open https://web2.mydomain.com/remote.php/webdav/
ls
get postgresql_10.10_4.1C_amd64_deb.tar.bz2 postgresql_10.10_4.1C_amd64_deb.tar.bz2
get postgresql_11.5_7.1C_amd64_deb.tar.bz2 postgresql_11.5_7.1C_amd64_deb.tar.bz2
get client_8_3_15_1778.deb64.tar.gz client_8_3_15_1778.deb64.tar.gz
get deb64_8_3_15_1778.tar.gz deb64_8_3_15_1778.tar.gz
quit
EOF
cd ~/setup-1c/dist/
cadaver -r dat
rm -f  ~/.netrc
rm -f  ~/setup-1c/dist/dat
cd ~/setup-1c/scripts

Сохранить.

sh dl_8.3.15.1778.sh

$ curl -J -O https://.....
  • -J (use remote header name)
  • -O (use remote name)


воскресенье, 8 декабря 2019 г.

Using LXC/LXD Containers with HAProxy

LetsEncrypt с HAProxy
Using LXC/LXD Containers with HAProxy
Hosting multiple websites with containers and HAProxy
How to set up multiple secure (SSL/TLS, Qualys SSL Labs A+) websites using LXD containers
Обслуживание нескольких сайтов с помощью Nginx, HAProxy и LXD в Ubuntu 16.04
How to manage Let's Encrypt SSL/TLS certificates with certbot
Let's Encrypt: подстановочный сертификат с Certbot
Подстановочный сертификат Letsencrypt и запись GoDaddy _acme-challenge

Для  godaddy.com




$ lxc launch ubuntu:18.04 web1
$ lxc exec web1 -- sudo --user ubuntu --login
$ sudo apt update && sudo apt upgrade
$ sudo apt install apache2
$ sudo nano /var/www/html/index.html
Изменить строку 224
It works web1!
Сохранить.
$ sudo systemctl enable apache2
$ sudo systemctl start apache2

$ exit
$ curl 10.91.211.18 | grep web1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10923  100 10923    0     0  2666k      0 --:--:-- --:--:-- --:--:-- 2666k
          It works web1!
===============================================================
$ lxc launch ubuntu:18.04 web2
$ lxc exec web2 -- sudo --user ubuntu --login
$ sudo apt update && sudo apt upgrade
$ sudo apt install apache2
$ sudo nano /var/www/html/index.html
Изменить строку 224
It works web2!
Сохранить.
$ sudo systemctl enable apache2
$ sudo systemctl start apache2
$ exit
$ curl 10.91.211.77 | grep web2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10923  100 10923    0     0  3555k      0 --:--:-- --:--:-- --:--:-- 3555k
          It works web2!
===============================================================
$ lxc launch ubuntu:18.04 gitlab
$ lxc launch ubuntu:18.04 haproxy

$ lxc list



Using LXC/LXD Containers with HAProxy
$ lxc launch ubuntu:18.04 haproxy
$ lxc config device add haproxy myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:localhost:80
#$ lxc config device remove haproxy myport80 
$ lxc config device add haproxy myport443 proxy listen=tcp:0.0.0.0:443 connect=tcp:localhost:443
#$ lxc config device remove haproxy myport443
$ lxc exec haproxy -- sudo --user ubuntu --login
$ sudo apt update && sudo apt upgrade
$ sudo apt install haproxy
$ sudo systemctl enable haproxy
$ sudo systemctl start haproxy
$ sudo nano /etc/hosts
Добавить
10.91.211.18 web1.lxd
10.91.211.77 web2.lxd
10.91.211.176 gitlab.lxd 
Сохранить.
$ sudo nano /etc/haproxy/haproxy.cfg

Заменить:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon

#ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets
#ssl-default-bind-ciphers EECDH+AESGCM:EDH+AESGCM
#tune.ssl.default-dh-param 2048

defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
option http-server-close
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

#frontend www-https
#bind *:443 ssl crt /etc/letsencrypt/live/example.com/example.com.pem
#reqadd X-Forwarded-Proto:\ https

#acl host_web1 hdr(host) -i web1.example.com
#acl host_web2 hdr(host) -i web2.example.com

#use_backend subdomain1 if host_web1
#use_backend subdomain2 if host_web2

frontend http_frontend
bind *:80

acl web_host1 hdr(host) -i web1.example.com
acl web_host2 hdr(host) -i web2.example.com

use_backend subdomain1 if web_host1
use_backend subdomain2 if web_host2

backend subdomain1
balance leastconn
http-request set-header X-Client-IP %[src]
#redirect scheme https if !{ ssl_fc }
server web1 web1.lxd:80 check

Сохранить.

$ sudo systemctl restart haproxy

Установим Wildcard Certificates
вручную:

$ sudo add-apt-repository -y ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install -y certbot
$ sudo systemctl stop haproxy

$ sudo certbot certonly --manual --preferred-challenges dns-01 -d *.example.com
Можно было бы  включить не только поддомены, но и сам домен:
#$ sudo certbot certonly --manual --preferred-challenges dns-01 -d *.example.com -d example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.example.com
with the following value:

kkjwKk4CieIWeMUZLGwuoizp1TA7linPuQ8GNMqLLy4

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue


Для  godaddy.com



Press Enter to Continue
Waiting for verification...
Cleaning up challenges

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 2020-03-08. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - 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


$ sudo - i

root@haproxy:~# cd /etc/letsencrypt/live/example.com
root@haproxy:~# cat fullchain.pem privkey.pem > example.com.pem

$ sudo nano /etc/haproxy/haproxy.cfg

Раскомментируем относящееся к https
Сохранить.

$ exit

Отключим http:
На хосте:

$ lxc config device remove haproxy myport80

$ sudo reboot  

$ sudo systemctl start haproxy

$ lxc file pull haproxy/etc/haproxy/haproxy.cfg .

=================================
Настроим  gitlab

$ lxc exec gitlab -- sudo --user ubuntu --login
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install mc
$ sudo dpkg-reconfigure locales
$ sudo dpkg-reconfigure tzdata
$ sudo dpkg-reconfigure keyboard-configuration
$ sudo apt install -y postfix
$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
$ sudo EXTERNAL_URL="http://gitlab.lxd" apt-get install gitlab-ee

https://gitlab.example.com
Ввести пароль для root не менее 8 символов
Зайти.
Запретить регистрацию.

#$ sudo gitlab-ctl stop

Backup gitlab

$ mkdir /home/user/backup

$ nano backup_gitlab_lxd.sh

#!/usr/bin/env bash
set -ex
lxc stop gitlab
BACKUP_DIR=/home/user/backup
#HOSTS=$(lxc list -c n --format csv)
HOSTS=gitlab
for HOST in ${HOSTS}

do
    BACKUP_NAME=${HOST}-$(date +"%Y-%m-%d")

    lxc snapshot ${HOST} auto-backup
    lxc publish ${HOST}/auto-backup --alias ${BACKUP_NAME}
    #lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz
    lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}
    lxc image delete ${BACKUP_NAME}
    lxc delete ${HOST}/auto-backup
done
lxc start gitlab

Сохранить.

$ crontab -e

# m h  dom mon dow   command
00 5 * * * sh /home/user/backup_gitlab_lxd.sh

Восстановление на другом компьютере:

$ lxc image import gitlab-2019-12-16.tar.gz --alias gitlab-backup
$ lxc launch gitlab-backup gitlab
$ lxc image delete gitlab-backup


вторник, 3 декабря 2019 г.

Настройка Git-сервера в контейнере lxd

Установка GitLab в Ubuntu 18.04 
Как настроить Git-сервер на Linux
4.4 Git on the Server - Setting Up the Server
Linode:Install GitLab on Ubuntu 18.04
DO:Установка Git в Ubuntu 18.04 [Краткое руководство]
DO:Установка Git в Ubuntu 18.04

Запись А gitlab.examle.com host  в DNS домена example.com

$ lxc launch ubuntu:18.04 gitlab
$ lxc exec gitlab /bin/bash
# adduser user
# usermod -aG sudo user
# apt update
# apt upgrade
## apt install qemu-user-static -y
# apt install mc samba sudo ssh wget -y
# dpkg-reconfigure locales
## Выбираем ru_RU.UTF-8 ru_RU.UTF-8 UTF-8
# locale -a  
## timedatectl set-timezone Europe/Moscow
# dpkg-reconfigure tzdata
## apt install keyboard-configuration
# dpkg-reconfigure keyboard-configuration
# nano /etc/ssh/sshd_config
#PasswordAuthentication no
PasswordAuthentication yes
Сохранить.
# systemctl reload sshd
##apt install tasksel
## tasksel --list-tasks 
## tasksel install xubuntu-core
## apt install xrdp
## systemctl enable xrdp
## apt install x2goserver x2goserver-xsession
# reboot

Зайти по ssh

$ sudo apt install -y postfix
$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
$ ip a

### Запись А gitlab.examle.com host  в DNS домена example.com, должна существовать,
### если указать "https" - будет попытка создать сертификат.
### предполагаем, что преобразованием https займется haproxy.
$ sudo EXTERNAL_URL=://gitlab.example.com" apt-get install gitlab-ee

http://gitlab
Ввести пароль для root не менее 8 символов
Зайти.

$ lxc list
| gitlab     | RUNNING | 192.168.0.221 (eth0) |      | PERSISTENT | 0         |

$ mkdir /home/user/setup-1c
$ cd /home/user/setup-1c
$ git init
Инициализирован пустой репозиторий Git в /home/user/setup-1c/.git/
$ git config user.name user
$ git config user.email "you@example.com"
$ git add README.md
$ git commit -am "Update README.md"
#$ git remote add origin http://192.168.0.221/user/setup-1c.git
$ git push -u origin master
=============================

user@lxd:~$ lxc delete u1804
user@lxd:~$ lxc copy u1804-cop u1804
user@lxd:~$ lxc start u1804
$ git clone http://192.168.0.221/user/setup-1c.git
$ cd setup-1c
$ sudo sh setup-1c.sh

Настройка почты с отправкой через yandex:
ещё

$ lxc exec gitlab bash
# nano /etc/gitlab/gitlab.rb
Добавить в конец
external_url 'http://gitlab'
gitlab_rails['gitlab_email_from'] = 'user@yandex.ru'
gitlab_rails['gitlab_email_display_name'] = 'Private GitLab'
gitlab_rails['gitlab_email_reply_to'] = 'user@yandex.ru'
gitlab_rails['gitlab_email_subject_suffix'] = ''
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.yandex.ru"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "user@yandex.ru"
gitlab_rails['smtp_password'] = "password_user@yandex.ru"
gitlab_rails['smtp_domain'] = "yandex.ru"
#gitlab_rails['gitlab_email_from'] = 'user@yandex.ru'
#gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_authentication'] = "plain"
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'

Сохранить.


# reboot
# gitlab-rails console
Notify.test_email('mail@domen.com', 'Message Subject', 'Message Body').deliver_now

Дальнейшая настройка (если понадобиться)

$ lxc exec gitlab -- sudo --user ubuntu --login
$ sudo nano /etc/gitlab/gitlab.rb

external_url 'http://gitlab.example.com'
 
Сохранить.

$ sudo gitlab-ctl reconfigure
$ exit