Asterisk в отказоустойчивой конфигурации
Шаг 1. Анализ сети в классе/дома
Шаг 2. Базовая настройка узлов
node1:~# cat /etc/hostname
node1
node1:~# cat /etc/hosts
127.0.0.1 localhost
10.5.7.114 node1
10.5.7.214 node2
node1:~# cat /etc/resolv.conf
nameserver 10.5.7.254
node1:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.5.7.114
netmask 255.255.255.0
gateway 10.5.7.254
node1:~# init 6
node1:~# apt update
node1:~# ssh-keygen
node1:~# ssh-copy-id node2
scp /etc/hosts node2:/etc/
scp /etc/hostname node2:/etc/
scp /etc/resolv.conf node2:/etc/
scp /etc/network/interfaces node2:/etc/network/
node1:~# ssh node2
node2:~# cat /etc/hostname
node2
node2:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.5.7.214
netmask 255.255.255.0
gateway 10.5.7.254
node2:~# init 6
node2:~# apt update
Шаг 3. Сервис DRBD
nodeN:~# init 0
nodeN:~# lshw -C disk
nodeN:~# mkdir /disk2
nodeN:~# apt install drbd8-utils
nodeN:~# cat /etc/drbd.d/global_common.conf
...
startup {
...
wfc-timeout 30;
}
...
# cat /etc/drbd.d/r0.res
resource r0 {
on node1 {
device /dev/drbd0;
disk /dev/sdb;
address 10.5.7.114:7788;
meta-disk internal;
}
on node2 {
device /dev/drbd0;
disk /dev/sdb;
address 10.5.7.214:7788;
meta-disk internal;
}
}
nodeN:~# drbdadm create-md r0
!!! Одновременно !!!
nodeN:~# systemctl start drbd
node1:~# drbdadm -- --overwrite-data-of-peer primary r0
node2:~# watch cat /proc/drbd
node1:~# mkfs -t ext4 /dev/drbd0
node1:~# mount /dev/drbd0 /disk2
Шаг 4. Технология LXC (часть 1)
nodeN:~# apt install lxc
nodeN:~# rmdir /var/lib/lxc/
nodeN:~# ln -s /disk2/var/lib/lxc/ /var/lib/lxc
node1:~# mkdir -p /disk2/var/lib/lxc/
node1:~# time lxc-create -t debian -n server
real 6m19.549s
real 14m13.770s
...
Шаг 5. Настройка bridge
node1:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address 10.5.7.114
netmask 255.255.255.0
gateway 10.5.7.254
bridge_ports eth0
node2:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address 10.5.7.214
netmask 255.255.255.0
gateway 10.5.7.254
bridge_ports eth0
Шаг 6. Технология LXC (часть 2)
node1:~# cat /var/lib/lxc/server/config
...
lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.ipv4 = 10.5.7.123/24
lxc.network.ipv4.gateway = 10.5.7.254
Шаг 7. Настройка дочерней системы
node1:~# chroot /var/lib/lxc/server/rootfs/ /bin/bash
root@node1:/# PS1='server:\w# '
server:/# apt update
server:/# apt purge isc-dhcp-client
server:/# apt install nano vim iputils-ping
server:/# cat /etc/hostname
server
server:/# cat /etc/hosts
127.0.0.1 localhost
10.5.7.123 server
server:/# cat /etc/resolv.conf
nameserver 10.5.7.254
Шаг 8. Запуск DRBD и LCX вручную
nodeN:~# init 0
!!! Одновременно !!!
nodeN:~# systemctl start drbd
nodeN:~# cat /proc/drbd
node1:~# drbdadm primary r0
node1:~# mount /dev/drbd0 /disk2
node1:~# lxc-info -n server
node1:~# lxc-start -n server
node1:~# lxc-info -n server
node1:~# lxc-attach -n server -- bash
root@server:~# time apt install asterisk
real 3m20.521s
Шаг 9. Минимальная настройка Asterisk
root@server:~# cat /etc/asterisk/sip.conf
[general]
transport=udp
disallow=all
allow=alaw
[401]
secret=tpassword401
type=friend
host=dynamic
allowsubscribe=no
root@server:~# cat /etc/asterisk/extensions.conf
[default]
exten => 301,1,Answer()
exten => 301,n,Playback(hello-world)
exten => 301,n,Hangup()
exten => 311,1,Answer()
same => n,Echo()
root@server:~# asterisk -rv
server*CLI> core reload
server*CLI> sip show users
server*CLI> sip show peers
server*CLI> dialplan show default
server*CLI> exit
Шаг 10. Перемещение контейнера на другой узел вручную
node1:~# lxc-stop -n server
node1:~# lxc-info -n server
node1:~# umount /disk2 #примерно, через минуту
node1:~# drbdadm secondary r0
node1:~# cat /proc/drbd
node2:~# drbdadm primary r0
node2:~# mount /dev/drbd0 /disk2
node2:~# lxc-start -n server
Шаг 11. Багфикс lxc для systemd
node2:~# lxc-stop -n server
nodeN:~# mkdir /etc/systemd/system/lxc@server.service.d/
nodeN:~# cat /etc/systemd/system/lxc@server.service.d/kill_signal_fix.conf
[Service]
KillSignal=SIGRTMIN+3
node2:~# systemctl start lxc@server
node2:~# systemctl status lxc@server
node2:~# lxc-info -n server
node2:~# systemctl stop lxc@server
node2:~# lxc-info -n server
Шаг 12. Пакет Corosync
nodeN:~# apt install corosync
nodeN:~# cat /etc/corosync/corosync.conf
...
bindnetaddr: 10.5.7.0
...
mcastaddr: 239.255.1.14
...
nodeN:~# systemctl restart corosync
nodeN:~# corosync-cmapctl | grep members
Шаг 13. Пакет Pacemaker (базовая конфигурация)
nodeN:~# apt install pacemaker
nodeN:~# crm_mon -1
node1:~# apt install crmsh
node1:~# crm status
node1:~# crm configure show
node1:~# crm
configure property stonith-enabled=false
configure property no-quorum-policy=ignore
configure property default-resource-stickiness=100
configure show
exit
Шаг 14. Управление местоположением контейнера с помощью Pacemaker
node2:~# umount /disk2
node2:~# drbdadm secondary r0
nodeN:~# systemctl stop drbd
nodeN:~# apt install psmisc #сюда входит утилита fuser
node1:~# crm configure
primitive pr_drbd_r0 ocf:linbit:drbd params drbd_resource="r0" op monitor interval="15s"
ms ms_drbd_r0 pr_drbd_r0 meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
primitive pr_fs_r0 ocf:heartbeat:Filesystem params device="/dev/drbd0" directory="/disk2" fstype="ext4"
colocation col_fs_on_drbd inf: pr_fs_r0 ms_drbd_r0:Master
order or_fs_after_drbd inf: ms_drbd_r0:promote pr_fs_r0:start
primitive pr_lxc_server systemd:lxc@server
group gr_fs_lxc pr_fs_r0 pr_lxc_server
commit
exit
node1:~# crm status
Шаг 15. Проверки
nodeN:~# crm_mon
nodeN:~# watch cat /proc/drbd