您好,登錄后才能下訂單哦!
實驗環境:
實驗目的:
實現存儲內容的主從備份
1、掛載軟件包
#掛載軟件包
mount.cifs //192.168.100.3/lzp /mnt
#創建目錄
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、對組件進行編譯安裝
#編譯安裝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移動到第三行,刪除掉末尾的
#endif
vim Makefile
#第一行末尾添加-lm
LIBS = -levent-lm
#編譯
make
#編譯好的magent文件
3、將編譯好的magent文件復制到/usr/bin目錄下,并推送給從服務器
#安裝openssh推送軟件
yum install openssh-clients -y
#將編譯好的magent文件復制到/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、關閉防火墻和安全功能
systemctl stop firewalld.service
setenforce 0
5、安裝keepalived,并進行修改
#安裝keepalived
yum install keepalived -y
#修改配置文件
vim /etc/keepalived/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
#修改route-id
router_id MAGENT_HA
}
vrrp_instance VI_1 {
state MASTER
#修改網卡端口
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
#修改,調用上邊函數
track_script {
magent
}
virtual_ipaddress {
#設置虛擬指向地址
192.168.45.188
}
}
6、創建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
#給于運行權限
chmod +x magent.sh
7、啟動服務,并查看
#啟動keepalived
systemctl start keepalived.service
#查看遷移地址
ip addr
#啟動memcached
memcached -m 512k -u root -d -l 192.168.45.132 -p 11211
安裝telent進行測試
yum install telnet -y
1、掛載軟件包,并關閉防火墻和安全功能
mount.cifs //192.168.100.3/lzp /mnt
#關閉防火墻和安全功能
systemctl stop firewalld.service
setenforce 0
2、解壓安裝包,并進行編譯
#解壓安裝包
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
#修改網絡接口
interface ens33
#修改virtual_router_id
virtual_router_id 52
#修改優先級
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
magent
}
virtual_ipaddress {
#修改地址
192.168.45.188
}
}
4、創建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、啟動服務
#啟動keepalived
systemctl start keepalived.service
#啟動memcached
memcached -m 512k -u root -d -l 192.168.45.131 -p 11211
安裝telent進行測試
yum install telnet -y
#關閉防火墻和安全功能
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
在從服務器上查看
在主服務器上查看
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。