本实验实现的是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 [email protected]:/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 [email protected]:/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
原文地址:http://blog.51cto.com/13620936/2150215
时间: 2024-10-09 05:29:08