In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the example analysis of Memcached high availability cluster, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Characteristics of Memcached:
1. There is no limit to the amount of item data that can be saved in Memcached, as long as there is enough memory
The maximum memory used by a single process in 2.Memcached is 2GB. To use more memory, you can start multiple Memcached processes on different ports.
3.Memcached is a non-blocking socket communication service, based on libevent library, because of non-blocking communication, read and write to memory very fast
4.Memcached is divided into server and client. Multiple servers and clients can be configured. It is widely used in distributed services.
5.Memcached is very efficient as a small-scale data distributed platform.
Server IP address software package main Memcached192.168.5.129libevent-2.1.8-stable.tar.gz, memcached-1.5.9.tar.gz, magent-0.5.tar.gz, keepalived build Memcached server from Memcached192.168.5.139libevent-2.1.8-stable.tar.gz, memcached-1.5.9.tar.gz, magent-0.5.tar.gz, keepalivedClient192.168.5.141telnet
The Memcached server needs to be built on both servers in exactly the same way. When installing the memcached server, you need to install libevent first, and then install memcached.
Install the environment package
Yum-y install gcc gcc-c++ make
Compile and install libevent (must be installed first)
# decompression
Tar zxvf libevent-2.1.8-stable.tar.gz-C / opt
# change to the libevent directory
Cd / opt/libevent-2.1.8-stable/
# configuration
. / configure-- prefix=/usr/
# compilation and installation
Make & & make install
Compile and install memcached
# decompression
Tar zxvf memcached-1.5.9.tar.gz-C / opt/
# switch to memcached
Cd / opt/memcached-1.5.9/
# configuration (specify libevent path)
. / configure-- with-libevent=/usr/
# compilation and installation
Make & & make install
Optimized startup (Mencached that supports replication requires the installed libevent-2.1.so.6 module, otherwise the startup service will report an error)
Ln-s / usr/lib/libevent-2.1.so.6 / usr/lib64/libevent-2.1.so.6
Install magent on the primary server
Magent is a memcached proxy software, to prevent a single point of failure, the cache proxy can also backup, through the client connection cache proxy server, cache proxy server connection cache server.
# create a magent directory
Mkdir / opt/magent
# decompression
Tar zxvf magent-0.5.tar.gz-C / opt/magent
# switch to directory
Cd / opt/magent
# make dynamic link libraries shared by the system
/ sbin/ldconfig
# Edit ketama.h and add file header information
Vim ketama.h
# ifndef SSIZE_MAX#define SSIZE_MAX 32767#endif
# Editing Makefile
Vi Makefile
LIBS =-levent-lm
# compile (an executable file for manage will be generated after completion)
Make
# make the service easy for the system to identify
Cp / opt/magent/magent / usr/bin/scp / opt/magent/magent root@192.168.5.139:/usr/bin/ send to install keepalived from the server
# install keepalived from master server
Yum-y install keepalived
# modify the master-slave server configuration file
Vim / etc/keepalived/keepalived.conf
! Configuration File for keepalivedglobal_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 router_id MAGENT_H1 / / router_id customization But make sure that the master and slave are consistent} vrrp_script magent {script "/ root/shell/magent.sh" interval 2 / / defines a function, which has not been created yet To define} vrrp_instance VI_1 {state MASTER / / slave for BACKUP interface ens33 virtual_router_id 51 / / id is the same here priority 100 / / Master server priority is higher than slave server advert_int 1 authentication {auth_type PASS auth_pass 1111} track_script {magent / / Application Function} virtual_ipaddress {192.168.5.100 / / define vtp customization As long as the address is not in use} / / there are extra contents under the configuration file that can be deleted directly at this time.
# create a shell directory
Mkdir / root/shell
# create magent.sh script
Vim / root/shell/magent.sh
#! / bin/bashKeepalived= `ps-ef | grep keepalived | grep-v grep | wc-l`if [$Keepalived-gt 0]; then magent-u root-n 51200-l 192.168.5.100-p 12000-s 192.168.5.129 192.168.5.139:11211else pkill 11211-b 192.168.5.139:11211else pkill-9 magentfi
Parameter description:
-n 51200 # define the maximum number of user connections-l 192.168.5.100 # specify virtual IP-p 12000 # specify port number-s # specify master cache server-b # specify slave cache server
# Grant script execution permission
Chmod + x / root/shell/magent.sh
# start the keepalived service
Systemctl enable keepalived.service
Systemctl start keepalived.service
Operating on the slave server
# copy the keepalived configuration file on the master server
Scp root@192.168.5.129:/etc/keepalived/keepalived.conf / etc/keepalived/keepalived.conf
# Editing keepalived configuration file
Vim keepalived.conf
! Configuration File for keepalivedglobal_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 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 Network Card name virtual_router_id 51 # id Master / Slave consistent priority 99 # Master Server priority is higher than Slave Server priority advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {# vip address 192.168.5.100} track_script {# call function magent}}
# create magent.sh script
Mkdir / root/shell
Vim / root/shell/magent.sh
#! / bin/bashKeepalived= `ip addr | grep 192.168.5.100 | grep-v grep | wc-l`if [$Keepalived-gt 0]; then magent-u root-n 51200-l 192.168.5.100-p 12000-s 192.168.5.129 grep 11211-b 192.168.5.139:11211else pkill-9 magentfi
# Grant script execution permission
Chmod + x / root/shell/magent.sh
# start the keepalived service
Systemctl enable keepalived.service
Systemctl start keepalived.service
Open memcached on the master and slave server
Memcached-m 512k-u root-d-l 192.168.5.129-p 11211 / / master server
Memcached-m 512k-u root-d-l 192.168.5.139-p 11211 / / slave server
Netstat-ntap | grep 11211
Client test connectivity
# install telnet client
Yum-y install telnet
# Connect to memcached
Telnet 192.168.175.188 12000
# Test the replication function
/ / Connect vip for testing, and insert user key value
[root@localhost ~] # telnet 192.168.5.100 12000Trying 192.168.5.100...Connected to 192.168.5.100.Escape character is'^] .set user 00 5test1STOREDget userVALUE user 0 5test1ENDquitConnection closed by foreign host.// connect to the main Memcached and query the user key value, which can be obtained successfully! [root@localhost ~] # telnet 192.168.5.129 11211Trying 192.168.5.129...Connected to 192.168.5.129.Escape character is'^] .get userVALUE user 0 5test1ENDquitConnection closed by foreign host.// connection from Memcached, query user key value, can also be obtained, successful! [root@centos7-1 ~] # telnet 192.168.5.139 11211Trying 192.168.96.17...Connected to 192.168.96.17.Escape character is'^] .get userVALUE user 0 5test1ENDquitConnection closed by foreign host. Test a single point of failure to shut down the primary server
View from the server
Client connection
This is the end of the sample analysis on the Memcached high availability cluster. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.