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

Implementation of memcached + keepalived High availability Cluster under Centos7

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

Share

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

Introduction to memcached + keepalived High availability Cluster memcached

Memcached is an open source high-performance distributed in-memory object caching system that stores all data.

Stored in memory, because a large Hash table is maintained in memory, any storage type is supported

data. Many websites improve their access speed by using Memcached, especially for large-scale needs

A website that accesses data.

Memcached is a typical Cmax S architecture, so the Memcached server and Memcached need to be installed.

API client. The Memcached server is written in C, while the Memcached API client can use the

Write in any language, such as PHP, Python, Perl, etc., and communicate with Memcached server through Memcached protocol

The server communicates with each other.

Introduction of memcached Master-Slave replication + keepalived High availability Framework

Memcached server modification data will be synchronized to the

The other one, but the Memcached API client cannot tell which Memcached service to connect to

, so you need to set the VP address and provide it to the Memcached Apl client to connect. Can be used

The VP address generated by keepalived connects to the primary Memcached server and provides a highly available architecture.

Because the Memcached master-slave replicates this architecture, the program connects to the master service

Add a VP address to the front end to achieve a highly available architecture. This is implemented in Keepalived, so

The purpose of Keepalived is to detect whether the state of the Memcached server is normal.

Keepalived constantly detects port 11211 of the Memcached master server, if Memcached is detected

If the service goes down or crashes, the VP will be moved from the master server to the slave server, thus realizing the

High availability of Memcached.

Experimental preparation

A primary server

Magent memcached libevent keepalived needs to be installed

A slave server

Memcached libevent keepalived needs to be installed

Experimental steps to install memcached and libeventtar xzvf memcached-1.5.6.tar.gztar xzvf libevent-2.1.8-stable.tar.gzcd libevent-2.1.8./configure on the master server and slave server-- prefix=/usr # specify the installation path make & & make install cd memcached-1.5.6./configure-- with-libevent=/usrmake & & make installln-s / usr/lib/libevent-2.1.so.6 / usr/lib64/ Libevent-2.1.so.6 # # the magent service on the master server requires this module to install magentmkdir / magenttar xzvf magent-0.5.tar.gzcd / magentvim ketama.h on the master server to modify # ifndef SSIZE_MAX#define SSIZE_MAX 32767vim MakefileLIBS =-levent-lmmakecp magent / usr/bin # # to facilitate system identification commands to copy magent on the master server to the slave server yum install openssh-clientsscp magent root@192.168.x.x: / usr/bin install keepalivedvim / etc/keepalived/keepalived.confrouter-_id MAGENT_HA on the master server delete vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 define new function vrrp_script magent {script "/ opt/shell/magent.sh" interval 2 # # interval} modify INTERFACE ens33 under vrrp_instance add track_script {magent} # use the new letter Number defines a virtual IPvirtual_ipaddress {192.168.x.x} below redundant parts can be deleted to install keepalivedyum install keepalived on the slave server copy the configuration script from the master server to the slave server scp / etc/keepalived/keepalived.conf root@192.168.x.x.:/etc/keepalived/keepalived.confvim / etc/keepalivedrouter_id MAGENT_HBstate BACKUP # # slave server virtual_router_id 52 # # ID configure magent script mkdir / opt/shell vim / opt/shell/magent.sh #! / bin/bashK= `ps-ef on the master server with different priortity 90 # # priorities | grep keepalived | grep-v grep | wc-l`if [$K-gt 0] Then magent-u root-n 51200-l 192.168.x.x-p 12000-s 192.168.x.x:11211-b 192.168.x.x:11211elsepkill-9 magentfi-n 51200 / define the maximum number of user connections-l 192.168.x.x / / specify virtual IP-p 12000 / / specify port number-s / / specify master cache server-b / / specify slave cache server chmod + x magent.sh Configure the magent script mkdir / opt/shell vim / opt/shell/magent.sh #! / bin/bash K = `ip addr | grep 192.168.x.x (virtual IP) | grep-v grep | wc-l`if [$K-gt 0] on the server Then magent-u root-n 51200-l 192.168.x.x-p 12000-s 192.168.x.x:11211-b 192.168.x.x:11211elsepkill-9 magentfi chmod + x magent.sh Master / Slave server enables keepalived service systemctl start keepalived.servicenetstat-ntap | grep 12000 if port 12000 indicates that the service is enabled, log in to the memcached server memcached-m 512k-u root-d-l 192.168.xx master-p 11211memcached-m 512k-u root- D-l 192.168.x.x slave-p 11211netstat-ntap | port 11211 of grep 11211 indicates that the service is enabled. Successfully test the installation of telnetyum install telnet-ytelnet 192.168.x.x (virtual IP) 12000add username 00 71234567Stored quit## on the third server through virtual IP login and creation of a user telnet 192.168.x.x (master / slave server) 11211get usernameVALUE username 0 71234567ENDquit## is available on both master and slave servers. Turn off memcachedpkill-9 memcached192.168.x.x (virtual IP) 12000add username 00 71234567Stored quit## on the master server through virtual IP write data telnet 192.168.x.x (slave server) 11211get usernameVALUE username 0 71234567ENDquit## from the server can still be read to this memcached+keepalived highly available cluster

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