环境部署
服务器角色 | IP地址 | 需要安装的软件包 |
---|
主缓存服务器 | 192.168.142.130 | Telnet、libevent、memcached、keepalived、magent |
从缓存服务器 | 192.168.142.131 | Telnet、libevent、memcached、keepalived |
客户端 | 192.168.142.132 | Telnet |
第一步:配置memcached主缓存服务器
mount.cifs
cd /mnt/memcached
mkdir /opt/magent
tar zxvf magent-0.5.tar.gz -C /opt/magent/
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++ make -y
cd /opt/libevent-2.1.8-stable/
./configure
make && make install
cd /opt/memcached-1.5.6/
./configure
make && make install
cd /opt/magent/
vim ketama.h
vim Makefile
LIBS = -levent-lm
make
yum install openssh-clients -y
cp magent /usr/bin
scp magent root@192.168.142.131:/usr/bin
systemctl stop firewalld.service
setenforce 0
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_HAL
}
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 {
192.168.142.100
}
}
mkdir /opt/shell
cd /opt/shell/
vim magent.sh
K=`ps -ef | grep keepalived | grep -v grep | wc -l`
if [ $K -gt 0 ];then
magent -u root -n 51200 -l 192.168.142.100 -p 12000 -s 192.168.45.132:
11211 -b 192.168.142.131:11211
else
pkill -9 magent
fi
chmod +x magent.sh
systemctl start keepalived.service
ip addr
memcached -m 512k -u root -d -l 192.168.142.130 -p 11211
netstat -anptu | grep 11211
第二步:配置memcached从缓存服务器
mount.cifs
cd /mnt/memcached
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++ make -y
cd /opt/libevent-2.1.8-stable/
./configure
make && make install
cd /opt/memcached-1.5.6/
./configure
make && make install
[root@localhost memcached-1.5.6]
[root@localhost keepalived]
[root@localhost keepalived]
[root@localhost 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_HB
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 52
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
magent
}
virtual_ipaddress {
192.168.142.100
}
}
mkdir /opt/shell
cd /opt/shell/
vim magent.sh
K=`ip addr | grep 192.168.142.100 | grep -v grep | wc -l`
if [ $K -gt 0 ];then
magent -u root -n 51200 -l 192.168.142.100 -p 12000 -s 192.168.142.130:
11211 -b 192.168.142.131:11211
else
pkill -9 magent
fi
chmod +x magent.sh
systemctl start keepalived.service
systemctl stop firewalld.service
setenforce 0
memcached -m 512k -u root -d -l 192.168.142.131 -p 11211
netstat -anptu | grep 11211
yum install telnet -y
第三步:客户端测试
systemctl stop firewalld.service
setenforce 0
yum install telnet -y
telnet 192.168.142.100 12000
add username 0 0 7
1234567
systemctl stop keepalived.service
telnet 192.168.142.100 12000
谢谢阅读!!!