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

Haproxy+Keepalived+MySQL to achieve load balancing by reading

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Environment description: the data security of this system is not high, and the TPS operation is very low, mainly the query environment.

The architecture of this solution is as follows: the application server connects the virtual IP address to the read-only application, connects to haproxy, and then transfers the TCP protocol to the following three database servers through haproxy. Haproxy is here to do layer 4 TCP switching service. Keepalived to prevent haproxy from a single point of failure. Why not use LVS? We have fewer environment servers, the performance of haproxy is similar to that of lvs, and haproxy comes with mysql check, so there is no need to write additional mysql detection scripts.

1.haproxy installation

Download address: http://www.haproxy.org/download/1.5/src/haproxy-1.5.5.tar.gz

Dependency package installation: # yum install gcc gcc-c++ make zlib-devel bzip2-devel openssl-devel

When pcre is installed, the version of pcre-7.8-3.1.el6.x86_64 that comes with it seems to be low, so proxy cannot be installed.

# tar xzvf pcre-8.34.tar.gz

# cd pcre-8.34#./configure-prefix=/usr\-docdir=/usr/share/doc/pcre-8.34\-enable-utf-enable-unicode-properties\-enable-pcregrep-libz-enable-pcregrep-libbz2#make#make check#make install

Script "/ etc/keepalived/check_haproxy.sh" interval 2 weight 2

Global_defs {router_id LVS_DEVEL}

Vrrp_instance VI_1 {state MASTER interface bond0 virtual_router_id 51 priority 150 advert_int 1 authentication {auth_type PASS auth_pass 1111} track_script {chk_http_port} virtual_ipaddress {192.168.231.18}

Configure the script to detect the status of haproxy: # vi / etcswap keepalivedstop check the etc/haproxy/haproxy.confsleep haproxy.shemaking bind Bash A = `ps-C haproxy-- no-header | wc-l`if [$A-eq 0]; then / usr/local/sbin/haproxy-f / etc/haproxy/haproxy.confsleep 3

If [`ps-C haproxy-- no-header | wc-l`-eq 0]; then / etc/init.d/keepalived stopfifi

Start the keepalived service: # / etc/init.d/keepalived start

Add a new protocol address: # ip add [root@mss-dn03 ~] # ip add1: lo: mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00 qdisc mq state DOWN qlen 0000 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 90:e2:ba:23:87:04 brd ff:ff:ff : ff:ff:ff3: eth2: mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 90:e2:ba:23:87:05 brd ff:ff:ff:ff:ff:ff

9: bond0: mtu 1500 qdisc noqueue state UP link/ether 6c:ae:8b:26:52:3b brd ff:ff:ff:ff:ff:ff inet 192.168.231.7/24 brd 192.168.231.255 scope global bond0 inet6 fe80::6eae:8bff:fe26:523b/64 scope link tentative dadfailed valid_lft forever preferred_lft forever

Set to enable self-startup: # chkconfig-- level 0123456 keepalived on# chkconfig-- list keepalived

During the test, it is found that after master downtime, VIP takes dozens of seconds to ping, and the switch is very slow: arping-I bond0-c 5-s VIP GATEWAY# arping-I bond0-c 5-s 192.168.231.18 192.168.231.254

Getting started with HAProxy and MySQL replication (read-write routing):

Http://blog.yannickjaquier.com/linux/getting-started-with-haproxy-and-mysql-replication.html Haproxy configuration Log: http://www.linuxidc.com/Linux/2012-06/63585.htm

From Weizhi Notes (Wiz)

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

Database

Wechat

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

12
Report