memcached集群搭建

memcache集群

1. 实验准备

1)服务器规划

主机IP角色
host1192.168.1.115客户机
host2192.168.1.116magnet 1
host3192.168.1.118magnet 2
host4192.168.1.117memcache主
host5192.168.1.131memcache从

2)需要软件包

magnet:libevent-2.022 keepalived
memcache:libevent-2.022 memcache-1.436

2. 操作过程

1)host2~5安装libevent

    5  tar -zxf libevent-2.0.22-stable.tar.gz -C /usr/src
    6  cd /usr/src/libevent-2.0.22-stable/
    7  ./configure --prefix=/usr/
    8  make && make install

2)host4 host5安装memcache

    7  tar -zxf memcached-1.4.36.tar.gz -C /usr/src
    8  cd /usr/src/memcached-1.4.36/
    9  ./configure --prefix=/usr/local/memcached --with-libevent=/usr/
   10  make
   11  make install
   16  ln -s /usr/local/memcached/bin/* /usr/local/bin/

3)启动两台memcache

host4 启动memcache
[root@localhost ~]# memcached -d -m 512 -u root -l 192.168.1.117 -p 11211

host 5 启动memcache
[root@localhost ~]# memcached -d -m 512 -u root -l 192.168.1.131 -p 11211

4)host2 host3 安装magnet

   10  tar -zxf magent-0.6.tar.gz -C /usr/local/magnet/
   11  cd /usr/local/magnet/
   12  vim ketama.h
   添加(头部添加):
   #ifndef SSIZE_MAX
   #define SSIZE_MAX 32767
   #endif
   13  ln -s /usr/lib64/libm.so /usr/lib64/libm.a
   23  ln -s /usr/lib64/libevent-2.0.so.5 /usr/lib64/libevent.a
   15  ldconfig
   16  sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
   18  make
   26  cp magent /usr/bin/

5) host2 host3 上搭建keepalived 虚拟IP设定为192.168.1.100

   32  yum -y install openssl-devel popt-devel
   31  tar -zxf keepalived-1.2.13.tar.gz -C /usr/src/
   32  cd /usr/src/keepalived-1.2.13/
   33  ./configure --prefix=/ 
   34  make && make install
[root@localhost keepalived-1.2.13]# vim /etc/keepalived/keepalived.conf 
vrrp_instance VI_1 {
    state MASTER  #第二台改为BACKUP
    interface ens33  #本机内网网卡名
    virtual_router_id 51
    priority 100  # 第二台改为90


    virtual_ipaddress {
        192.168.1.100
    }

[root@localhost keepalived-1.2.13]# /etc/init.d/keepalived start

6)启动两台magent(启动命令相同)

magent 启动参数
-u:用户
-n:最大连接数
-l:magent 对外监听IP 地址
-p:magent 对外监听端口
-s:magent 主缓存IP 地址和端口
-b:magent 备缓存IP 地址和端口
# magent -u root -n 51200 -l 192.168.1.100 -p 12000 -s 192.168.1.117:11211 -b 192.168.1.131:11211 

7)各主机关闭防火墙

systemctl stop firewalld

7)客户机登陆验证

# yum -y install telnet
[root@localhost ~]# telnet 192.168.1.100 12000
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is '^]'.
set today 0 0 6
sunday
STORED

去主memcache上查看键值对情况
[root@localhost ~]# telnet 192.168.1.117 11211
Trying 192.168.1.117...
Connected to 192.168.1.117.
Escape character is '^]'.
get today
VALUE today 0 6
sunday
END

去从memcache查看键值对情况
[root@localhost ~]# telnet 192.168.1.131 11211
Trying 192.168.1.131...
Connected to 192.168.1.131.
Escape character is '^]'.
get today 
VALUE today 0 6
sunday
END

memcache主从转进行同步,集群搭建完成
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值