實(shí)驗(yàn)環(huán)境:
實(shí)驗(yàn)?zāi)康模?/strong>
實(shí)現(xiàn)存儲(chǔ)內(nèi)容的主從備份
1、掛載軟件包
#掛載軟件包
mount.cifs //192.168.100.3/lzp /mnt
#創(chuàng)建目錄
mkdir /opt/magent
#解壓必要安裝包
cd /mnt/mem
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
2、對(duì)組件進(jìn)行編譯安裝
#編譯安裝libevent
cd /opt/libevent-2.1.8-stable/
./configure --prefix=/usr
make && make install
#編譯安裝memcached
cd /opt/memcached-1.5.6/
./configure --with-libevent=/usr
make && make install
#編譯安裝magent
cd /opt/magent/
#修改ketama.h配置文件
vim ketama.h
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#將#endif移動(dòng)到第三行,刪除掉末尾的
#endif
vim Makefile
#第一行末尾添加-lm
LIBS = -levent-lm
#編譯
make
#編譯好的magent文件
3、將編譯好的magent文件復(fù)制到/usr/bin目錄下,并推送給從服務(wù)器
#安裝openssh推送軟件
yum install openssh-clients -y
#將編譯好的magent文件復(fù)制到/usr/bin目錄下
cp magent /usr/bin
#推送magent文件
scp magent root@192.168.45.131:/usr/bin
The authenticity of host '192.168.45.131 (192.168.45.131)' can't be established.
ECDSA key fingerprint is SHA256:bw2256OHr5apf7CliZv/fAOyVNVsMmRn+lZ5efeQgTg.
ECDSA key fingerprint is MD5:6f:f6:70:4f:46:64:ec:17:a7:ae:c0:15:1c:8b:55:1c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.45.131' (ECDSA) to the list of known hosts.
root@192.168.45.131's password:
magent 100% 112KB 5.8MB/s 00:00
4、關(guān)閉防火墻和安全功能
systemctl stop firewalld.service
setenforce 0
5、安裝keepalived,并進(jìn)行修改
#安裝keepalived
yum install keepalived -y
#修改配置文件
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
#寫入下列內(nèi)容
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
#修改route-id
router_id MAGENT_HA
}
vrrp_instance VI_1 {
state MASTER
#修改網(wǎng)卡端口
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
#修改,調(diào)用上邊函數(shù)
track_script {
magent
}
virtual_ipaddress {
#設(shè)置虛擬指向地址
192.168.45.188
}
}
6、創(chuàng)建magent腳本
mkdir /opt/shell
cd /opt/shell/
vim 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.45.188 -p 12000 -s 192.168.45.132:
11211 -b 192.168.45.131:11211
else
pkill -9 magent
fi
#給于運(yùn)行權(quán)限
chmod +x magent.sh
7、啟動(dòng)服務(wù),并查看
#啟動(dòng)keepalived
systemctl start keepalived.service
#查看遷移地址
ip addr
#啟動(dòng)memcached
memcached -m 512k -u root -d -l 192.168.45.132 -p 11211
安裝telent進(jìn)行測(cè)試
yum install telnet -y
1、掛載軟件包,并關(guān)閉防火墻和安全功能
mount.cifs //192.168.100.3/lzp /mnt
#關(guān)閉防火墻和安全功能
systemctl stop firewalld.service
setenforce 0
2、解壓安裝包,并進(jìn)行編譯
#解壓安裝包
cd /mnt/mem
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
#編譯安裝libevent
cd /opt/libevent-2.1.8-stable/
./configure --prefix=/usr
make && make install
#編譯安裝memcached
cd /opt/memcached-1.5.6/
./configure --with-libevent=/usr
make && make install
3、安裝keepalived
#安裝keepalived
yum install keepalived -y
#修改keepalived文件
cd /etc/keepalived/
mv keepalived.conf keepalived.conf.bk
vim 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
router_id MAGENT_HB
}
vrrp_instance VI_1 {
state BACKUP
#修改網(wǎng)絡(luò)接口
interface ens33
#修改virtual_router_id
virtual_router_id 52
#修改優(yōu)先級(jí)
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
magent
}
virtual_ipaddress {
#修改地址
192.168.45.188
}
}
4、創(chuàng)建magent腳本
mkdir /opt/shell
cd /opt/shell/
vim magent.sh
#!/bin/bash
K=`ip addr | grep 192.168.45.188 | grep -v grep | wc -l`
if [ $K -gt 0 ];then
magent -u root -n 51200 -l 192.168.45.188 -p 12000 -s 192.168.45.132:
11211 -b 192.168.45.131:11211
else
pkill -9 magent
fi
chmod +x magent.sh
4、啟動(dòng)服務(wù)
#啟動(dòng)keepalived
systemctl start keepalived.service
#啟動(dòng)memcached
memcached -m 512k -u root -d -l 192.168.45.131 -p 11211
安裝telent進(jìn)行測(cè)試
yum install telnet -y
#關(guān)閉防火墻和安全功能
systemctl stop firewalld.service
setenforce 0
#安裝telnet
yum install telnet -y
#在telnet中寫入文件
[root@manager ~]# telnet 192.168.45.188 12000
Trying 192.168.45.188...
Connected to 192.168.45.188.
Escape character is '^]'.
add username 0 0 7
1234567
STORED
在從服務(wù)器上查看
在主服務(wù)器上查看
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站chinadenli.net,海內(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)景需求。
分享文章:Memcache高可用群集-創(chuàng)新互聯(lián)
文章位置:http://chinadenli.net/article40/djgpeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、網(wǎng)站收錄、軟件開發(fā)、品牌網(wǎng)站設(shè)計(jì)、動(dòng)態(tài)網(wǎng)站、響應(yī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í)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容