Научиться настраивать отказоустойчивую конфигурацию сервисов Linux/FreeBSD.
[nodeN:~] # cat /etc/resolv.conf
search corpX.un nameserver 10.5.6.254
[nodeN:~] # cat /etc/hosts
127.0.0.1 localhost 192.168.X.1 node1.corpX.un node1 192.168.X.2 node2.corpX.un node2 10.5.6.254 proxy
root@nodeN:~# cat /etc/network/interfaces
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.X.N netmask 255.255.255.0 auto eth1 iface eth1 inet manual up ip link set eth1 up auto eth2 iface eth2 inet static address 10.5.6.N*100+X netmask 255.255.255.0 auto eth3 iface eth3 inet manual up ip link set eth3 up
root@nodeN:~# cat /etc/hostname
nodeN.corpX.un
[nodeN:~] # cat /etc/sysctl.conf
... net.ipv4.ip_forward=1 ...
[nodeN:~] # cat .bashrc
... export http_proxy=http://proxy:3128/ ...
root@nodeN:~# init 6 ... root@nodeN:~# apt update
[nodeN:~] # cat /etc/rc.conf.local
hostname="nodeN.corpX.un" ifconfig_em0="inet 192.168.X.N/24" ifconfig_em1="up" ifconfig_em2="inet 10.5.6.N*100+X/24" ifconfig_em3="up"
[nodeN:~] # cat /etc/rc.conf
gateway_enable="YES" sshd_enable="YES"
[nodeN:~] # cat .cshrc
... setenv HTTP_PROXY http://proxy:3128 ...
[nodeN:~] # init 6 ... [nodeN:~] # pkg update -f [nodeN:~] # pkg install pkg
nodeN# ping node1 nodeN# ping node2 nodeN# ping proxy
node1# ssh-keygen ... Enter passphrase (empty for no passphrase): Пароль на ключ пустой!!! ... node1# ssh-copy-id -i .ssh/id_rsa.pub node2
Проверка:
node1# scp /etc/hosts node2:/etc/
Сценарий: настроить DNS на node1, на node2 конфигурация появится автоматически
node1# csync2 -xvv
nodeN# cat /etc/resolv.conf
search corpX.un nameserver 192.168.X.1 nameserver 192.168.X.2
Сценарий: на обоих узлах создаем пользователя user1 с uid=10001
Примечание: выполнить в модуле 5-ть
Примечания:
Проверка:
Вывод сообщений об ошибках:
freebsd# tail -f /var/log/messages linux# tail -f /var/log/syslog
C:\>ping gate
Сценарий:
root@nodeN:~# apt install fake root@nodeN:~# cat /usr/share/ucarp/vip-up
#!/bin/sh /sbin/ifup $1:ucarp ip addr add 172.16.1.X/24 dev eth1 send_arp 172.16.1.X `cat /sys/class/net/eth1/address` 172.16.1.254 ff:ff:ff:ff:ff:ff eth1 route delete default route add default gw 172.16.1.254
root@nodeN:~# cat /usr/share/ucarp/vip-down
#!/bin/sh /sbin/ifdown $1:ucarp ip addr del 172.16.1.X/24 dev eth1 route delete default route add default gw 192.168.X.254
[nodeN:~] # cat /usr/local/sbin/ucarp-up
#!/bin/sh /sbin/ifconfig "$1" alias "$2" netmask 255.255.255.255 /sbin/ifconfig em1 inet 172.16.1.X/24 alias /sbin/route delete default /sbin/route add default 172.16.1.254
[nodeN:~] # cat /usr/local/sbin/ucarp-down
#!/bin/sh /sbin/ifconfig "$1" -alias "$2" /sbin/ifconfig em1 inet 172.16.1.X/24 -alias /sbin/route delete default /sbin/route add default 192.168.X.254
FreeBSD
[nodeN:~] # cat /etc/rc.conf
... ifconfig_em3="up" ...
Debian/Ubuntu
root@nodeN:~# cat /etc/network/interfaces
... auto eth3 iface eth3 inet manual up ip link set eth3 up
# cat named.conf
... forwarders { 172.16.1.254; 172.16.2.254; }; ...
Debian/Ubuntu
nodeN# cat /usr/share/ucarp/vip-up
#!/bin/sh ... ip addr add 172.16.2.X/24 dev eth3 send_arp 172.16.2.X `cat /sys/class/net/eth3/address` 172.16.2.254 ff:ff:ff:ff:ff:ff eth3 ... #route add default gw 172.16.1.254
nodeN# cat /usr/share/ucarp/vip-down
... ip addr del 172.16.2.X/24 dev eth3 ...
FreeBSD
nodeN# cat /usr/local/sbin/ucarp-up
... /sbin/ifconfig em3 inet 172.16.2.X/24 alias ... #/sbin/route add default 172.16.1.254
nodeN# cat /usr/local/sbin/ucarp-down
... /sbin/ifconfig em3 inet 172.16.2.X/24 -alias ...
Debian/Ubuntu
nodeN# cat /usr/share/ucarp/vip-up
... ip route add default via 172.16.1.254 table 101 ip route add default via 172.16.2.254 table 102
nodeN# cat isp1_isp2.sh
#!/bin/sh ip rule del from 192.168.X/24 to 192.168.X/24 table main while ip rule del from any table 101;do true;done while ip rule del from any table 102;do true;done ip rule add from 192.168.X.0/25 table 101 ip rule add from 192.168.X.128/25 table 102 ip rule add from 192.168.X/24 to 192.168.X/24 table main /sbin/ip route flush cache /usr/sbin/conntrack -F
nodeN# cat isp1.sh
#!/bin/sh ip rule del from 192.168.X/24 to 192.168.X/24 table main while ip rule del from any table 101;do true;done while ip rule del from any table 102;do true;done ip rule add from 192.168.X.0/24 table 101 ip rule add from 192.168.X/24 to 192.168.X/24 table main /sbin/ip route flush cache /usr/sbin/conntrack -F
nodeN# cat isp2.sh
#!/bin/sh ip rule del from 192.168.X/24 to 192.168.X/24 table main while ip rule del from any table 101;do true;done while ip rule del from any table 102;do true;done ip rule add from 192.168.X.0/24 table 102 ip rule add from 192.168.X/24 to 192.168.X/24 table main /sbin/ip route flush cache /usr/sbin/conntrack -F
FreeBSD
nodeN# cat /etc/pf.conf
table <ISP1> persist table <ISP2> persist nat on em1 from 192.168.X/24 to any -> 172.16.1.X nat on em3 from 192.168.X/24 to any -> 172.16.2.X pass in quick on em0 from 192.168.X.0/24 to 192.168.X.0/24 pass in on em0 route-to (em1 172.16.1.254) from <ISP1> to any pass in on em0 route-to (em3 172.16.2.254) from <ISP2> to any
nodeN# cat isp1_isp2.sh
#!/bin/sh /sbin/pfctl -t ISP1 -T flush /sbin/pfctl -t ISP2 -T flush /sbin/pfctl -t ISP1 -T add 192.168.X.0/25 /sbin/pfctl -t ISP2 -T add 192.168.X.128/25 /sbin/pfctl -F state
nodeN# cat isp1.sh
#!/bin/sh /sbin/pfctl -t ISP1 -T flush /sbin/pfctl -t ISP2 -T flush /sbin/pfctl -t ISP1 -T add 192.168.X.0/24 /sbin/pfctl -F state
nodeN# cat isp2.sh
#!/bin/sh /sbin/pfctl -t ISP1 -T flush /sbin/pfctl -t ISP2 -T flush /sbin/pfctl -t ISP2 -T add 192.168.X.0/24 /sbin/pfctl -F state
Debian/Ubuntu/FreeBSD
nodeN# cat select_isp.sh
#!/bin/sh export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH ifconfig | grep -q 192.168.X.254 || exit 0 route delete default route add default gw 172.16.1.254 2>/dev/null || exit 0 # route add default 172.16.1.254 2>/dev/null || exit 0 ping -c3 ya.ru >/dev/null 2>&1 ALIVE1=$? route delete default route add default gw 172.16.2.254 # route add default 172.16.2.254 ping -c3 ya.ru >/dev/null 2>&1 ALIVE2=$? route delete default test $ALIVE1 -eq 0 && conf_name="isp1.sh" test $ALIVE2 -eq 0 && conf_name="isp2.sh" test $ALIVE1 -eq 0 && test $ALIVE2 -eq 0 && conf_name="isp1_isp2.sh" # echo /root/$conf_name # exit 0 touch /tmp/conf_name test $conf_name = "`cat /tmp/conf_name`" && exit 0 echo $conf_name > /tmp/conf_name eval /root/$conf_name
nodeN# crontab -l
* * * * * /root/select_isp.sh >/dev/null 2>&1
Debian/Ubuntu
nodeN# ip route show table 101 nodeN# ip route show table 102 nodeN# ip rule show
FreeBSD
nodeN# pfctl -t ISP1 -T show nodeN# pfctl -t ISP1 -T show
Сценарий: отказоустойчивый www хостинг
node1# cat corpX.un
... www A 192.168.X.10
node1# csync2 -xvv
nodeN# service proftpd stop nodeN# update-rc.d -f proftpd remove или nodeN# systemctl disable proftpd
Указываем в файле /etc/hosts имя slave указывающее на соседний сервер
node1# cat /etc/hosts
... 10.M.Z.200+X slave ...
node2# cat /etc/hosts
... 10.M.Z.100+X slave ...
Ubuntu/FreeBSD
nodeN# cat /CHANGE/DIR/rsyncd.conf ... hosts allow = slave nodeN# rsync slave::home nodeN# crontab -l
FreeBSD
* * * * * ps ax | grep -v grep | grep -q 'ftpd -D' && /usr/local/bin/rsync -a /home/ slave::home
Ubuntu
* * * * * ps ax | grep -v grep | grep -q 'proftpd: (accepting connections)' && /usr/bin/rsync -a /home/ slave::home
Debian
* * * * * ps ax | grep -v grep | grep -q 'proftpd: (accepting connections)' && /usr/bin/rsync -az --delete /home/ slave:/home/
Сценарий: Создаем отказоустойчивый корпоративный файловый сервер. Первый узел кластера должен использоваться сервером по умолчанию.
nodeN# systemctl disable istgt crm(live)configure# primitive pr_istgt lsb:istgt crm(live)configure# primitive pr_ip ocf:heartbeat:IPaddr2 params ip=192.168.X.15 cidr_netmask=32 nic=eth0 crm(live)configure# group gr_ip_fs pr_ip pr_fs_r0 pr_istgt crm(live)configure# commit
nodeN# update-rc.d -f iscsitarget remove или nodeN# systemctl disable iscsitarget root@nodeN:~# service heartbeat stop root@nodeN:~# cat /etc/ha.d/haresources
node2.corpX.un \ drbddisk \ Filesystem::/dev/drbd0::/disk2::ext4 \ IPaddr2::192.168.X.15/32/eth0 \ iscsiserv
root@nodeN:~# cat /etc/ha.d/resource.d/iscsiserv
#!/bin/sh case $1 in start) service iscsitarget start ;; stop) service iscsitarget stop ;; esac exit 0
root@nodeN:~# chmod +x /etc/ha.d/resource.d/iscsiserv root@nodeN:~# service heartbeat start
[nodeN:~] # service heartbeat stop [nodeN:~] # cat /usr/local/etc/ha.d/haresources
node2.corpX.un \ hast \ IPaddr::192.168.X.15/32 \ iscsiserv
[nodeN:~] # cat /usr/local/etc/ha.d/resource.d/iscsiserv
#!/bin/sh case $1 in start) sleep 10 service istgt onestart ;; stop) service istgt onestop ;; esac exit 0
[nodeN:~] # chmod +x /usr/local/etc/ha.d/resource.d/iscsiserv [nodeN:~] # service heartbeat start
root@nodeN:~# service smbd stop root@nodeN:~# service nmbd stop root@nodeN:~# systemctl disable smbd root@nodeN:~# systemctl disable nmbd
crm(live)configure# primitive pr_smbd systemd:smbd crm(live)configure# edit gr_ip_fs crm(live)configure# commit
root@nodeN:~# service heartbeat stop root@nodeN:~# cat /etc/ha.d/haresources
node1.corpX.un \ drbddisk \ Filesystem::/dev/drbd0::/disk2::ext4 \ IPaddr2::192.168.X.20/32/eth0 \ smbd
root@nodeN:~# service heartbeat start
[nodeN:~] # service heartbeat stop [nodeN:~] # cat /usr/local/etc/ha.d/haresources
node1.corpX.un \ hast \ IPaddr::192.168.X.20/32 \ smbserv
[nodeN:~] # cat /usr/local/etc/ha.d/resource.d/smbserv
#!/bin/sh case $1 in start) sleep 10 service samba_server onestart ;; stop) service samba_server onestop ;; esac exit 0
[nodeN:~] # chmod +x /usr/local/etc/ha.d/resource.d/smbserv [nodeN:~] # service heartbeat start
master# hastctl status
master# cat /proc/drbd
node1# crm resource stop pr_ip pr_istgt pr_smbd node1# crm configure delete pr_ip pr_istgt pr_smbd gr_ip_fs
nodeN# cat /etc/network/interfaces
... auto br0 iface br0 inet static address 192.168.X.N netmask 255.255.255.0 ucarp-vid 1 ucarp-vip 192.168.X.254 ucarp-password secret bridge_ports eth0 iface br0:ucarp inet static address 192.168.X.254 netmask 255.255.255.255 ...
nodeN# cat /etc/default/isc-dhcp-server
... INTERFACES="br0"
nodeN# init 0
nodeN# ps ax | grep carp nodeN# ifconfig | grep carp nodeN# ps ax | grep dh nodeN# ps ax | grep he nodeN# mount | grep ext
root@nodeN:~# rmdir /var/lib/lxc/ root@nodeN:~# ln -s /disk2/var/lib/lxc/ /var/lib/lxc
root@node1.corpX.un:~# mkdir -p /disk2/var/lib/lxc/ root@node1.corpX.un:~# lxc-create -t debian -n server
root@node1.corpX.un:~# cp /etc/ssh/sshd_config /var/lib/lxc/server/rootfs/etc/ssh/sshd_config root@node1.corpX.un:~# cp /etc/hosts /var/lib/lxc/server/rootfs/etc/hosts root@node1.corpX.un:~# chroot /var/lib/lxc/server/rootfs/ /bin/bash root@node1:/# PS1='server:\w# ' server:/# apt update server:/# apt purge resolvconf isc-dhcp-client server:/# apt install nano vim iputils-ping
server:/# cat /etc/hostname
server.corpX.un
server:/# cat /etc/hosts
127.0.0.1 localhost 192.168.X.30 server.corpX.un 10.Z.M.254 proxy
server:/# rm /etc/resolv.conf server:/# cat /etc/resolv.conf
search corpX.un nameserver 192.168.X.1 nameserver 192.168.X.2
server:/# passwd
root@node1.corpX.un:~# cat /var/lib/lxc/server/config
... lxc.network.type = veth lxc.network.link = br0 lxc.network.flags = up lxc.network.ipv4 = 192.168.X.30/24 lxc.network.ipv4.gateway = 192.168.X.254 ...
root@node1.corpX.un:~# lxc-info -n server root@node1.corpX.un:~# lxc-start -n server root@node1.corpX.un:~# lxc-info -n server root@node1.corpX.un:~# lxc-attach -n server -- ps ax root@node1.corpX.un:~# ssh server root@node1.corpX.un:~# lxc-stop -n server root@node1.corpX.un:~# systemctl start lxc@server debian9_nodeN# mkdir /etc/systemd/system/lxc@server.service.d/ debian9_nodeN# cat /etc/systemd/system/lxc@server.service.d/kill_signal_fix.conf
[Service] KillSignal=SIGRTMIN+3
root@node1.corpX.un:~# systemctl stop lxc@server
# mount_cd9660 /dev/cd0 /mnt # setenv D /disk2/jail/mail # mkdir -p $D # tar -xvf /mnt/usr/freebsd-dist/base.txz -C $D
[nodeN:~] # cat /etc/rc.conf
... jail_list="mail"
[nodeN:~] # cat /etc/jail.conf
allow.raw_sockets = 1; exec.clean; exec.system_user = "root"; exec.jail_user = "root"; exec.start = "/bin/sh /etc/rc"; exec.stop = "/bin/sh /etc/rc.shutdown"; mount.devfs; allow.set_hostname = 0; allow.sysvipc = 0; mail { host.hostname = "mail.corpX.un"; path = "/disk2/jail/mail"; interface = "em0"; ip4.addr = "192.168.X.30"; exec.consolelog = "/var/log/jail_mail_console.log"; }
[node1:~] # cp /root/.cshrc /disk2/jail/mail/root/ [node1:~] # cp /etc/hosts /disk2/jail/mail/etc/ [node1:~] # cp /etc/ssh/sshd_config /disk2/jail/mail/etc/ssh/ [node1:~] # service jail onestart mail [node1:~] # jls [node1:~] # jexec NN csh mail# cat /etc/resolv.conf
nameserver 192.168.X.1 nameserver 192.168.X.2
mail# cat /etc/rc.conf
sshd_enable=yes
mail# passwd mail# ping ya.ru mail# telnet ya.ru 80 [node1:~] # service jail onestop mail
nodeN# systemctl disable docker nodeN# systemctl stop docker nodeN# init 6 node1# mkdir -p /disk2/var/lib/ node1# mv /var/lib/docker/ /disk2/var/lib/ node2# rm -r /var/lib/docker nodeN# ln -s /disk2/var/lib/docker/ /var/lib/docker
NEW primitive pr_lxc_server systemd:lxc@server group gr_fs_lxc pr_fs_r0 pr_lxc_server OLD primitive pr_lxc_server systemd:lxc@server primitive pr_lxc_server ocf:heartbeat:lxc params container=server config=/var/lib/lxc/server/config order or_lxc_after_fs pr_fs_r0 pr_lxc_server colocation col_lxc_on_drbd inf: pr_lxc_server ms_drbd_r0:Master !!! Похоже порядок в группе имеет значение и здесь ошибка !!! group gr_lxc_fs pr_lxc_server pr_fs_r0 crm_resource --resource pr_lxc_server --cleanup --node node45.bmstu.ru crm resource stop pr_lxc_server crm resource move pr_lxc_server node46.bmstu.ru crm resource move pr_fs_r0 node45.bmstu.ru systemctl start lxc@server /etc/init.d/lxc start server