[nodeN:~] # cat /etc/resolv.conf
domain corpX.un nameserver 10.Z.M.125
[nodeN:~] # cat /etc/hosts
127.0.0.1 localhost localhost.corpX.un 192.168.X.1 node1.corpX.un node1 192.168.X.2 node2.corpX.un node2 10.5.1.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.1.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.1.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/
node1# csync2 -xvv
Примечания:
Проверка:
Вывод сообщений об ошибках:
freebsd# tail -f /var/log/messages linux# tail -f /var/log/syslog
Сценарий:
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
[nodeN:~] # cat /etc/rc.conf
... ifconfig_em3="up" ...
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; }; ...
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 ...
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 ...
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 echo > /tmp/conf_name
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
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
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=$? 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
nodeN# pfctl -t ISP1 -T show nodeN# pfctl -t ISP1 -T show
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 ...
Устанавливаем на node1 Пакет RSYNC
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
!!! Проверять на отказоустойчивость по окончании синхронизации
Сценарий: Создаем отказоустойчивый корпоративный файловый сервер. Первый узел кластера должен использоваться сервером по умолчанию.
node1# cat corpX.un
... iscsi A 192.168.X.15
node1# csync2 -x
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
node1# cat corpX.un
... samba A 192.168.X.20
node1# csync2 -x
root@nodeN:~# service smbd stop root@nodeN:~# service nmbd stop root@nodeN:~# echo manual > /etc/init/smbd.override root@nodeN:~# echo manual > /etc/init/nmbd.override или root@nodeN:~# systemctl disable smbd root@nodeN:~# systemctl disable nmbd
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 \ smbserv
root@nodeN:~# cat /etc/ha.d/resource.d/smbserv
#!/bin/sh case $1 in start) service smbd start ;; stop) service smbd stop ;; esac exit 0
root@nodeN:~# chmod +x /etc/ha.d/resource.d/smbserv 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 смонтирован зеркалируемый раздел !!!
nodeN# apt install bridge-utils 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 ubuntu -n mail
root@node1.corpX.un:~# cp /etc/ssh/sshd_config /var/lib/lxc/mail/rootfs/etc/ssh/sshd_config root@node1.corpX.un:~# cp /etc/hosts /var/lib/lxc/mail/rootfs/etc/hosts root@node1.corpX.un:~# chroot /var/lib/lxc/mail/rootfs/ /bin/bash root@node1:/# PS1='mail:\w# ' mail:/# apt-get update mail:/# apt-get purge resolvconf isc-dhcp-client mail:/# apt-get install nano
mail:/# cat /etc/hostname
mail.corpX.un
mail:/# cat /etc/hosts
127.0.0.1 localhost 192.168.X.30 mail.corpX.un 10.Z.M.254 proxy
mail:/# rm /etc/resolv.conf mail:/# cat /etc/resolv.conf
search corpX.un nameserver 192.168.X.1 nameserver 192.168.X.2
mail:/# userdel -r ubuntu mail:/# passwd
root@node1.corpX.un:~# cat /var/lib/lxc/mail/config
... lxc.network.type = veth lxc.network.link = br0 lxc.network.ipv4 = 192.168.X.30/24 lxc.network.ipv4.gateway = 192.168.X.254 ...
root@node1.corpX.un:~# lxc-info -n mail root@node1.corpX.un:~# lxc-start -n mail -d root@node1.corpX.un:~# lxc-info -n mail root@node1.corpX.un:~# lxc-attach -n mail -- ps ax root@node1.corpX.un:~# ssh mail root@node1.corpX.un:~# lxc-stop -n mail root@nodeN.corpX.un:~# service heartbeat stop
# 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