heartbeat
Нужно, чтобы при остановке фтп сервера на одном узле, автоматически запускался сервер на другом.
Подготовка окружения
Добавляем интерфейс eth1
[root@server1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR=10.0.0.1
NETMASK=255.255.255.0
[root@server1 ~]# ssh server2
[root@server2 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR=10.0.0.2
NETMASK=255.255.255.0
CTRL + D
[root@server1 ~]# service network restart && ssh server2 service network restart
[root@server1 ~]# vi /etc/hosts
Добавляем:
############################################
## eth1 - Interconnect Private Network
10.0.0.2 slave.localdomain slave
############################################
[root@server1 ~]# ssh server2
[root@server2 ~]# vi /etc/hosts
Добавляем:
############################################
## eth1 - Interconnect Private Network
10.0.0.1 slave.localdomain slave
############################################
CTRL + D
Убедиться, что с каждого узла идет ping на slave
Инсталляция heartbeat
[root@server1 ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@server1 ~]# ssh server2 rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@server1 ~]# yum install -y heartbeat && ssh server2 yum install -y heartbeat
[root@server1 ~]# chkconfig --level 345 heartbeat on && ssh server2 chkconfig --level 345 heartbeat on
[root@server1 ~]# yum install -y heartbeat && ssh server2 yum install -y heartbeat
-- Останавливаю фтп сервер, он должен будет подняться скриптами
[root@server1 ~]# service proftpd stop && ssh server2 service proftpd stop
[root@server1 ~]# chkconfig --level 345 proftpd off && ssh server2 chkconfig --level 345 proftpd off
[root@server1 ~]# vi /etc/ha.d/ha.cf
bcast eth0
deadtime 30
initdead 120
auto_failback off
node server1.localdomain
node server2.localdomain
debugfile /var/log/ha-debug
logfile /var/log/ha-log
[root@server1 ~]# scp /etc/ha.d/ha.cf server2:/etc/ha.d/ha.cf
[root@server1 ~]# vi /etc/ha.d/authkeys
auth 1
1 sha1 heartbeatpass
[root@server1 ~]# scp /etc/ha.d/authkeys server2:/etc/ha.d/authkeys
[root@server1 ~]# chmod 600 /etc/ha.d/authkeys && ssh server2 chmod 600 /etc/ha.d/authkeys
[root@server1 ~]# vi /etc/ha.d/resource.d/ftpserv
#!/bin/sh
# Don't forget disable autostart service
# Uncomment starting services compatible with FreeBSD/Ubuntu
case $1 in
start)
/etc/init.d/proftpd start
;;
stop)
/etc/init.d/proftpd stop
;;
esac
exit 0
[root@server1 ~]# chmod +x /etc/ha.d/resource.d/ftpserv
[root@server1 ~]# scp /etc/ha.d/resource.d/ftpserv server2:/etc/ha.d/resource.d/ftpserv
-- Файл один на обоих узлах.
-- 192.168.1.20 - виртуальный интерфейс на каждом из хостов.
[root@server1 ~]# vi /etc/ha.d/haresources
server1.localdomain \
IPaddr2::192.168.1.20/32/eth0 \
ftpserv
[root@server1 ~]# scp /etc/ha.d/haresources server2:/etc/ha.d/haresources
[root@server1 ~]# service heartbeat restart && ssh server2 service heartbeat restart
Проверки
[root@server1 ha.d]# ps ax | grep heartbeat
[root@server1 ha.d]# ssh server2 ps ax | grep heartbeat
[root@server1 ha.d]# cl_status nodestatus server1.localdomain
active
[root@server1 ha.d]# cl_status nodestatus server2.localdomain
active
[root@server1 ha.d]# ps ax | grep ftp
2054 ? Ss 0:00 proftpd: (accepting connections)
2449 pts/0 S+ 0:00 grep ftp
[root@server1 ha.d]# ssh server2 ps ax | grep ftp
[root@server1 ha.d]#
[root@server1 ha.d]# ip addr show eth0
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:93:1e:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.21/24 brd 192.168.1.255 scope global eth0
inet 192.168.1.21/32 brd 192.168.1.255 scope global eth0
inet 192.168.1.20/32 brd 192.168.1.255 scope global eth0
inet6 fe80::a00:27ff:fe93:1e10/64 scope link
valid_lft forever preferred_lft forever
[root@server1 ~]# less /var/log/ha-debug
[root@server1 ~]# less /var/log/ha-log
Копирование
[root@server1 ~]# vi /etc/rsyncd.conf
pid file = /var/run/rsyncd.pid
[home]
uid = root
use chroot = yes
path = /home
read only = no
hosts allow = slave
[root@server1 ~]# scp /etc/rsyncd.conf server2:/etc/rsyncd.conf
[root@server1 ~]# crontab -e
* * * * * ps ax | grep -v grep | grep -q 'proftpd: (accepting connections)' && /usr/bin/rsync -a /home/ slave::home
[root@server1 ~]# ssh server2
[root@server2 ~]# crontab -e
* * * * * ps ax | grep -v grep | grep -q 'proftpd: (accepting connections)' && /usr/bin/rsync -a /home/ slave::home
[root@server1 ~]# ssh slave
The authenticity of host 'slave (10.0.0.2)' can't be established.
RSA key fingerprint is 0d:b6:67:4c:37:94:d8:b4:91:48:33:fd:e5:74:65:5a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave,10.0.0.2' (RSA) to the list of known hosts.
Last login: Sun Feb 2 03:57:09 2014 from 192.168.1.21
[root@server2 ~]# ssh slave
The authenticity of host 'slave (10.0.0.1)' can't be established.
RSA key fingerprint is 0d:b6:67:4c:37:94:d8:b4:91:48:33:fd:e5:74:65:5a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave,10.0.0.1' (RSA) to the list of known hosts.
Last login: Sun Feb 2 03:57:04 2014 from 192.168.1.22