本文共 4916 字,大约阅读时间需要 16 分钟。
2019年第一篇日记,来的有点晚一些!
测试环境:
系统:Centos6.8 IP:192.168.0.117由于本人穷,所以这次Redis集群+TwemProxy 都部署在同一台服务器上
一、首先安装redis集群环境,这里部署3个redis服务
1.安装依赖包[root@18c local]# yum install gcc-c++ tcl
2.下载并安装redis
[root@18c local]# wget http://download.redis.io/redis-stable.tar.gz[root@18c local]# tar zxvf redis-stable.tar.gz [root@18c local]# mv redis-stable redis[root@18c local]# cd redis[root@18c redis]# makeroot@18c local]# make install配置多个redis服务[root@18c redis]# cd /usr/local/redis[root@18c redis]# cp redis.conf redis_6379.conf[root@18c redis]# cp redis.conf redis_6380.conf[root@18c redis]# cp redis.conf redis_6381.conf修改配置文件redis1:[root@18c redis]# cat redis_6379.conf |grep -E "port|pidfile|logfile|databases" |grep -Ev "^$|^[#;]"port 6379pidfile /var/run/redis_6379.pidlogfile /var/run/redis_6379.logdatabases 1redis2:[root@18c redis]# cat redis_6380.conf |grep -E "port|pidfile|logfile|databases" |grep -Ev "^$|^[#;]"port 6380pidfile /var/run/redis_6380.pidlogfile /var/run/redis_6380.logdatabases 2redis3:[root@18c redis]# cat redis_6381.conf |grep -E "port|pidfile|logfile|databases" |grep -Ev "^$|^[#;]"port 6381pidfile /var/run/redis_6381.pidlogfile /var/run/redis_6381.logdatabases 3启动3个redis[root@18c redis]#redis-server /usr/local/redis/redis_6379.conf &[root@18c redis]#redis-server /usr/local/redis/redis_6380.conf &[root@18c redis]#redis-server /usr/local/redis/redis_6381.conf &[root@18c redis]# ps -ef |grep redisroot 15800 15773 0 15:42 pts/2 00:00:00 grep redisroot 31532 1 0 10:27 ? 00:00:15 redis-server 127.0.0.1:6379 root 31538 1 0 10:27 ? 00:00:15 redis-server 127.0.0.1:6380 root 31554 1 0 10:28 ? 00:00:15 redis-server 127.0.0.1:6381
二、安装TwemProxy
1.编译安装autoconf[root@18c local]# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz[root@18c local]# tar -zvxf autoconf-2.69.tar.gz[root@18c local]# cd autoconf-2.69[root@18c local]# ./configure [root@18c local]# make[root@18c local]# make install
2.编译安装automake
[root@18c local]# wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz[root@18c local]# tar -zvxf automake-1.15.tar.gz[root@18c local]# cd automake-1.15[root@18c local]# ./configure && make && make install[root@18c local]# make [root@18c local]# make install
3.编译安装libtool
[root@18c local]# wget https://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz[root@18c local]# tar -zvxf libtool-2.4.6.tar.gz[root@18c local]# cd libtool-2.4.6[root@18c local]# ./configure && make && make install
4.编译安装twemproxy
[root@18c local]# wget https://github.com/twitter/twemproxy/archive/master.zip[root@18c local]# unzip master.zip[root@18c local]# cd twemproxy-master[root@18c twemproxy-master]# aclocal[root@18c twemproxy-master]# aautoreconf -ivf //执行autoreconf 生成 configure文件等[root@18c twemproxy-master]# ./configure --prefix=/usr/local/twemproxy/[root@18c twemproxy-master]# make [root@18c twemproxy-master]# make install配置文件[root@18c twemproxy-master]# lssbin share[root@18c twemproxy]# cp -r /user/local/twemproxy-master/conf /usr/local/twemproxy/[root@18c twemproxy]# cd conf/[root@18c conf]# lsnutcracker.leaf.yml nutcracker.root.yml nutcracker.yml[root@18c conf]# cp nutcracker.yml nutcracker.yml.bak[root@18c conf]# cat nutcracker.yml alpha: listen: 127.0.0.1:22121 hash: fnv1a_64 distribution: ketama auto_eject_hosts: true redis: true server_retry_timeout: 2000 server_failure_limit: 1 servers: //这里配置了三个分片 - 127.0.0.1:6379:1 - 127.0.0.1:6380:1 - 127.0.0.1:6381:1beta: listen: 127.0.0.1:22122 hash: fnv1a_64 hash_tag: "{}" distribution: ketama auto_eject_hosts: false timeout: 400 redis: true servers: - 127.0.0.1:6380:1 server1 - 127.0.0.1:6381:1 server2 - 127.0.0.1:6382:1 server3 - 127.0.0.1:6383:1 server4.....
5.启动
[root@18c conf]# nohup /usr/local/twemproxy/sbin/nutcracker -c /usr/local/twemproxy/conf/nutcracker.yml & [root@18c conf]# ps -ef|grep nutcracker root 15109 1 0 13:34 ? 00:00:00 /usr/local/twemproxy/sbin/nutcracker -c /usr/local/twemproxy/conf/nutcracker.yml root 15920 15866 0 15:59 pts/2 00:00:00 grep nutcracker
6.测试 twemproxy set/get ,后端分片查看
[root@18c conf]# redis-cli -h 127.0.0.1 -p 22121127.0.0.1:22121> set shiyu 66666OK127.0.0.1:22121> get shiyu"66666"127.0.0.1:22121> set ssssssssssssssssssssssssssssssssshhhhhhhhhhhhhhhhhhhhhhhhhhhh "hahahahahahahahahhahahahahahahahahah"OK127.0.0.1:22121> get ssssssssssssssssssssssssssssssssshhhhhhhhhhhhhhhhhhhhhhhhhhhh"hahahahahahahahahhahahahahahahahahah"127.0.0.1:22121> set yuhuashi "777777"OK127.0.0.1:22121> get yuhuashi登录三台redis节点上查看,发现已经有分片了[root@18c conf]# redis-cli -p 6379127.0.0.1:6379> get shiyu"66666"[root@18c conf]# redis-cli -p 6380127.0.0.1:6380> get yuhuashi"777777"[root@18c conf]# redis-cli -p 6381127.0.0.1:6381> get ssssssssssssssssssssssssssssssssshhhhhhhhhhhhhhhhhhhhhhhhhhhh"hahahahahahahahahhahahahahahahahahah"
至此新年第一个测试结束
转载地址:http://njhji.baihongyu.com/