大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

memcached群集

本实验实现的是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群集


网站栏目:memcached群集
当前链接:http://dzwzjz.com/article/jchsdg.html
在线咨询
服务热线
服务热线:028-86922220
TOP