码迷,mamicode.com
首页 > 系统相关 > 详细

memcached群集

时间:2018-07-25 23:58:45      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:gcc-c++   软件包   amp   grep -v   val   51cto   关闭防火墙   服务器   ipa   

本实验实现的是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 //查看虚拟地址

技术分享图片

在客户机上安装telnet

# yum install telnet -y

技术分享图片

memcached群集

标签:gcc-c++   软件包   amp   grep -v   val   51cto   关闭防火墙   服务器   ipa   

原文地址:http://blog.51cto.com/13620936/2150215

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!