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

Memcached High availability Cluster (Memcached Primary Primary replication + Keepalived)

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

Share

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

Case description

In order to solve the single point of failure of memcached, it is necessary to achieve the high availability of memcached cache.

First of all, you need to implement the master replication of Memcached, which means that the modified data of any memcached server will be synchronized to another server, but memcached API cannot tell which server to connect to, so VIP is required.

Second, connect to the memcached server through the VIP generated by Keepalived, providing a highly available architecture.

Case Topology

Case environment host IP address operating system main software Memcached 1192.168.37.128 Centos7libeventured memcachedkeepalivedvicentMemcached 1192.168.37.130Centos7libeventgentMemalived installation package

Link: https://pan.baidu.com/s/1tHnxoldZoX7U0aHnx6GlRg password: vl6l

Case implementation 1. Master-slave server installs memcached

1. Install the environment package

Yum install gcc gcc-c++ make-y

Systemctl stop firewalld.service

Setenforce 0

2. Decompress libevent and memecached packages

Tar zxvf libevent-2.1.8-stable.tar.gz-C / opt

Tar zxvf memcached-1.5.6.tar.gz-C / opt

3. Compile and install manually (note: libevent comes first and memcached comes later)

Cd / opt/libevent-2.1.8-stable/. / configure-- prefix=/usrmake & & make installcd / opt/memcached-1.5.6/. / configure-- with-libevent=/usrmake & & make install II. Install magent on the main server

1. Decompress magent

Mkdir / opt/magent

Tar zxvf magent-0.5.tar.gz-C / opt/magent/ # proxy, slave server does not need to install

2. Edit the configuration file

Modify the beginning of the cd / opt/magentvim ketama.h # file # ifndef SSIZE_MAX # define SSIZE_MAX 32767 # endif # remove the last endifvim Makefile LIBS =-levent-lm # pay attention to the space make # install magentls # view the magent executable

3. Copy the magent program to memcached slave server

Yum install openssh-clients-y # install the push plug-in

Cp magent / usr/bin/ # copies the compiled magent program to the slave server

Scp magent root@192.168.37.130:/usr/bin

Third, install keepalived on the main server

Yum install keepalived-y

Vim / etc/keepalived/keepalived.conf / / 12 Line router_id MAGENT_HA Delete 13-16 script interval under line 1 add vrrp_script magent {script "/ opt/shell/magent.sh" script 2 # interval 2s} vrrp_instance VI_1 {.interface ens33 # modify .track _ script {# call-add Note the parentheses magent} virtual_ipaddress # modify 192.168.37.188} # define the drift address} # delete the rest

4. Install keepalivedyum install keepalived-ycd / etc/keepalived/mv keepalived.conf keepalived.conf.bk # from the server to modify the configuration file name scp keepalived.conf root@192.168.37.130:/etc/keepalived/ # push vi keepalived.conf router_id MAGENT_HB state BACKUP virtual_router_id 52 priority 90 on the master server

Fifth, the master-slave server writes the script loaded by the keepalived configuration file

1. Create a directory

Mkdir / opt/shell

2. Write a script

Cd / opt/shellvim magent.sh #! / bin/bashK= `ps-ef | grep keepalived | grep-v grep | wc-l`if [$K-gt 0] Then magent-u root-n 51200-l 192.168.37.188-p 12000-s 192.168.37.128 192.168.37.130:11211elsepkill 11211-b 192.168.37.130:11211elsepkill-9 magentfi-n 51200 / / define the maximum number of user connections-l 192.168.37.188 / / specify virtual IP-p 12000 / / specify port number-s / / specify primary cache server-b / / specify add execution permissions from cache server chmod + x magent.sh #

3. Start the keepalived service on the master-slave server

Systemctl start keepalived.service

Netstat-ntap | grep 12000 # starts slowly. Confirm that magent is running.

4. Confirm that the drift address of the master-slave server is effective.

/ / Master server:

/ / from the server:

6. Enable memecached from the master-slave server

/ / Master server:

Memcached-m 512k-u root-d-l 192.168.37.128-p 11211

Netstat-ntap | grep 11211

Yum install telnet-y

Telnet 192.168.37.128 11211

/ / from the server:

Memcached-m 512k-u root-d-l 192.168.37.130-p 11211

Netstat-ntap | grep 11211

Yum install telnet-y

Telnet 192.168.37.130 11211

VII. Client testing

1. Connect to VIP and write data

Yum install telnet-y

Telnet 192.168.37.188 12000

Add username 0 0 4

1234

2. The master and slave server can see the written content.

3. Disconnect a memcached and visit it again, and the client can still connect

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