群集—memcache群集

一、安装部署memcache群集架构:

实验准备:
在主服务器上:
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 install

vim /opt/magent/ketama.h   在开头修改,再将最后的endif删除!
#ifndef SSIZE_MAX 
#define SSIZE_MAX 32767 
#endif

Vim Makefile
LIBS = -levent -lm     ##在第一行

make
cp magent /usr/bin/
yum install openssh-clients -y
scp magent root@14.0.0.15:/usr/bin   ###将自己身上的magent启动脚本送给到从服务器
yum install keepalived -y
*****************************************************************
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

vrrp_script magent {
      script "/opt/shell/magent.sh"
      interval 2
}

global_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_HA   **
}

vrrp_instance VI_1 {
    state MASTER       
    interface ens33              **
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

track_script {
       magent
   }

virtual_ipaddress {
        14.0.0.188       **自己设定只要不和自己上面的一样就行
    }
}
cd /etc/keepalived/
scp keepalived.conf root@14.0.0.15:/etc/keepalived/
mkdir /opt/shell

vim /opt/shell/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 14.0.0.188 -p 12000 -s 14.0.0.14:11211 -b 14.0.0.15:11211
 else
 pkill -9 magent
fi

chmod +x magent.sh
systemctl start keepalived.service
netstat -natp | grep 12000
memcached -m 512k -u root -d -l 14.0.0.14 -p 11211
netstat -natp | grep 11211
yum install telnet -y



在从服务器上:
tar zxvf libevent-2.1.8-stable.tar.gz -C /opt/       ###事件通知库
tar zxvf memcached-1.5.6.tar.gz -C /opt/           ###服务端
yum install gcc gcc-c++ -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 install
yum install keepalived -y
cd /etc/keepalived/
mv keepalived.conf keepalived.conf.bak
vim /etc/keepalived/keepalived.conf
state MASTER >>>BACKUP
virtual_router_id 51 >>52
priority 100 >> 80

mkdir /opt/shell

vim /opt/shell/magent.sh
K=`ip addr | grep 14.0.0.188 | grep -v grep | wc -l`
if [ $K -gt 0 ]; then
  magent -u root -n 51200 -l 14.0.0.188 -p 12000 -s 14.0.0.14:11211 -b 14.0.0.15:11211start
 else
 pkill -9 magent
fi

chmod +x magent.sh
systemctl start keepalived.service
netstat -natp | grep 12000
memcached -m 512k -u root -d -l 14.0.0.15 -p 11211
netstat -natp | grep 11211
yum install telnet -y

二、memcached+lamp:

实验准备:
memcache服务端:14.0.0.120
memcache客户端:14.0.0.200
实验过程:
tar zxvf memcached.tar.gz -C /opt/
tar zxvf libevent-stables.tar.gz -C /opt/
cd /opt/   看一下
yum install gcc gcc-c++ make -y
cd libevent-stable/
./configure --prefix=/usr/local/libevent
make && make install 
cd .../memcache/
./configure --prefix=/usr/local/memcached \
--with-libevent=/usr/local/libevent/
make && make install
ln -s /usr/local/memcached/bin/* /usr/local/bin/
memcached -d -m 32m -p 11211 -u root
netstat -ntap | grep memc
systemctl stop firewalld.service
setenforce 0
yum install telnet -y 

telnet 127.0.0.1 11211
add username 0(不设置序列号) 0(不记时间) n(输入的字节长度,一定要匹配上,不然报错!!)
get username
gets username   多一个更行因子(更新一次就+1)
set username    有就修改,没有就添加
replace  school 0 0 2    必须存在
cas username 0 0 7       更新因子相同才能更改
append       在后面添加 
prepend      在前面添加


安装lnmp:
mysql -u root -p 
CREATE DATABASE sky;
GRANT all ON sky.* TO 'skyuser'@'%' IDENTIFIED BY '123';
flush privileges;

cd /usr/local/httpd/htdocs
vim index.php
<?php
$link=mysql_connect('14.0.0.120','skyuser','123');
if($link) echo "<h1> Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>

yum install autoconf -y
tar zxvf memcache.tar.gz -C /opt/
cd /opt/memcache/
/usr/local/php5/bin/phpize
./configure \
--enbles-memcache \
--with-php-config=/usr/local/php5/bin/php-config
make && make install 
vim /usr/local/php5/php.ini 
extension_dir="/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"
extension=memcache.so
vim /usr/local/httpd/htdocs/index.php
<?php
$memcache = new Memcache();
$memcache-> connect('14.0.0.120',11211);
$memcache-> set ('key','Memcache test Successful!',0,60);
$result = $memcache -> get('key');
unset($memcache);
echo $result;
?>
systemctl httpd restart
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值