Get the App
SLTechnology News&Howtos  ›  Servers  › 

Memcached cluster

Shulou Source: shulou.com Published: 2022-06-03 06:46:25 09月24日 Update

Configure memcached master cache node and slave cache node-start three virtual machines with the same configuration: 192.168.80.100 configure memcached master cache node 192.168.80.101 configure memcached slave cache node 192.168.80.1021. Turn off the fire wall machine and Selinux [important] (start all three to start) systemctl stop firewalld / / turn off firewall setenforce 0 / / turn off monitoring 2. Install the environment package yum install gcc gcc-c++ make-y

3. Compile and install libevent (must be installed first) install upload software yum install lrz*-y

# decompress tar xf libevent-2.1.8-stable.tar.gz-C / opttar xf memcached-1.5.6.tar.gz-C / opt/# and change to the libevent directory cd / opt/libevent-2.1.8-stable/

# configure. / configure-- prefix=/usr/local/libevent# compile and install make & & make install3. Compile and install memcached# switch to memcachedcd / opt/memcached-1.5.6/# configuration (specify libevent path). / configure\-- prefix=/usr/local/memcached\-- with-libevent=/usr/local/libevent/# compile and install make & & make install4. Optimized startup (Mencached that supports replication requires an installed libevent-2.1.so.6 module, otherwise the startup service will report an error) ln-s / usr/local/libevent/lib/libevent-2.1.so.6.0.2 / usr/lib64/libevent-2.1.so.6 5. Start the memcached# master server cd / usr/local/memcached/bin/./memcached-d-m 32m-l 192.168.80.100-p 11211-u root# slave server cd / usr/local/memcached/bin/./memcached-d-m 32m-l 192.168.80.101-p 11211-u root6. Check whether memcached starts netstat-anpt | grep memcached netstat-ntap | grep 11211

Magent is installed on the master server, and the slave server does not need to install magent1. Create the magent directory mkdir / opt/magent2. Decompress tar xf magent-0.5.tar.gz-C / opt/magent3. Change to the directory cd / opt/magent4. Make dynamic link libraries shared by the system / sbin/ldconfig

5. Edit ketama.h to add file header information vi ketama.h # ifndef SSIZE_MAX # define SSIZE_MAX 32767

6. Modify the Makefilevi Makefile / / libevent installation path to use the following in / usr/local/libevent: LIBS =-levent-lm-L / usr/local/libevent/libINCLUDE=-I / usr/local/libevent/include

Magent + Keepalived to implement Memcached high availability cluster 7. Compile (an executable file for manage will be generated after completion) make

8. Copying mgent commands to system management makes it easy to use cp / opt/magent/magent / usr/bin/9. Send to slave server scp / opt/magent/magent root@192.168.80.101:/usr/bin

Install keepalivedyum-y install keepalived1. Edit the keepalived configuration file vi / etc/keepalived/keepalived.conf to delete the contents and add the following! Configuration File for keepalivedglobal_defs {router_id magent_H1 # specify router_id} vrrp_script magent {# define function script "/ root/shell/magent.sh" interval 2} vrrp_instance VI_1 {state MASTER interface ens32 # Local Nic name virtual_router_id 51 # id Master / Slave consistent priority # Master priority is greater than slave priority advert_int 1 authentication {auth_type PASS auth_pass 1111} track_script {# call function magent} virtual_ipaddress {# vip address 192.168.80.188}}

two。 Set up the shell directory mkdir / root/shell3. Create the magent.sh script vi / rootamp gt gt magent.wc gt binamplash bashKeepalive = `ps-gt | grep keepalived | grep-v grep | wc-l`if [$Root-gt 0] Then magent-u root-n 51200-l 192.168.80.188-p 12000-s 192.168.80.100 192.168.80.101:11211else pkill 11211-b 192.168.80.101:11211else pkill-9 magentfi parameter description:-n 51200 # defines the maximum number of user connections-l 192.168.175.188 # specifies virtual IP-p 12000 # specify port number-s # specify master cache server-b # specify slave cache server

4. Give the script execution permission chmod + x / root/shell/magent.sh5. Start the keepalived service systemctl enable keepalivedsystemctl start keepalivednetstat-anpt | grep 12000

6. Check keepalived service status systemctl status keepalived

7. Check the vip address ip addr show ens32

Netstat-anpt | grep 11211

Operate on the slave server 1. Install keepalivedyum-y install keepalived2. Copy the keepalived configuration file on the primary server to scp root@192.168.80.100:/etc/keepalived/keepalived.conf / etc/keepalived/keepalived.conf

3. Edit the keepalived configuration file vi / etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {router_id magent_H2 # specify router_id} vrrp_script magent {# define function script "/ root/shell/magent.sh" interval 2} vrrp_instance VI_1 {state BACKUP interface ens33 # Local Nic name virtual_router_id 51 # id Master / Slave consistent priority 90 # Master priority is greater than slave priority advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {# vip address 192.168.80.188} track_script {# call function magent}}

4. Create a new shell directory mkdir / root/shell5. Create the magent.sh script vi / root192.168.80.101:11211else pkill gt magent.rootKeepalived gt. Create a then magent script, then magent root-n 51200-l 192.168.80.100 192.168.80.101:11211else pkill 11211-b Keepaliv-9 magentfi

6. Give the script execution permission chmod + x / root/shell/magent.sh7. Start the keepalived service systemctl enable keepalivedsystemctl start keepalived

8. Check keepalived service status systemctl status keepalived

9. Check the vip address ip addr show ens32

Test 1 on the client side. Install telnet client yum install telnet-y

two。 Connect memcached test copy function / / connect vip to test, insert user key value telnet 192.168.80.188 12000Trying 192.168.80.188...Connected to 192.168.80.188.Escape character is'^] '.set user 0 (tag) 0 (cache time never expires) 5 (cache content) 12345STOREDget userVALUE user 0 512345ENDquitConnection closed by foreign host.// connect Memcached1, query user key value, you can get, successful! Telnet 192.168.80.100 11211Trying 192.168.80.100...Connected to 192.168.80.100.Escape character is'^] .get userVALUE user 0 512345ENDquitConnection closed by foreign host.

/ / Connect to Memcached2, query the user key value, and you can also get it. Success! [root@centos7-1 ~] # telnet 192.168.80.101 11211Trying 192.168.80.101...Connected to 192.168.80.101.Escape character is'^] .get userVALUE user 0 512345ENDquitConnection closed by foreign host.

Test a single point of failure to stop the master server, connect to the drift address, and see if there is any content

Tags: Service server configuration cache compilation content address file directory check priority function script node test switch consistency success master-slave function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Shulou Tech Info Microsoft Redmi