Skip to content

Instantly share code, notes, and snippets.

@nlopin
Created September 18, 2020 15:17
Show Gist options
  • Save nlopin/abede87bd26d72ae75447b907068ab54 to your computer and use it in GitHub Desktop.
Save nlopin/abede87bd26d72ae75447b907068ab54 to your computer and use it in GitHub Desktop.
#!/bin/bash
apt-get -y update
apt-get -y install keepalived
sysctl -w net.ipv4.ip_nonlocal_bind=1
sysctl -p
cat > /etc/keepalived/keepalived.conf <<EOL
vrrp_script chk_httpd {
script "systemctl status keepalived"
interval 2
}
vrrp_instance LB_VIP {
interface eth1
state MASTER
priority 100 / 50
virtual_router_id 33
authentication {
auth_type PASS
auth_pass secret
}
virtual_ipaddress {
192.168.56.200
}
track_script {
chk_httpd
}
virtual_server 192.168.56.200 80 {
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.56.101 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.56.102 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.56.103 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
}
EOL
systemctl enable --now keepalived
#!/bin/bash
apt-get -y update
apt-get -y install nginx
sysctl -w net.ipv4.conf.all.arp_ignore=1
sysctl -w net.ipv4.conf.all.arp_announce=2
sysctl -p
ip addr add 192.168.56.200/24 dev eth1
service nginx start
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-20.04"
(1..3).each do |i|
config.vm.define "nginx#{i}" do |node|
node.vm.hostname = "nginx#{i}"
node.vm.provision "shell", path: "nginx-provision.sh"
node.vm.network :private_network, ip: "192.168.56.10#{i}"
end
end
(1..2).each do |i|
config.vm.define "keepalived#{i}" do |node|
node.vm.hostname = "keepalived#{i}"
node.vm.provision "shell", path: "keepalived-provision.sh"
node.vm.network :private_network, ip: "192.168.56.20#{i}"
end
end
config.vm.define "client" do |node|
node.vm.hostname = "client"
node.vm.network :private_network, ip: "192.168.56.2"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment