您好,登錄后才能下訂單哦!
Magent緩存代理介紹
因為Memcached服務器與服務器之間沒有任何通訊,所以當任何服務器節點出現故障時,會出現單點故障。通過Magent緩存代理,防止單點現象。通過客戶端連接到緩存代理服務器,緩存代理服務器可以連接多臺Memcached機器并同時將每臺Memcached機器進行數據同步。如果其中一臺緩存服務器down機,系統依然可以繼續工作,如果其中一臺Memcached機器down掉,數據不會丟失并且可以保證數據的完整性。
原理演示圖:
實驗環境介紹:
三臺服務器:
master/slave/client
實驗步驟
在master和slave上同時安裝libevent、memcached
master&&slave:
systemctl stop firewalld.service
setenforce 0
tar zxvf memcached-1.5.6.tar.gz -C /opt
tar zxvf libevent-2.1.8-stable.tar.gz -C /opt
yum install gcc gcc-c++ -y
cd /opt/libevent-2.1.8-stable/
./configure --prefix=/usr/local
make && make install
cp /usr/local/lib/libevent-2.1.so.6 /usr/lib64/
cd /opt/memcached-1.5.6/
./configure --with-libevent=/usr/local
make && make install
在master上安裝配置magent
master:
mkdir /opt/magent
tar zxvf magent-0.5.tar.gz -C /opt
vim /opt/magent/ketama.h
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif
vim /opt/magent/Makefile
LIBS = -levent -lm 此處為英文單詞‘l’,不是1
make
將magent命令復制到slave服務器上
注:標記地方為需要更改的位置
yum install openssl-clients -y
cp magent /usr/bin
scp magent root@192.168.218.157:/usr/bin
yum install keepalived -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 MAGENT_HA
}
vrrp_script magent {
script "/opt/shell/magent.sh" 腳本位置
interval 2 檢測腳本為2秒
}
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 { 調用vrrp_script magent
magent
}
virtual_ipaddress {
192.168.218.16
}
}
從服務器上安裝配置keepalived
slave:
yum install openssl-clients -y
yum install keepalived -y
cd /etc/keepalived/
mv keepalived.conf keepalived.conf.bk
master:
cd /etc/keepalived/
scp keepalived.conf root@192.168.218.157:/etc/keepalived/keepalived.conf
slave:
vim /etc/keepalived/keepalived.conf
global_defs {
router_id MAGENT_HB
vrrp_instance VI_1 {
state BACKUP
virtual_router_id 52
priority 90
master:
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 192.168.218.16 -p 12000 -s 192.168.218.130:11211 -b 192.168.218.157:11211 else pkill -9 magent fichmod +x /opt/shell/magent.sh
systemctl start keepalived.servic
netstat -ntap | grep 12000 #此時檢查應有12000端口號
slave:
mkdir /opt/shell
vim /opt/shell/magent.sh
#!/bin/bash K=`ip addr | grep 192.168.218.16 | grep -v grep | wc -l` if [ $K -gt 0 ];then magent -u root -n 51200 -l 192.168.218.16 -p 12000 -s 192.168.218.130:11211 -b 192.168.218.157:11211 else pkill -9 magent fi
#magent -u指定用戶、-n指定連接數量、-l指定漂移地址、-p指定端口、-s指定主服務器地址、-b指定從服務器地址
chmod +x /opt/shell/magent.sh
systemctl start keepalived.servic
netstat -ntap | grep 12000 #此時檢查應有12000端口號
master:
memcached -m 512k -u root -d -l 192.168.218.130 -p 11211
netstat -ntap | grep 11211
slave:
memcached -m 512k -u root -d -l 192.168.218.157 -p 11211
netstat -ntap | grep 11211
測試:
master:
yum install telnet -y
telnet 192.168.218.130 11211
slave:
yum install telnet -y
telnet 192.168.218.157 11211
client:
yum install telnet -y
telnet 192.168.218.16 12000
Trying 192.168.218.16...
Connected to 192.168.218.16.
Escape character is '^]'.
add username 0 0 7 #寫入一段數據
1231231
STORED
slave:
telnet 192.168.218.157 11211
Trying 192.168.218.157...
Connected to 192.168.218.157.
Escape character is '^]'.
get username
VALUE username 0 7
1231231 #在主服務器和從服務器上可以看到同步過來的數據
END
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。