您好,登錄后才能下訂單哦!
今天小編給大家分享的是web中的memcache緩存服務器的詳細介紹,相信大部分人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,話不多說,一起往下看吧。
MemCache 是一個自由、源碼開放、高性能、分布式的分布式內存對象緩存系統(tǒng),用于動態(tài)Web 應用以減輕數(shù)據(jù)庫的負載。它通過在內存中緩存數(shù)據(jù)和對象來減少讀取數(shù)據(jù)庫的次數(shù),從而提高了網站訪問的速度。
實驗:
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 服務器 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 服務器 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
[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 服務 暫時不要啟動 Magent 服務)
[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 服務器 2 臺)
[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-kerneldir=/usr/src/kernels/2.6.32-431.el6.x86_64
[root@localhost keepalived-1.2.13]# make && make install
配置主緩存服務器
[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
配置備緩存服務器
[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ù)與主緩存服務器保持一致----
}
[root@localhost ~]# service keepalived restart
[root@localhost ~]# ip add show dev eth0
驗證:
客戶端 ping 192.168.1.10 查看 VIP 的變化情況。
5、驗證:
1)用主緩存節(jié)點連接上主緩存的 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é)點的 11211 端口進行查看
[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é)點的 11211 端口進行查看
[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é)點和備緩存節(jié)點都有數(shù)據(jù)。
宕掉主緩存節(jié)點。
1)停止 memcached 進程(或者斷開主緩存節(jié)點的網卡),
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
總結:
memcache 的優(yōu)點:可以做多主或者多從
memcache 的缺點:當主緩存節(jié)點當?shù)粲只謴?,之前的緩存?shù)據(jù)會丟失。
配置主緩存服務器
vim keepalived.conf
! Configuration File for keepalived
global_defs {
** router_id magent-1**
}
vrrp_instance VI_1 {
state **MASTER**
interface **ens33**
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.164.100 #漂移地址
}
}
scp keepalived.conf 192.168.164.7:/etc/keepalived/
備服務器
cd /etc/keepalived/
vim keepalived.conf
! Configuration File for keepalived
global_defs {
** router_id magent-2**
}
vrrp_instance VI_1 {
state **BACKUP**
interface **ens33**
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.164.100 #漂移地址
}
}
啟動keepalived
systemctl start keepalived.service
主緩存和備緩存一樣的啟動命令(-l 是漂移 IP 還沒有搭建 Keepalived 服務 暫時不要啟動 Magent 服務)
magent -uroot -n 51200 -l 192.168.164.100 -p 12000 -s 192.168.164.8:11211 -b 192.168.164.9:11211
以上就是memcache緩存服務器的具體介紹,內容較為全面,而且我也相信有相當?shù)囊恍┕ぞ呖赡苁俏覀內粘9ぷ骺赡軙姷交蛴玫降?。通過這篇文章,希望你能收獲更多。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。