Direkt zum Hauptinhalt

Einrichtung Loadbalancer

Einrichtung Loadbalancer

Auf Loadbalancer 1 einloggen und folgende Pakete installieren

 

apt install lvs

Nun eine neue Datei mit folgender Config anlegen

nano /etc/keepalived/keepalived.conf 

Inhalt einfügen

global_defs {
     notification_email {
       info@hacker-net.de
     }
     notification_email_from lb001@strange-hosting.com
     smtp_server hacker-net.de
     smtp_connect_timeout 60
  }

  vrrp_instance VI_1 {
      state MASTER
      interface eth0
      virtual_router_id 101
      unicast_src_ip 159.69.13.9
      unicast_peer { 49.12.74.225 }
      priority 101
      notify /root/failover.sh
      advert_int 1
      authentication {
          auth_type PASS
          auth_pass 775567567ghBysA!asHjk99gf!
      }
      virtual_ipaddress {
          116.202.189.172
      }
      virtual_ipaddress_excluded {
         2a01:4f8:1c0c:8218::1
         }

  }

Nun die failover.sh im root Verzeichnis anlegen

nano /root/failover.sh

Nun Inhalt einfügen

#!/bin/bash

#lb0001 ID : 5605626
#lb0002 ID : 5605974
#floating ip LBS 116.202.189.172 =: 245713
#floating id KC 78.46.239.42 =: 617007
#floatingip6 id 2a01:4f8:1c17:8106::/64 =: 246612
#floating ip  GBL 16126703 =: 78.47.118.115

TYPE=$1
NAME=$2
STATE=$3

case $STATE in
        "MASTER") curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 5BEoQe1HDjITxzhCPmnp8cJq1Ybv6ehNIgdvrfkiECG0fyASSOQbIlFMj9GF0lsV" -d '{"server": 5605626}' 'https://api.hetzner.cloud/v1/floating_ips/245713/actions/assign'
                  curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 5BEoQe1HDjITxzhCPmnp8cJq1Ybv6ehNIgdvrfkiECG0fyASSOQbIlFMj9GF0lsV" -d '{"server": 5605626}' 'https://api.hetzner.cloud/v1/floating_ips/246612/actions/assign'
                  curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 5BEoQe1HDjITxzhCPmnp8cJq1Ybv6ehNIgdvrfkiECG0fyASSOQbIlFMj9GF0lsV" -d '{"server": 5605626}' 'https://api.hetzner.cloud/v1/floating_ips/16126703/actions/assign'
                  curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 5BEoQe1HDjITxzhCPmnp8cJq1Ybv6ehNIgdvrfkiECG0fyASSOQbIlFMj9GF0lsV" -d '{"server": 5605626}' 'https://api.hetzner.cloud/v1/floating_ips/617007/actions/assign'





                  echo "Master"
                  exit 0
                  ;;
        "BACKUP") echo "backup"
                  exit 0
                  ;;
        "FAULT")  echo "fault"
                  exit 0
                  ;;
        *)        echo "unknown state"
                  exit 1
                  ;;
esac

 

Nun auf Loadblancer zwei einloggen

Folgene pakete installieren

apt install lvs

Nun eine neue Datei mit folgender Config anlegen

nano /etc/keepalived/keepalived.conf 

Inhalt einfügen

nano /root/failover.sh