标签:地方 figure make .so ade 实例 emctl cal 高可用
实验拓扑服务器 | IP地址 | 操作系统 | 主要软件 |
---|---|---|---|
memcached1 | 192.168.144.122 | centos7.3 | libevent2.1.8、memcached1.5.6、keepalive、telnet、magent0.5 |
memcached2 | 192.168.144.129 | centos7.3 | libevent、memcached、keepalive、telnet |
客户端 | 192.168.144.141 | centos7.3 | LAMP架构或telnet |
tar zvxf memcached-1.5.6.tar.gz -C /opt/
tar zvxf libevent-2.1.8-stable.tar.gz -C /opt/
cd /opt/libevent-2.1.8-stable
./configure --prefix=/usr/local/libevent
make && make install
cd /opt/memcached-1.5.6
./configure \
--prefix=/usr/local/memcached \
--with-libevent=/usr/local/libevent/ #需要跟上事件通知库模块make && make install
ln -s /usr/local/memcached/bin/* /usr/local/bin/
ln -s /usr/local/libevent/lib/libevent-2.1.so.6 /usr/lib64/libevent-2.1.so.6
tar magent-0.5.tar.gz -C /opt/
cd /opt
vi ketama.h
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767 //前两行带#的改成这样
#endif //位置上调
systemctl stop firewalld.service
setenforce 0
vi Makefile
LIBS = -levent -lm -L/usr/local/libevent/lib //注意libevent的安装路径,否则make会报错
INCLUDE = -I/usr/local/libevent/include
make
cp magent /usr/local/bin/
scp magent root@192.168.144.129:/usr/bin/
yum install keepalved -y
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
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 001 //两台服务器不同
}
vrrp_script magent { //添加主主数据复制实例,函数名为magent,只要keepalive启动就可启动复制
script "/opt/shell/magent.sh" //设置magent启动脚本,注意后面脚本位置要与之相同
interval 2
}
vrrp_instance VI_1 {
state MASTER //从为BACKUP
interface ens33 //网卡为ens33
virtual_router_id 51 //与从服务器需要区别开
priority 100 //从服务器优先级应当比主的低
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script { //调用函数执行
magent
}
virtual_ipaddress {
192.168.144.188 //设置虚拟IP
}
}
cd /opt/shell #没有该目录,需要创建
vim 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.144.188 -p 12000 -s 192.168.144.122:11211 -b 192.168.144.129:11211
else
pkill -9 magent
fi
-n 51200 //定义用户最大连接数
-l 192.168.175.188 //指定虚拟IP
-p 12000 //指定端口号
-s //指定主缓存服务器
-b //指定从缓存服务器
chmod +x /opt/shell/magent.sh
memcached -d -m 32m -p 11211 -u root
systemctl start keepalived.service
vi magent.sh #注意脚本位置要跟配置文件中对应,不然调用执行
#!/bin/bash
K=`ip addr | grep 192.168.144.188 | grep -v grep | wc -l`
if [ $K -gt 0 ]; then
magent -u root -n 51200 -l 192.168.144.188 -p 12000 -s 192.168.144.122:11211 -b 192.168.144.129:11211
else
pkill -9 magent
fi
chmod +x /opt/shell/magent.sh
memcached -d -m 32m -p 11211 -u root
systemctl start keepalived.service
telnet 192.168.144.188 12000
add username 0 0 7
1234567
systemctl stop keepalived.service
memcached实现主主复制和keepalive高可用方式
标签:地方 figure make .so ade 实例 emctl cal 高可用
原文地址:http://blog.51cto.com/13659253/2150250