四臺(tái)電腦
memcache:192.168.1.201 192.168.1.202
magent: 192.168.1.100 192.168.1.101
實(shí)驗(yàn):
1、安裝libevent軟件(四臺(tái))
[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臺(tái))
[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臺(tái))
[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
無(wú)法make的時(shí)候需要安裝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/
主緩存和備緩存一樣的啟動(dòng)命令(-l 是漂移IP 還沒(méi)有搭建Keepalived服務(wù) 暫時(shí)不要啟動(dòng)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 對(duì)外監(jiān)聽(tīng)I(yíng)P 地址
-p:magent 對(duì)外監(jiān)聽(tīng)端口
-s:magent 主緩存IP 地址和端口
-b:magent 備緩存IP 地址和端口
[root@localhost ~]# ps -elf | grep magent
4、安裝keepalived 軟件(Magent 服務(wù)器 2臺(tái))
[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.
說(shuō)明主緩存節(jié)點(diǎn)和備緩存節(jié)點(diǎn)都有數(shù)據(jù)。
宕掉主緩存節(jié)點(diǎn)。
1)停止memcached進(jìn)程(或者斷開(kāi)主緩存節(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ù)會(huì)丟失。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
新聞標(biāo)題:memcache集群-創(chuàng)新互聯(lián)
本文來(lái)源:http://chinadenli.net/article20/dojeco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、服務(wù)器托管、網(wǎng)站收錄、企業(yè)網(wǎng)站制作、網(wǎng)站排名、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容