redis + twemproxy 分布式集群与部署

环境说明
Centos 6.8
192.168.200.48:6380
192.168.200.49:6381
192.168.200.50:6382
192.168.200.50:6379 提供服务

更新系统
yum -y upgrade

1、下载和解包
创建安装文件夹
mkdir -p /application
进入安装文件夹
cd /application
下载安装程序
wget http://mirrors.hncgo.com/redis-3.2.5.tar.gz
解压
tar xf redis-3.2.5.tar.gz
创建软件连接
ln -s /application/redis-3.2.5 /application/redis
编辑安装
cd redis
make
make install

mkdir conf
mv redis.conf conf
cd conf
vim redis.conf

修改以下信息
bind 127.0.0.1 192.168.200.48
prot 6379
daemonize yes  在前台运行
dbfilename dump_6379.rdb 
appendfilename "appendonly_6379.aof"
pidfile /var/run/redis_6379.pid
logfile "6379.log"


批量替换6379为6380
:1,$ s/6379/6380/g


创建启动管理脚本
redis_service.sh (单实例)
#!/bin/bash
act=$1
cmd=/application/redis/src/redis-server
conf=/application/redis/conf/redis.conf
case $act in
     'start')
         $cmd $conf;;
     'stop')
         /application/redis/src/redis-cli shutdown;;
     'restart')
         /application/redis/src/redis-cli shutdown
         sleep 2;
         $cmd $conf;;
     *)
         echo "[start|stop|restart]";;
esac
##########################
./redis_service.sh start
./redis_service.sh stop
./redis_service.sh restart


redis_service.sh (多实例)
#!/bin/bash
act=$1
port=$2
cmd=/application/redis/src/redis-server
conf=/application/redis/conf/redis_"$port".conf
case $act in
     'start')
         $cmd $conf;;
     'stop')
         /application/redis/src/redis-cli -p "$port" shutdown;;
     'restart')
         /application/redis/src/redis-cli -p "$port" shutdown
         sleep 2;
         $cmd $conf;;
     *)
         echo "[start|stop|restart]";;
esac
#######################################
./redis_service.sh start 6379
./redis_service.sh stop 6379
./redis_service.sh restart 6379

加入开机启动
vim /etc/rc.local
增加
/application/redis/redis_service.sh start 6380

netstat -ntlp |grep 6380
    
chmod 755 redis_service.sh
        
        
        
安装集群控制软件,只需要在一台机器上安装就可以了

环境准备:(必须按以下顺序安装)
yum remove autoconf
安装autoconf-2.69.tar.gz
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar xf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure
make && make install
ln -s /usr/local/bin/autoreconf /usr/bin/

2.4安装automake-1.15.tar.gz
wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
tar xf automake-1.15.tar.gz
cd automake-1.15
./configure
make&& make install

2.5安装libtool-2.4.tar.gz
wget http://ftp.gnu.org/gnu/libtool/libtool-2.4.tar.gz
tar xf libtool-2.4.tar.gz
cd libtool-2.4
./configure
make&& make install


cd /tools
下载和解包(必须使用autoconf 2.6 以上的版本)
wget http://mirrors.hncgo.com/twemproxy-master.zip
unzip twemproxy-master.zip
cd twemproxy-master
autoreconf -fvi
./configure --prefix=/application/twemproxy
make -j 8
make install

cd /application/twemproxy
mkdir conf
cd /tools/twemproxy-master/conf/
cp nutcracker.yml /application/twemproxy/conf/
cd /application/twemproxy/conf
vim nutcracker.yml
只保留以下内容并修改
#######################################
redis03:
   listen: 192.168.200.50:6379
   hash: fnv1a_64
   hash_tag: "{}"
   distribution: ketama
   auto_eject_hosts: false
   timeout: 400
   redis: true
   servers:
    - 192.168.200.48:6380:1 server1
    - 192.168.200.49:6381:1 server2
    - 192.168.200.50:6382:1 server3
#####################################
cd ..

vim twemproxy_service.sh
#!/bin/bash
act=$1
case $act in
     'start')
         /application/twemproxy/sbin/nutcracker -d -c /application/twemproxy/conf/nutcracker.yml ;;
     'stop')
         killall nutcracker;;
     'restart')
         killall nutcracker
         sleep 2
         /application/twemproxy/sbin/nutcracker -d -c /application/twemproxy/conf/nutcracker.yml ;;
     *)
         echo "[start|stop|restart]";;
esac

chmod 755 twemproxy_service.sh
加入开机启动
vim /etc/rc.local
增加
/application/twemproxy/twemproxy_service.sh start

netstat -ntlp |grep 6379



加入开机启动
vim /etc/rc.local
增加
/application/twemproxy/twemproxy_service.sh start

posted @ 2017-07-18 21:01  王亦福-Jeff  阅读(282)  评论(0编辑  收藏  举报