> 데이터 베이스 > MySQL 튜토리얼 > Keepalive,Twemproxy,Redis整体集群搭建记录

Keepalive,Twemproxy,Redis整体集群搭建记录

WBOY
풀어 주다: 2016-06-07 16:37:15
원래의
1263명이 탐색했습니다.

简介 搭建时间:2014/07/24 搭建系统:centos 6.2,centos 6.5 服务器架构 192.168.0.221 twemproxy,redis master01,redis slave02 192.168.0.220 twemproxy,redis master02,redis slave01 192.168.0.10 keepalived master 192.168.0.20 keepalived slav

redis简介

搭建时间:2014/07/24

搭建系统:centos 6.2,centos 6.5

服务器架构

192.168.0.221 twemproxy,redis master01,redis slave02
192.168.0.220 twemproxy,redis master02,redis slave01
192.168.0.10 keepalived master
192.168.0.20 keepalived slave

服务版本:

redis?: 2.4.10
keepalived: 1.2.2
twemproxy-master: 0.3.0

Redis

安装Redis

解压redis源码包;

根据README的介绍,完成安装步骤(make)

将redis文件夹mv到/usr/local下面,完成安装

配置redis的master/slave

新建redis配置文件路径

登录到192.168.0.221服务器

mkdir /var/redis/master01/{conf,data,logs,run};
mkdir /var/redis/slave02/{conf,data,logs,run};

登录到192.168.0.220服务器

mkdir /var/redis/master02/{conf,data,logs,run};
mkdir /var/redis/slave01/{conf,data,logs,run};

创建redis.conf文件(master和slave都大致一样,只有2行不同)

dir /var/redis/master01/? #redis的地址
pidfile ./run/redis.pid? #相对路径地址是相当dir来说的
logfile ./logs/stdout.log
dbfilename ./data/dump.rdb
bind 192.168.0.220 #监听服务地址
daemonize yes
requirepass 123qwe #服务密码
masterauth 123qwe? #这个只是在slave服上面配置,master不需要配置
slaveof 192.168.0.221 6601 #这个只是需要在slave上面配置,master不需要配置,指定master的地址
databases 16
port 6601 # 服务端口
timeout 0
loglevel verbose
save 900 1
save 300 10
rdbcompression yes
slave-serve-stale-data yes #如果master断了,slave是否提供服务
appendonly no
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000
slowlog-max-len 1024

启动redis服务 先启动redis master服务,然后再启动redis slave服务

登录到slave服务器,执行./redis-cli -h 192.168.0.220 -p 6601 -a 123qwe info,如果配置正确,最后会显示

role:slave
master_host:192.168.0.221
master_port:6601
master_link_status:up
master_last_io_seconds_ago:8
master_sync_in_progress:0

说明redis的master/slave已经完成配置

twemproxy

安装twemproxy

首先去下载最新的twemproxy,在github上面找到最新版本

如果是采用和我一样的系统,需要先更新autoconf,系统自带版本过低,编译会报错

CFLAGS=”-ggdb3 -O0″ autoreconf -fvi
./configure –prefix=/usr/local/twemproxy? –enable-debug=log
make && make install

配置twemproxy

这里配置是采用2台服务器搭建,每个服务器都安装一个twemproxy,配置一样,前端使用keepalived进行LVS分发

登陆到192.168.0.221/220,修改conf下面的nutcracker.yml,配置如下:

redis1:
listen: 0.0.0.0:10000
hash: fnv1a_64 #分发算法
distribution: ketama
timeout: 400
backlog: 1024
preconnect: true
auto_eject_hosts: true
server_retry_timeout: 2000 # 重试的时间
server_failure_limit: 3 #失败尝试次数,达到上限就取消后端分发权限
servers:
- 192.168.0.220:6601:1? # redis实例的ip,端口,权重
- 192.168.0.221:6601:1

redis启动服务

/usr/local/twemproxy/sbin/nutcracker -c /usr/local/twemproxy/conf/nutcracker.yml -d

redis测试服务

随便另外找一个安装有redis的服务器

./redis-cli -h 192.168.0.220 -p 10000 -a 123qwe

如果没有报错,说明成功!

keepalived

安装keepalived

登录到192.168.0.10

yum install kernel-devel
./configure –prefix=/usr/local/keepalived –with-kernel-dir=/usr/src/kernels/2.6.18-308.el5-x86_64/
make && make install

在make之前,如果现实如下结果,表示你的系统可以完成keepalived的各项功能

Keepalived configuration
————————
Keepalived version?????? : 1.2.2
Compiler???????????????? : gcc
Compiler flags?????????? : -g -O2 -DETHERTYPE_IPV6=0x86dd
Extra Lib??????????????? : -lpopt -lssl -lcrypto
Use IPVS Framework?????? : Yes # 要实现LVS功能,必须保证这个地方是YES
IPVS sync daemon support : Yes #
IPVS use libnl?????????? : No
Use VRRP Framework?????? : Yes
Use Debug flags????????? : No

keepalived配置

修改文件keepalived.conf

global_defs {
router_id wd_twemproxy
}

vrrp_instance wd2 {
state BACKUP # master标准MASTER
nopreempt
interface em2
track_interface {
em2
}

virtual_router_id 70
priority 100 # 权重高的作为master
advert_int 1
authentication {
auth_type PASS
auth_pass css74..tfwwapmzi4r
}

virtual_ipaddress {
192.168.0.100/16 dev em2 scope global #定义VIP
}
}

virtual_server 192.168.0.100 10000 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.0.0
persistence_timeout 120
protocol TCP

real_server 192.168.0.220 10000 {
weight 1
TCP_CHECK {
connect_timeout 60
nb_get_retry 3
delay_before_retry 3
connect_port 10000
}
}

real_server 192.168.0.221 10000 {
weight 1
TCP_CHECK {
connect_timeout 60
nb_get_retry 3
delay_before_retry 3
connect_port 10000
}
}
}

配置完成了之后,启动keepalived

/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf

执行 ipvsadm -Ln

显示如下:

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port
Forward Weight ActiveConn InActConn
TCP? 192.168.0.100:10000 wrr persistent 120
-> 192.168.0.220:10000???????? Route?? 1????? 0????????? 0
-> 192.168.0.221:10000???????? Route?? 1????? 0????????? 0

说明keepalived配置成功

总结(关键,可以首先阅读)

因为不想再次修改上面的内容,所以直接在后面添加说明,看了之后再根据下面的内容自己调整上面的配置!

坑爹第一季

以上的做法当你完全配置完成之后,可以发现无法提供服务,想知道为什么吗,我TM也不知道,反正就是不行,无法连接

[Mon Jul 28 10:57:29 2014] nc_proxy.c:336 accepted c 9 on p 8 from ‘unknown’
[Mon Jul 28 10:57:29 2014] nc_core.c:201 close c 9 ‘unknown’ on event FF00FF eof 0 done 0 rb 0 sb 0: Connection reset by pee
[Mon Jul 28 10:57:35 2014] nc_proxy.c:336 accepted c 9 on p 8 from ‘unknown’
[Mon Jul 28 10:57:35 2014] nc_core.c:201 close c 9 ‘unknown’ on event FF00FF eof 0 done 0 rb 0 sb 0: Connection reset by peer

以上为twemproxy启动之后报错信息,如果你也是采用keepalived作为最前端的LVS分发功能,那估计结果不会比我好到哪去。

解决办法:

放弃使用keepalived使用LVS的功能,最多使用热备功能,前端使用两个twemproxy,一个主,一个备,keepalived提供服务。

坑爹第二季

如果redis使用主备功能,不要使用密码认证,直接使用内网地址也很安全,不然twemproxy无法提供服务,切记,切记!!!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿