您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mount.cifs //192.168.100.8/memcached /abc //挂载
Password for root@//192.168.100.8/memcached:
[root@localhost ~]# cd /abc/
[root@localhost abc]# ls
LAMP-php5.6 magent-0.5.tar.gz memcached-1.5.6.tar.gz
libevent-2.1.8-stable.tar.gz memcache-2.2.7.tgz
[root@localhost abc]# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt //解压事件库软件包,memcached依赖于事件库
[root@localhost abc]# tar zxvf memcached-1.5.6.tar.gz -C /opt/ //解压服务端memcached软件包
[root@localhost abc]# yum install gcc gcc-c++ make -y //安装环境包
[root@localhost abc]# mkdir /opt/magent
[root@localhost abc]# tar zxvf magent-0.5.tar.gz -C /opt/magent/
[root@localhost opt]# cd libevent-2.1.8-stable/
[root@localhost libevent-2.1.8-stable]# ./configure --prefix=/usr
[root@localhost libevent-2.1.8-stable]# make && make install //编译安装
[root@localhost libevent-2.1.8-stable]# cd ../memcached-1.5.6/
[root@localhost memcached-1.5.6]# ./configure --with-libevent=/usr
make && make install
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mount.cifs //192.168.100.8/memcached /abc
Password for root@//192.168.100.8/memcached:
[root@localhost ~]# cd /abc/
[root@localhost abc]# ls
LAMP-php5.6 magent-0.5.tar.gz memcached-1.5.6.tar.gz
libevent-2.1.8-stable.tar.gz memcache-2.2.7.tgz
[root@localhost abc]# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt //解压事件库软件包
[root@localhost abc]# tar zxvf memcached-1.5.6.tar.gz -C /opt/ /解压服务端memcached软件包
[root@localhost abc]# yum install gcc gcc-c++ make -y
[root@localhost opt]# cd libevent-2.1.8-stable/
[root@localhost libevent-2.1.8-stable]# ./configure --prefix=/usr
[root@localhost libevent-2.1.8-stable]# make && make install
[root@localhost libevent-2.1.8-stable]# cd ../memcached-1.5.6/
[root@localhost memcached-1.5.6]# ./configure --with-libevent=/usr
make && make install
[root@localhost memcached-1.5.6]# cd /opt/
[root@localhost opt]# ls
libevent-2.1.8-stable magent memcached-1.5.6 rh
[root@localhost opt]# cd magent/
[root@localhost magent]# vim ketama.h
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
[root@localhost magent]# vim Makefile
LIBS = -levent -lm //指定makefile文件
make //编译
[root@localhost magent]# ls
ketama.c ketama.h ketama.o magent magent.c magent.o Makefile
[root@localhost magent]# yum install openssh-clients -y //安装scp远程同步软件包
[root@localhost magent]# cp magent /usr/bin/ //把magent脚本放到/usr/local中,让系统能识别
[root@localhost magent]# scp magent root@192.168.144.239:/usr/bin/ //把mangent文件拷贝到从服务器上
[root@localhost bin]# systemctl stop firewalld.service
[root@localhost bin]# setenforce 0
[root@localhost bin]# yum install keepalived -y
[root@localhost magent]# 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
router_id MAGENT_HA //主服务器id,两台不能一样
}
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
magent
}
virtual_ipaddress {
192.168.144.188 //客户端访问的漂移地址
}
}
[root@localhost bin]# cd /etc/keepalived/
[root@localhost keepalived]# mv keepalived.conf keepalived.conf.bak //更改名称
[root@localhost keepalived]# yum install openssh-clients -y
[root@localhost magent]# cd /etc/keepalived/
[root@localhost keepalived]# scp keepalived.conf root@192.168.144.239:/etc/keepalived/
[root@localhost keepalived]# ls
keepalived.conf keepalived.conf.bak
[root@localhost keepalived]# 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 MAGENT_HB //routed_id不能相同
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 52 //从服务器虚拟id不能和主服务器一样
priority 90 //优先级比主服务器低
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
magent
}
virtual_ipaddress {
192.168.144.188
}
}
[root@localhost keepalived]# mkdir /opt/shell
[root@localhost keepalived]# cd /opt/shell/
[root@localhost shell]# vim magent.sh
#!/bin/bash
k=`ps -ef | grep keepalived | grep -v grep | wc -l` //检查keepaliveed进程,如果开启
if [ $k -gt 0 ]; then
magent -u root -n 51200 -l 192.168.144.188 -p 12000 -s 192.168.144.238:11211 -b
// -n连接数量 -l指定漂移地址,-p指定端口映射到主从服务器的地址
192.168.144.239:11211
else
pkill -9 magent
fi
[root@localhost shell]# chmod +x magent.sh
[root@localhost shell]# systemctl start keepalived.service
[root@localhost shell]# netstat -ntap | grep 12000
tcp 0 0 192.168.144.188:12000 0.0.0.0:* LISTEN 124720/magent
[root@localhost keepalived]# mkdir /opt/shell
[root@localhost keepalived]# cd /opt/shell/
[root@localhost 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.144.188 -p 12000 -s 192.168.144.238:11211 -b 192.168.144.239:11211
else
pkill -9 magent
fi
[root@localhost shell]# chmod +x magent.sh
[root@localhost shell]# systemctl start keepalived.service
[root@localhost shell]# netstat -ntap | grep 12000 //查看magent端口
tcp 0 0 192.168.144.188:12000 0.0.0.0:* LISTEN 11660/magent
[root@localhost shell]# memcached -m 512k -u root -d -l 192.168.144.238 -p 11211 //启动主,-m指定空间大小
[root@localhost shell]# netstat -ntap | grep 11211
tcp 0 0 192.168.144.238:11211 0.0.0.0:* LISTEN 44647/memcached
[root@localhost shell]# memcached -m 512k -u root -d -l 192.168.144.239 -p 11211 #启动从
[root@localhost shell]# netstat -ntap | grep 11211
tcp 0 0 192.168.144.239:11211 0.0.0.0:* LISTEN 42654/memcached
[root@localhost ~]# telnet 192.168.144.188 12000
Trying 192.168.144.188...
Connected to 192.168.144.188.
Escape character is '^]'.
add username 0 0 7 //编写键值对数据
1234567
STORED
[root@localhost shell]# telnet 192.168.144.238 11211
Trying 192.168.144.238...
Connected to 192.168.144.238.
Escape character is '^]'.
geer^H^H
ERROR
get username
VALUE username 0 7
1234567
END
[root@localhost shell]# telnet 192.168.144.239 11211
Trying 192.168.144.239...
Connected to 192.168.144.239.
Escape character is '^]'.
get username
VALUE username 0 7
1234567
END
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。