Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Heartbeat+ipvs+keepalived

2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. High availability Heartbeat

Server1 and server4 installation resource packs

heartbeat-3.0.4-2.el6.x86_64.rpm

heartbeat-devel-3.0.4-2.el6.x86_64.rpm

heartbeat-libs-3.0.4-2.el6.x86_64.rpm

ldirectord-3.9.5-3.1.x86_64.rpm

yum install -y heartbeat-*

[root@server1 ha.d]# cd /usr/share/doc/heartbeat-3.0.4/

[root@server1 heartbeat-3.0.4]# cp ha.cf authkeys haresources /etc/ha.d/

[root@server1 heartbeat-3.0.4]# cd /etc/ha.d

[root@server1 ha.d]# vim ha.cf

[root@server1 ha.d]# vim authkeys

[root@server1 ha.d]# chmod 600 authkeys

[root@server1 ha.d]# vim haresources

[root@server1 ha.d]# scp ha.cf authkeys haresources server4:/etc/ha.d

[root@server1 ha.d]# /etc/init.d/heartbeat start

Server4 does the same.

[root@server4 ha.d]# /etc/init.d/heartbeat start

Testing:

[root@server1 ha.d]# /etc/init.d/heartbeat stop

[root@server1 ha.d]# /etc/init.d/heartbeat start

1.ipvs Load Balancer

First stop heartbeat on server1 and server4.

Operations on Server1, and server1 as scheduler

[root@server1 ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm

[root@server1 ~]# cd /usr/share/doc/ldirectord-3.9.5/

[root@server1 ldirectord-3.9.5]# cp ldirectord.cf /etc/ha.d

[root@server1 ~]# yum install -y ipvsadm

[root@server1 ~]# ipvsadm -L

[root@server1 ~]# ipvsadm -C##Purge rules

[root@server1 ~]# ipvsadm -A -t 172.25.6.100:80 -s rr ##rr means to add a new virtual ip using polling scheduling algorithm

[root@server1 ~]# ip addr add 172.25.6.100/24 dev eth0

[root@server1 ~]# ip addr

[root@server1 ~]# ipvsadm -a -t 172.25.6.100:80 -r 172.25.6.2:80 -g ##Add new rule

[root@server1 ~]# ipvsadm -a -t 172.25.6.100:80 -r 172.25.6.3:80 -g

[root@server1 ~]# /etc/init.d/ipvsadm save ##Save added rules

[root@server1 ~]# ipvsadm -L ##Displays a list of virtual servers in the kernel

[root@server1 ~]# /etc/init.d/httpd restart

Operations on Server2

[root@server2 ~]# ip addr add 172.25.6.100/32 dev eth0

[root@server2 ~]# ip addr

[root@server2 ~]# yum install -y arptables_jf

[root@server2 html]# arptables -A IN -d 172.25.6.100 -j DROP

[root@server2 html]# arptables -A OUT -s 172.25.6.200 -j mangle --mangle-ip-s 172.25.6.2

[root@server2 html]# /etc/init.d/arptables_jf save

[root@server2 html]# /etc/init.d/httpd restart

Operations on Server3

[root@server3 ~]# /etc/init.d/httpd start

[root@server3 ~]# ip addr add 172.25.6.100/32 dev eth0 ##Add ip to intranet NIC

[root@server3 ~]# ip addr

[root@server3 ~]# yum install -y arptables_jf

[root@server3 html]# arptables -A IN -d 172.25.6.100-j DROP ##Append policy to this address

[root@server3 html]# arptables -A OUT -s 172.25.6.100-j mangle --mangle-ip-s 172.25.6.3 ##Add policy, jump from 100 source address to 3

[root@server3 ~]# /etc/init.d/arptables_jf save ##Save added policies

[root@server3 ~]# /etc/init.d/arptables_jf start

[root@server3 ~]# /etc/init.d/httpd restart

Testing:

2. High Availability and Load Balancer

[root@server1 ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm

[root@server1 ~]# cd /etc/ha.d/

[root@server1 ha.d]# vim ldirectord.cf

[root@server1 ha.d]# ipvsadm -C##Purge policy

[root@server1 ha.d]# ipvsadm -L ##View policy

[root@server1 ha.d]# ip addr del 172.25.6.100/24 dev eth0 ##Delete ip on intranet NIC

[root@server1 ha.d]# vim haresources

[root@server1 ha.d]# scp haresources ldirectord.cf 172.25.6.4:/etc/ha.d/ ##server4 Do the same on server1

Turn on heartbeat on server4 instead of heartbeat on server1

[root@server1 html]# /etc/init.d/httpd restart

Testing:

If httpd is open for server2 and server3

If server2 and server3 httpd are down, access the host where heartbeat resides

4.keepalived

Close Heartbeat for Server1 and Server4, Open httpd for Server2 and Server3

Operations on Server1

[root@server1 ~]# tar zxf keepalived-1.2.20.tar.gz

[root@server1 ~]#cd keepalived-1.2.20/

[root@server1 keepalived-1.2.20]# ./ configure --prefix=/usr/local/keepalived/ ##Interpret to specified path

[root@server1 keepalived-1.2.20]# make && make install

[root@server1 keepalived-1.2.20]# cd /usr/local/keepalived/

[root@server1 local]# scp -r keepalived/ 172.25.6.4:/usr/local/

[root@server1 sbin]#

ln -s /usr/local/keepalived/sbin/keepalived /sbin/

[root@server1 etc]# ln -s /usr/local/keepalived/etc/keepalived/ /etc/

[root@server1 sysconfig]#

ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

[root@server1 sysconfig]#

ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

[root@server1 init.d]# chmod +x keepalived

[root@server1 init.d]# cd /etc/keepalived/

[root@server1 keepalived]# ls

keepalived.conf samples

[root@server1 keepalived]# vim keepalived.conf

[root@server1 keepalived]# /etc/init.d/keepalived start

Send the modified configuration file to server4 at the same location

Operations on Server4

[root@server4 keepalived]#

ln -s /usr/local/keepalived/sbin/keepalived /sbin/

[root@server4 keepalived]#

ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d

[root@server4 keepalived]#

chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived

[root@server4 keepalived]#

ln -s /usr/local/keepalived/etc/sysconfig/keepalived /

etc/sysconfig/

[root@server4 keepalived]# /etc/init.d/keepalived start

[root@server4 keepalived]# mkdir /etc/keepalived/

Change server1 to server4, state to backup,

The virtual_router_id of the two must be different, and the priority value of server4 is less than the value of server1.

Restart keepalived

Testing:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report