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

Building LVSkeepalived- Multi-web applications based on DR pattern

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

Share

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

Server partition

Note: test environment, so nginx and Apache are deployed on the same real server

Master and backup and real server servers are common.

VIP

172.20.0.210

Master

172.20.0.22

Backup

172.20.0.25

Real_server

172.20.0.22

Real_server

172.20.0.25

Web: nginx

Port:8220

Web: Apache

Port:8221

Master and backup deployment installation ipvsadm

Create the appropriate directory

[root@SALT1 ~] # mkdir software

[root@SALT1 ~] # cd software/

Download the installation package:

The corresponding commands are:

Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz

View kernel parameters

[root@SALT1 software] # uname-a

Linux SALT1 2.6.32-431.el6.x86_64 # 1 SMP Sun Nov 10 22:19:54 EST 2013 x86 "64 GNU/Linux

Create a soft connection, do not create this link, ipvsadm compilation installation can not go through.

[root@SALT1 software] # ln-s / usr/src/kernels/2.6.32-431.el6.x86_64/ / usr/src/linux

Compile and install ipvsadm

[root@SALT1 software] # ls

Ipvsadm-1.24.tar.gz

[root@SALT1 software] # tar-xvf ipvsadm-1.24.tar.gz

Ipvsadm-1.24/config_stream.c

Ipvsadm-1.24/config_stream.h

…… .

[root@SALT1 software] # cd ipvsadm-1.24

[root@SALT1 ipvsadm-1.24] # make & & make install

Make-C libipvs

Make [1]: Entering directory `/ root/software/ipvsadm-1.24/libipvs'

Gcc-Wall-Wunused-Wstrict-prototypes-g-O2-I/usr/src/linux/include-DHAVE_NET_IP_VS_H

…… ..

Load the IP_VS module of LVS

[root@ccb log] # ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

[root@ccb log] # lsmod | grep ip_vs

Ip_vs 115643 0

Libcrc32c 1246 1 ip_vs

Ipv6 321422 31 ip_vs

Install keepalived

Download the installation package

The corresponding commands are:

[root@SALT1 software] # wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz

-- 2016-07-13 14-14-9-14-14-14-9-7-13-14-14-9-14-14-14-14-14-14-14-14-14-14-14-14-14-14-14-14-http://www.keepalived.org/software/keepalived-1.1.19.tar.gz

Resolving www.keepalived.org... 37.59.63.157, 2001:41d0:8:7a9d::1

Connecting to www.keepalived.org | 37.59.63.157 |: 80. Connected.

HTTP request sent, awaiting response... 200 OK

Length: 241437 (236K) [application/x-gzip]

Saving to: "keepalived-1.1.19.tar.gz"

241437 190K/s in 1.2s

2016-07-13 14:09:06 (190 KB/s)-"keepalived-1.1.19.tar.gz" saved [241437max 241437]

Compile and install keepalived

[root@SALT1 software] # tar-xvf keepalived-1.1.19.tar.gz

Keepalived-1.1.19/

Keepalived-1.1.19/config.log

Keepalived-1.1.19/configure

Keepalived-1.1.19/README

Keepalived-1.1.19/ChangeLog

Keepalived-1.1.19/Makefile.in

…… ..

[root@SALT1 software] # cd keepalived-1.1.19

[root@SALT1 keepalived-1.1.19] #. / configure-prefix=/usr/local/keepalived

Checking for gcc... Gcc

……

[root@SALT1 keepalived-1.1.19] #

[root@SALT1 keepalived-1.1.19] # make

Make-C lib | | exit 1

Make [1]: Entering directory `/ root/software/keepalived-1.1.19/lib'

Gcc-g-O2-I. -Wall-Wunused-Wstrict-prototypes-c memory.c

Gcc-g-O2-I. -Wall-Wunused-Wstrict-prototypes-c utils.c

……

Make complete

[root@SALT1 keepalived-1.1.19] # make install

Make-C keepalived install

Make [1]: Entering directory `/ root/software/keepalived-1.1.19/keepalived'

Install-d / usr/local/keepalived/sbin

……

Create the appropriate directory

[root@ccb keepalived-1.1.19] # cp / usr/local/keepalived/sbin/keepalived / usr/sbin/

[root@ccb keepalived-1.1.19] # cp / usr/local/keepalived/etc/sysconfig/keepalived / etc/sysconfig/

[root@ccb keepalived-1.1.19] # cp / usr/local/keepalived/etc/rc.d/init.d/keepalived / etc/init.d/

[root@ccb keepalived-1.1.19] # mkdir / etc/keepalived/

[root@ccb keepalived-1.1.19] # cd

[root@ccb ~] # cp / usr/local/keepalived/etc/keepalived/keepalived.conf / etc/keepalived/

At this point, lvskeepalived installation is complete.

Keepalived configuration Master configuration:

[root@localhost ~] # vi / etc/keepalived/keepalived.conf

# global define

Global_defs {

Router_id node-A

}

Vrrp_sync_group test {

Group {

Test

}

}

Vrrp_instance test {

State MASTER

Interface eth2

Lvs_sync_daemon_interface eth2

Virtual_router_id 50

Priority 180

Advert_int 3

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

172.20.0.210

}

}

Virtual_server 172.20.0.210 8220 {

Delay_loop 3

Lb_algo rr

Lb_kind DR

Persistence_timeout 1

Protocol TCP

Real_server 172.20.0.22 8220 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8220

}

}

Real_server 172.20.0.25 8220 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8220

}

}

}

Virtual_server 172.20.0.210 8221 {

Delay_loop 3

Lb_algo rr

Lb_kind DR

Persistence_timeout 1

Protocol TCP

Real_server 172.20.0.25 8221 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8221

}

}

Real_server 172.20.0.22 8221 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8221

}

}

}

Backup configuration

[root@localhost ~] # vi / etc/keepalived/keepalived.conf

# global define

Global_defs {

Router_id node-B

}

Vrrp_sync_group test {

Group {

Test

}

}

Vrrp_instance test {

State BACKUP

Interface eth2

Lvs_sync_daemon_interface eth2

Virtual_router_id 50

Priority 150

Advert_int 3

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

172.20.0.210

}

}

Virtual_server 172.20.0.210 8220 {

Delay_loop 3

Lb_algo rr

Lb_kind DR

Persistence_timeout 1

Protocol TCP

Real_server 172.20.0.22 8220 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8220

}

}

Real_server 172.20.0.25 8220 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8220

}

}

}

Virtual_server 172.20.0.210 8221 {

Delay_loop 3

Lb_algo rr

Lb_kind DR

Persistence_timeout 1

Protocol TCP

Real_server 172.20.0.25 8221 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8221

}

}

Real_server 172.20.0.22 8221 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8221

}

}

}

Web Application configuration:

Confirm that nginx and apache are started:

[root@localhost sbin] # lsof-iRose 8220

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

Nginx 22005 root 6u IPv4 86789 0t0 TCP *: 8220 (LISTEN)

Nginx 22006 nobody 6u IPv4 86789 0t0 TCP *: 8220 (LISTEN)

[root@localhost sbin] # lsof-iRu 8221

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

Httpd 22012 root 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22015 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22016 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22017 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22018 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22019 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22020 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22021 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Httpd 22022 apache 4U IPv6 86820 0t0 TCP *: 8221 (LISTEN)

Create lvsDR_node scripts on both real_server:

[root@localhost ~] # vi / etc/init.d/lvsDR_node

#! / bin/bash

# descript: start real server DR

VIP=172.20.0.210

. / etc/rc.d/init.d/functions

Case "$1" in

Start)

Echo "start LVS of RealServer DR"

/ sbin/ifconfig lo:0$ VIP broadcast $VIP netmask 255.255.255.255 up

Echo "1" > / proc/sys/net/ipv4/conf/all/arp_ignore

Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce

Stop)

/ sbin/ifconfig lo:0 down

Echo "close LVS of RealServer DR"

Echo "0" > / proc/sys/net/ipv4/conf/all/arp_ignore

Echo "0" > / proc/sys/net/ipv4/conf/all/arp_announce

*)

Echo "Usage: $0 {start | stop}"

Exit 1

Esac

Start keepalived:

Start the keepalived on the master and backup servers, respectively:

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

Starting keepalived: [OK]

[root@localhost ~] #

Start lvsDR_node on real_server

[root@localhost ~] # / etc/init.d/lvsDR_node start

Start LVS of RealServer DR

Verify: view startup status:

Master:

Backup

Web handoff verification Apache authentication

Nginx authentication:

Now the VIP is on the master server (172.20.0.22). In order to ensure that the application can be accessed properly after the web application switch, stop the nginx and apache on the master server. :

You can see that both nginx and Apache are inaccessible on the 22 server.

Nginx:

Apache:

View status:

Use VIP to access:

As shown in the figure above, after switching between web applications, web applications can still be accessed normally through VIP.

VIP handoff verification:

Toggle VIP

Master:

Backup

Nginx authentication:

Apache authentication:

Note: when keepalived on master starts again, VIP will immediately switch to master, and backup will automatically switch to backup state.

As shown in the figure:

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