温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

memcached群集

发布时间:2020-07-07 19:03:13 来源:网络 阅读:462 作者:凉夏了夏天 栏目:建站服务器

本实验实现的是memcached+magent+keepalived高可用群集:

  • magent:代理memcached实现负载均衡
  • keepalived:magent主从HA高可用
  • memcached:缓存对象

实验要求:

  • 服务器:192.168.177.140(magent+memcached+libevent+keepalived)
  • 从服务器:192.168.177.135(memcached+libevent+keepalived)
  • 客户机:192.168.177.132(telnet软件包)
挂载(主从)
# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt
# tar zxvf memcached-1.5.6.tar.gz -C /opt
# mkdir /opt/magent ==注==从服务器不做
# tar zxvf magent-0.5.tar.gz -C /opt/magent/
# yum install gcc gcc-c++ make -y
---
# cd /opt/libevent-2.1.8-stable/
  ./configure --prefix=/usr      
# make && make install

# cd memcached-1.5.6/
 ./configure --with-libevent=/usr    
# make && make instal
---
 只有主:
# cd /opt/magent/
# vim ketama.h
 ifndef SSIZE_MAX                
 define SSIZE_MAX 32767
# vim Makefile
 LIBS = -levent -lm
 make
安装openssh-clients
主服务器上:
# yum install openssh-clients -y
# cp magent /usr/bin/  //便于使用
# scp magent root@192.168.177.135:/usr/bin   //将magent复制到从服务器上
# systemctl stop firewalld.service  //关闭防火墙
# setenforce 0  //增强型安全功能
从服务器上:
# yum install openssh-clients
# systemctl stop firewalld.service
# setenforce 0
# cd /usr/bin
# ls
就会发现magent变成一个可执行的文件
安装keepalived
主服务器上:
# yum install keepalived -y
# vi /etc/keepalived/keepalived.conf 
 router_id MAGENT_HA
 interface ens33
 virtual_router_id 51
 priority 100
 virtual_ipaddress {
        192.168.177.188  //设置的虚拟IP
    }
vrrp_script magent {
        script "/opt/shell/magent.sh"
        interval 2
}
track_script {
        magent
}
# scp /etc/keepalived/keepalived.conf root@192.168.177.135:/etc/keepalived/keepalived.conf   //将keepalived.conf复制到从服务器上
从服务器上:
# vim /etc/keepalived/keepalived.conf
 修改:state :BACKUP
       interface ens33
       virtual_router_id 52
       priority 90
编辑脚本文件
主从一样:
# mkdir /opt/shell
# cd /opt/shell
# vi magent.sh
#!/bin/bash
K=`ps -ef | grep keepalived | grep -v grep | wc -l`
if [ $K -gt 0 ]; then
        magent -u root -n 51200 -l 192.168.177.188 -p 12000 -s 192.168.177.140:11211 -b 192.168.177.135:11211
else
pkill -9 magent
fi
# chmod +x magent.sh  //为脚本添加执行权限
# systemctl start keepalived.service //开启服务
启动memcached服务
# memcached -m 512k -u root -d -l 192.168.177.140 -p 11211 //主服务器上
# memcached -m 512k -u root -d -l 192.168.177.135 -p 11211   //从服务器上
ip addr //查看虚拟地址

memcached群集

在客户机上安装telnet
# yum install telnet -y

memcached群集

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI