重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
[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
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
创新互联长期为近千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为保康企业提供专业的成都网站建设、做网站,保康网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。