溫馨提示×

溫馨提示×

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

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

memcached高可用群集部署

發(fā)布時間:2020-06-10 18:04:49 來源:網(wǎng)絡(luò) 閱讀:265 作者:caozhengtao1213 欄目:系統(tǒng)運維

環(huán)境部署

服務(wù)器角色 IP地址 需要安裝的軟件包
主緩存服務(wù)器 192.168.142.130 Telnet、libevent、memcached、keepalived、magent
從緩存服務(wù)器 192.168.142.131 Telnet、libevent、memcached、keepalived
客戶端 192.168.142.132 Telnet

第一步:配置memcached主緩存服務(wù)器

#掛載軟件包
mount.cifs //192.168.142.1/memcached /mnt
cd /mnt/memcached

#創(chuàng)建目錄
mkdir /opt/magent       

#解壓安裝包
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

#進(jìn)行編譯安裝
cd /opt/libevent-2.1.8-stable/
./configure --prefix=/usr
make && make install
cd /opt/memcached-1.5.6/
./configure --with-libevent=/usr
make && make install

cd /opt/magent/

vim ketama.h
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif
#第一行末尾添加-lm
vim Makefile
LIBS = -levent-lm

#編譯
make

#安裝openssh
yum install openssh-clients -y
cp magent /usr/bin

#推送magent文件
scp magent root@192.168.142.131:/usr/bin

#關(guān)閉防火墻和安全功能
systemctl stop firewalld.service 
setenforce 0

#安裝keepalived
yum install keepalived -y

#修改配置文件
vim /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

#寫入下列內(nèi)容,定義函數(shù)
vrrp_script magent {
        script "/opt/shell/magent.sh"
        interval 2
}

#修改route-id
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_HAL
   #修改id名
}

#修改網(wǎng)卡端口
vrrp_instance VI_1 {
    state MASTER
    interface ens33         #修改網(wǎng)卡信息
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    #修改,調(diào)用上邊函數(shù)
    track_script {
        magent
   }
    virtual_ipaddress {
        192.168.142.100     #定義虛擬IP地址
    }
}

mkdir /opt/shell
cd /opt/shell/

#配置從服務(wù)器腳本
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.142.100 -p 12000 -s 192.168.45.132:
11211 -b 192.168.142.131:11211
else
pkill -9 magent
fi

chmod +x magent.sh
#啟動
systemctl start keepalived.service

#查看遷移地址
ip addr

#啟動主服務(wù)器
memcached -m 512k -u root -d -l 192.168.142.130 -p 11211

#查看端口是否正常開啟
netstat -anptu | grep 11211

第二步:配置memcached從緩存服務(wù)器

#掛載軟件包
mount.cifs //192.168.142.1/memcached /mnt

#解壓安裝包
cd /mnt/memcached
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

cd /opt/libevent-2.1.8-stable/
./configure --prefix=/usr
make && make install

cd /opt/memcached-1.5.6/
./configure --with-libevent=/usr
make && make install

[root@localhost memcached-1.5.6]# cd /etc/keepalived/
[root@localhost keepalived]# mv keepalived.conf keepalived.conf.bk
[root@localhost keepalived]# touch keepalived.conf
[root@localhost keepalived]# vim keepalived.conf

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 MAGENT_HB      #id名不可與主服務(wù)器相同
}

vrrp_instance VI_1 {
    state BACKUP            #設(shè)定從服務(wù)器
    interface ens33
    virtual_router_id 52    #id號不可與主服務(wù)器相同
    priority 90             #優(yōu)先級低與主服務(wù)器 
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    track_script {
        magent
   }
    virtual_ipaddress {
        192.168.142.100     #定義虛擬IP地址
    }
}

mkdir /opt/shell
cd /opt/shell/

#配置從服務(wù)器腳本
vim magent.sh
#!/bin/bash
K=`ip addr | grep 192.168.142.100 | grep -v grep | wc -l`
if [ $K -gt 0 ];then
        magent -u root -n 51200 -l 192.168.142.100 -p 12000 -s 192.168.142.130:
11211 -b 192.168.142.131:11211
else
pkill -9 magent
fi
chmod +x magent.sh

#啟動keepalived
systemctl start keepalived.service

#關(guān)閉防火墻和安全功能
systemctl stop firewalld.service 
setenforce 0

#啟動從服務(wù)器
memcached -m 512k -u root -d -l 192.168.142.131 -p 11211

#查看端口是否正常開啟
netstat -anptu | grep 11211

#安裝telent進(jìn)行測試
yum install telnet -y

第三步:客戶端測試

#關(guān)閉防火墻和安全功能
systemctl stop firewalld.service 
setenforce 0

#安裝telent進(jìn)行測試
yum install telnet -y

#使用漂移地址登錄連接
telnet 192.168.142.100 12000

#創(chuàng)建鍵值對,驗證主從同步
add username 0 0 7
1234567

#雙機(jī)熱備
#停掉主服務(wù)器
systemctl stop keepalived.service

#使用漂移地址登錄連接
telnet 192.168.142.100 12000

謝謝閱讀!!!

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

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

AI