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

Load balancer

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Load balancer: nginx/haproxy/lvs/F5

Agent:

Forward proxy: helps clients cache data on the server

Reverse proxy: helps the server cache data

HAProxy:

1. Installation

[root@vh04 bin] # yum install-y haproxy

2. Modify the configuration file

[root@vh04 bin] # vim / etc/haproxy/haproxy.cfg

Delete all the following parts of # main frontend which proxys to the backends and add the following:

Define a monitoring page

Listen stats

Bind 0.0.0.0:1080

Stats refresh 30s

Stats uri / mystats

Stats realm Ha Manager

Stats auth admin:admin

Listen web-discuz 0.0.0.0:80

Cookie SERVERID rewrite

Balance roundrobin

Server web1 192.168.4.2:80 cookie a1i1 check inter 2000 rise 2 fall

five

Server web2 192.168.4.3:80 cookie a1i2 check inter 2000 rise 2 fall 5

3. Start the service

[root@vh04 bin] # systemctl start haproxy

4. Visit http://192.168.4.4 to realize load balancer polling and scheduling, and visit http://192.168.4.4:1080/mystats to see the monitoring page.

Configure vh04 as the log server so that you can receive logs sent by haproxy over the network

1. Configure vh04 to accept logs sent from the network

[root@vh04 bin] # vim / etc/rsyslog.conf # Provides UDPsyslogreception

$ModLoad imudp

$UDPServerRun 51mm Provides TCP syslog reception

$ModLoad imtcp

$InputTCPServerRun 514

2. Restart the log service

[root@vh04 bin] # systemctl restart rsyslog

3. Track the tail of the log. You can see the log by visiting http://192.168.4.4.

[root@vh04 bin] # tail-f / var/log/messages

You can execute the logger command to write logs to syslog, as shown in

[root@vh04 bin] # logger "my test log"

[root@vh04 bin] # tail-2 / var/log/messages

HSRP: hot backup routing protocol, cisco private

VRRP: virtual redundant routing Protocol, IETF (Internet engineer Task Force) Common Standard

HA: high availability

Heartbeat: HearBeat, equivalent to a hello message on a router device

Dual hot backup: keepalived

1. Implement a highly available web cluster

1. Topology: two Web servers and one database server.

2. Install keepalived on the web server

[root@vh02 ~] # yum install-y keepalived

3. Modify the configuration

[root@vh02 ~] # vim / etc/keepalived/keepalived.conf # vrrp_strict comment out this line

Vrrp_instance VI_1 {

State MASTER secondary server changed to BACKUP

Interface eth0

Virtual_router_id 51 Virtual Router ID

Priority 150 priority

Advert_int 1 heartbeat message is sent in 1s.

Authentication {shared password on both sides

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {Virtual IP address

192.168.4.200

}

}

Delete all follow-up content

4. Start the service

[root@vh02 ~] # systemctl start keepalived

5. View the virtual ip address

[root@vh02 ~] # ip address show eth0

6. Verify: disable the keepalived of vh02 and vip will appear on vh03.

Configure highly available, load-balanced web clusters

1. Create a virtual machine vh05 (used as an additional scheduler)

Vh05.tedu.cn 192.168.4.5/24 selinux/firewall/yum

2. Clear the rules for lvs on vh04, because the rules will be configured by keepalived

[root@vh04 bin] # ipvsadm-D-t 192.168.4.10080

3. Install lvs on vh05

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

4. Web server needs to configure vip on lo and modify kernel parameters.

5. Do not manually configure VIP on the scheduler, because it is up to keepalived to decide which scheduler VIP appears on. So get rid of vh04's VIP.

[root@vh04 bin] # ifdown eth0:0

[root@vh04 bin] # rm-f / etc/sysconfig/network-scripts/ifcfg-eth0:0

6. Install keepalived on the scheduler

[root@vh04 bin] # yum install-y keepalived

7. Modify the configuration

[root@vh04 bin] # vim / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Notification_email {root@localhostbr/ > root@localhost

Notification_email_from admin@tedu.cn

Smtp_server 127.0.0.1

Smtp_connect_timeout 30

Router_id LVS_DEVEL

Vrrp_skip_check_adv_addr# vrrp_strict

Vrrp_garp_interval 0

Vrrp_gna_interval 0

}

Vrrp_instance VI_1 {

State MASTER

Interface eth0

Virtual_router_id 51

Priority 150

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

192.168.4.100

}

}

Virtual_server 192.168.4.100 80 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Within persistence_timeout 50 # 50 seconds, the same client is always scheduled to the same server

Protocol TCP

Real_server 192.168.4.2 80 {weight 1 TCP_CHECK {connect_timeout 3 nb_get_retry 3 delay_before_retry 3}} real_server 192.168.4.3 80 {weight 1 TCP_CHECK {connect_timeout 3 nb_get_retry 3 delay_before_retry 3}}

}

Delete the subsequent contents of the profile

8. Start the service

[root@vh04 bin] # systemctl start keepalived

9. After the backup lvs scheduler starts, there is no VIP. You can turn off vh04 and check the status of vh05.

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