溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

memcache集群

發(fā)布時間:2020-07-04 07:15:55 來源:網(wǎng)絡(luò) 閱讀:392 作者:cmk577 欄目:數(shù)據(jù)庫

四臺電腦
memcache:192.168.1.201 192.168.1.202
magent: 192.168.1.100 192.168.1.101
實(shí)驗(yàn):
1、安裝libevent軟件(四臺)
[root@localhost ~]# tar -zxvf libevent-2.0.21-stable.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/libevent-2.0.21-stabl
[root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr/
[root@localhost libevent-2.0.21-stable]# make && make install
2、安裝memcached軟件(Memcached服務(wù)器 2臺)
[root@localhost ~]# tar -zxvf memcached-1.4.31.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/memcached-1.4.31/
[root@localhost memcached-1.4.31]# ./configure --enable-memcache --with-libevent=/usr/
[root@localhost memcached-1.4.31]# make && make install
主緩存:
[root@localhost ~]# memcached -d -m 1024 -u root -l 192.168.1.201 -p 11211
備緩存:
[root@localhost ~]# memcached -d -m 1024 -u root -l 192.168.1.202 -p 11211
[root@localhost ~]# netstat -anpt | grep memcached
3、安裝magent 軟件(Magent 服務(wù)器 2臺)
[root@localhost ~]# mkdir /usr/magent
[root@localhost ~]# tar -zxvf magent-0.6.tar.gz -C /usr/magent/
[root@localhost ~]# cd /usr/magent/
[root@localhost magent]# vim ketama.h
添加(頭部添加):
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif
[root@localhost magent]# ln -s /usr/lib64/libm.so /usr/lib64/libm.a
[root@localhost magent]# ln -s /usr/lib64/libevent-1.4.so.2 /usr/lib64/libevent.a
無法make的時候需要安裝libevent-1.4.so.2
[root@localhost magent]# /sbin/ldconfig
[root@localhost magent]# sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
[root@localhost magent]# make
[root@localhost magent]# cp magent /usr/bin/
主緩存和備緩存一樣的啟動命令(-l 是漂移IP 還沒有搭建Keepalived服務(wù) 暫時不要啟動Magent服務(wù))
[root@localhost ~]# magent -u root -n 51200 -l 192.168.1.10 -p 12000 -s 192.168.1.201:11211 -b 192.168.1.202:11211
[root@localhost ~]# magent -u root -n 51200 -l 192.168.1.10 -p 12000 -s 192.168.1.201:11211 -b 192.168.1.202:11211
-u:用戶
-n:最大連接數(shù)
-l:magent 對外監(jiān)聽IP 地址
-p:magent 對外監(jiān)聽端口
-s:magent 主緩存IP 地址和端口
-b:magent 備緩存IP 地址和端口
[root@localhost ~]# ps -elf | grep magent
4、安裝keepalived 軟件(Magent 服務(wù)器 2臺)
[root@localhost ~]# yum –y install openssl*
[root@localhost ~]# tar -zxvf keepalived-1.2.13.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/keepalived-1.2.13/
[root@localhost keepalived-1.2.13]# ./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64
[root@localhost keepalived-1.2.13]# make && make install
配置主緩存服務(wù)器
[root@localhost ~]# vim /etc/keepalived/keepalived.conf
修改:
global_defs {
router_id LVS_DEVEL_R1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.10
}
}
[root@localhost ~]# service keepalived restart
[root@localhost ~]# ip add show dev eth0
配置備緩存服務(wù)器
[root@localhost ~]# vim /etc/keepalived/keepalived.conf
修改:
global_defs {
router_id LVS_DEVEL_R2
}
vrrp_instance VI_1 {
state BACKUP
priority 99
......
virtual_ipaddress {
192.168.1.10
}
---其他參數(shù)與主緩存服務(wù)器保持一致----
}
[root@localhost ~]# service keepalived restart
[root@localhost ~]# ip add show dev eth0
驗(yàn)證:
客戶端ping 192.168.1.10 查看VIP的變化情況。
5、驗(yàn)證:
1)用主緩存節(jié)點(diǎn)連接上主緩存的1200端口插入數(shù)據(jù)
[root@localhost ~]# telnet 192.168.1.10 12000
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
set key 33 0 5
ggggg
STORED
quit
Connection closed by foreign host.
2)查看插入的數(shù)據(jù)
[root@localhost ~]# telnet 192.168.1.10 12000
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
get key
VALUE key 33 5
ggggg
END
quit
Connection closed by foreign host.
3)連接主緩存節(jié)點(diǎn)的11211端口進(jìn)行查看
[root@localhost ~]# telnet 192.168.1.201 11211
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is '^]'.
get key
VALUE key 33 5
ggggg
END
quit
Connection closed by foreign host.
4)連接主緩存節(jié)點(diǎn)的11211端口進(jìn)行查看
[root@localhost ~]# telnet 192.168.1.202 11211
Trying 192.168.1.200...
Connected to 192.168.1.200.
Escape character is '^]'.
get key
VALUE key 33 5
ggggg
END
quit
Connection closed by foreign host.
說明主緩存節(jié)點(diǎn)和備緩存節(jié)點(diǎn)都有數(shù)據(jù)。
宕掉主緩存節(jié)點(diǎn)。
1)停止memcached進(jìn)程(或者斷開主緩存節(jié)點(diǎn)的網(wǎng)卡),
2)客戶端查看
[root@localhost ~]# telnet 192.168.1.10 12000
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
get key
VALUE key 33 5
ggggg
END

總結(jié):
memcache的優(yōu)點(diǎn):可以做多主或者多從
memcache的缺點(diǎn):當(dāng)主緩存節(jié)點(diǎn)當(dāng)?shù)粲只謴?fù),之前的緩存數(shù)據(jù)會丟失。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI