Memcache High availability Cluster
Memcache High availability Cluster
Experimental environment:
Experimental purpose:
Realize the master-slave backup of the stored content
Experimental construction: first, the main server:
1. Mount the software package
# Mount the package mount.cifs / / 192.168.100.3/lzp / mnt# create directory mkdir / opt/magent # decompress the necessary installation package cd / mnt/memtar zxvf magent-0.5.tar.gz-C / opt/magent/tar zxvf libevent-2.1.8-stable.tar.gz-C / opttar zxvf memcached-1.5.6.tar.gz-C / opt# install the necessary components yum install gcc gcc-c++ make-y
2. Compile and install the components
# compile install libeventcd / opt/libevent-2.1.8-stable/./configure-- prefix=/usrmake & & make install# compile install memcachedcd / opt/memcached-1.5.6/./configure-- with-libevent=/usrmake & & make install# compile install magentcd / opt/magent/# modify ketama.h configuration file vim ketama.h#ifndef SSIZE_MAX#define SSIZE_MAX 3276 move # endif to line 3 Delete the end of # endifvim Makefile# and add-lmLIBS =-levent-lm# to compile make at the end of the first line
# compiled magent file
3. Copy the compiled magent file to the / usr/bin directory and push it to the slave server.
# install openssh push software yum install openssh-clients-y # copy the compiled magent file to the / usr/bin directory cp magent / usr/bin# push magent file scp magent root@192.168.45.131:/usr/binThe authenticity of host '192.168.45.131 (192.168.45.131)' can't be established.ECDSA key fingerprint is SHA256:bw2256OHr5apf7CliZv/fAOyVNVsMmRn+lZ5efeQgTg.ECDSA key fingerprint is MD5:6f:f6:70:4f:46:64:ec:17 A7:ae:c0:15:1c:8b:55:1c.Are you sure you want to continue connecting (yes/no)? YesWarning: Permanently added '192.168.45.131' (ECDSA) to the list of known hosts.root@192.168.45.131's password: magent 100% 112KB 5.8MB/s 00:00
4. Turn off firewall and security features
Systemctl stop firewalld.service setenforce 0
5. Install keepalived and modify it
# install keepalivedyum install keepalived-y # modify the configuration file vim / etc/keepalived/keepalived.conf! Configuration File for keepalived# writes the following content vrrp_script magent {script "/ opt/shell/magent.sh" interval 2} global_defs {notification_email {acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc} notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 # modify route-id router_id MAGENT_HA} vrrp_instance VI _ 1 {state MASTER # modify Nic port interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication {auth_type PASS auth_pass 1111} # modify Call the above function track_script {magent} virtual_ipaddress {# to set the virtual pointing address 192.168.45.188}}
6. Create a magent script
Mkdir / opt/shellcd / opt/shell/vim magent.shangxinxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlcxlcxlcmllll`f; then magent-u root-n 51200-l 192.168.45.188-p 12000-s 192.168.45.132l1211-b 192.168.45.131:11211elsepkill-9 magentfi# are given to run permission chmod + x magent.sh.
7. Start the service and view
# launch keepalivedsystemctl start keepalived.service# to view the migration address ip addr# launch memcached memcached-m 512k-u root-d-l 192.168.45.132-p 11211
Install telent for testing
Yum install telnet-y II, slave server
1. Mount the software package and turn off the firewall and security features.
Mount.cifs / / 192.168.100.3/lzp / mnt# turn off firewall and security features systemctl stop firewalld.service setenforce 0
2. Extract the installation package and compile it
# decompress the installation package cd / mnt/memtar zxvf libevent-2.1.8-stable.tar.gz-C / opttar zxvf memcached-1.5.6.tar.gz-C / opt# install the necessary components package yum install gcc gcc-c++ make-y # compile and install libeventcd / opt/libevent-2.1.8-stable/./configure-- prefix=/usrmake & & make install# compilation and install memcachedcd / opt/memcached-1.5.6/./configure-- with-libevent=/usrmake & & make install
3. Install keepalived
# install keepalivedyum install keepalived-y # modify the keepalived file cd / etc/keepalived/mv keepalived.conf keepalived.conf.bkvim keepalived.conf! Configuration File for keepalivedvrrp_script magent {script "/ opt/shell/magent.sh" interval 2} global_defs {notification_email {acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc} notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 # modify router_id router_id MAGENT_HB} vrrp_instance VI_1 {state BACKUP # modify network interface interface ens33 # modify virtual_router_id virtual_router_id 52 # modify priority priority 90 advert_int 1 authentication {auth_type PASS auth_pass 1111} track_script {magent} virtual_ipaddress {# modify address 192.168.45.188}}
4. Create a magent script
Mkdir / opt/shellcd / opt/shell/vim magent.shangxinxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxmagent.sh; grep 192.168.45.13211211-b 192.168.45.131:11211elsepkill-9 magentfichmod + x magent.sh
4. Start the service
# start keepalivedsystemctl start keepalived.service # launch memcachedmemcached-m 512k-u root-d-l 192.168.45.131-p 11211
Install telent for testing
Yum install telnet-y
Client # turn off firewall and security features systemctl stop firewalld.service setenforce install telnet yum install telnet-y # write the file [root@manager ~] # telnet 192.168.45.188 12000Trying 192.168.45.188...Connected to 192.168.45.188.Escape character is'^ '.add username 00 71234567STORED in telnet
View from the server
View on the primary server