User Tools

Site Tools


протокол_carp

Протокол CARP

Debian/Ubuntu

Установка

root@nodeN:~# apt install ucarp

Настройка

root@nodeN:~# less /usr/share/doc/ucarp/README.Debian

root@nodeN:~# less /etc/network/if-up.d/ucarp

root@nodeN:~# cat /etc/network/interfaces
...
auto eth0
iface eth0 inet static
        address 192.168.X.N
        netmask 255.255.255.0

        ucarp-vid 1
        ucarp-vip 192.168.X.254
        ucarp-password secret

iface eth0:ucarp inet static
        address 192.168.X.254
        netmask 255.255.255.255
...
root@nodeN:~# less /usr/share/ucarp/vip-up
#!/bin/sh

/sbin/ifup $1:ucarp
root@nodeN:~# less /usr/share/ucarp/vip-down
#!/bin/sh

/sbin/ifdown $1:ucarp

Запуск

root@nodeN:~# ifdown --force eth0

root@nodeN:~# ifup eth0

Проверка

root@nodeN:~# ps ax | grep carp

root@nodeN:~# ifconfig eth0:ucarp

root@nodeN:~# pkill -USR1 ucarp

root@nodeN:~# killall -USR1 ucarp

root@nodeN:~# grep carp /var/log/syslog

Смена ролей узлов

wincmd:\> arp -a

masternode# pkill -USR2 ucarp

masternode# killall -USR2 ucarp

wincmd:\> arp -a

FreeBSD (user land)

Установка

[nodeN:~] # pkg install ucarp

Настройка

[nodeN:~] # less /usr/local/etc/rc.d/ucarp

[nodeN:~] # cat /etc/rc.conf
...
ucarp_src="192.168.X.N"
ucarp_enable="YES"
ucarp_vhid="1"
ucarp_if="em0"
ucarp_addr="192.168.X.254"
ucarp_pass="secret"
ucarp_upscript="/usr/local/sbin/ucarp-up"
ucarp_downscript="/usr/local/sbin/ucarp-down"
[nodeN:~] # cat /usr/local/sbin/ucarp-up
#!/bin/sh
...
/sbin/ifconfig "$1" alias "$2" netmask 255.255.255.255
[nodeN:~] # cat /usr/local/sbin/ucarp-down
#!/bin/sh
...
/sbin/ifconfig "$1" -alias "$2"
...
[nodeN:~] # service ucarp start

Дополнительные материалы

Ubuntu вариант запуска процесса вручную

Установка

root@nodeN:~# apt-get install ucarp

Настройка

root@nodeN:~# cat /etc/vip-up.sh
#!/bin/sh
/sbin/ip addr add 192.168.X.254/32 dev "$1"
root@nodeN:~# cat /etc/vip-down.sh
#!/bin/sh
/sbin/ip addr del 192.168.X.254/32 dev "$1"
root@nodeN:~# chmod +x /etc/vip-up.sh /etc/vip-down.sh

Запуск (можно прописать в /etc/rc.local)

root@node1:~# ucarp -i eth0 -s 192.168.X.1 -v 1 -p secret -a 192.168.X.254 -u /etc/vip-up.sh -d /etc/vip-down.sh -z -B

root@node2:~# ucarp -i eth0 -s 192.168.X.2 -v 1 -p secret -a 192.168.X.254 -u /etc/vip-up.sh -d /etc/vip-down.sh -z -B

Примечания:

  • Не смотря на ОБЯЗАТЕЛЬНОЕ наличие ключа -a 192.168.X.254 адрес повторно приходится присваивать/удалять в скриптах
  • If you want a “preferred” master to immediately become a master even if another host is already the master: a) add the –preempt (or -P) switch to *all* hosts b)use a lower skew (-k) or a lower base for the “preferred” one.

Проверка

root@nodeN:~# ip addr show dev eth0

Остановка

root@nodeN:~# killall ucarp

FreeBSD (kernel land)

Настройка

node1# ifconfig carp0 create
node1# ifconfig carp0 vhid 1 pass testpass321 192.168.X.254/24

node2# ifconfig carp0 create
node2# ifconfig carp0 vhid 1 advskew 100 pass testpass321 192.168.X.254/24

node1# cat /etc/rc.conf
...
cloned_interfaces="carp0"
ifconfig_carp0="vhid 1 pass testpass321 192.168.X.254/24"
...
node2# cat /etc/rc.conf
...
cloned_interfaces="carp0"
ifconfig_carp0="vhid 1 advskew 100 pass testpass321 192.168.X.254/24"
...

Проверка

nodeN# ifconfig carp0
протокол_carp.txt · Last modified: 2021/07/08 08:04 by admin