搭建redis集群

准备

sudo apt-get install git python python-pip
sudo pip install redis
sudo pip install -e git://github.com/idning/pcl.git#egg=pcl
sudo pip install -e git://github.com/kislyuk/argcomplete.git#egg=argcomplete
git clone https://github.com/idning/redis-mgr.git

编译redis 和twemproxy 并且把他们放到_binaries/目录下(可能需要 cp redis-server redis-sentinel 到该目录下)

$ ll _binaries/
total 19M
1735820 -rwxr-xr-x 1 ning ning 705K 2014-03-24 19:26 nutcracker
1735818 -rwxr-xr-x 1 ning ning 5.1M 2014-03-24 19:26 redis-sentinel
1735819 -rwxr-xr-x 1 ning ning 5.1M 2014-03-24 19:26 redis-server
1735815 -rwxr-xr-x 1 ning ning 3.8M 2014-03-24 19:26 redis-cli
1735809 -rwxr-xr-x 1 ning ning  28K 2014-03-24 19:26 redis-check-aof
1735801 -rwxr-xr-x 1 ning ning 3.7M 2014-03-24 19:26 redis-benchmark

选择配置文件的名字

export REDIS_DEPLOY_CONFIG=conf && . bin/active
执行命令后遇到一个错误:(eval):9: command not found: complete
因为complete是bash的一个内建命令,但是我用的是zsh,所以才出现了这个问题。
目前没找到解决办法,只能先切到bash上来弄了。

编辑配置文件

vim conf/conf.py
替换配置中的127.0.0.5为远程服务器IP(如连本地机器,仍然需要ssh-copy-id才可以不用密码登陆)
修改集群中的user为正确的用户名

确保可以ssh到目标机器而不用输入密码(使用use ssh-copy-id)

ssh-copy-id -i ~/.ssh/id_rsa.pub remote_ip

启动

$ ./bin/deploy.py cluster0 -h
$ ./bin/deploy.py cluster0 deploy
$ ./bin/deploy.py cluster0 start
$ ./bin/deploy.py cluster0 scheduler --web_port 8008 (run this in screen or somehow on background)

配置

cluster0 = {
    'cluster_name': 'cluster0',    #集群的名字
    'user': 'ning',                #远程主机用户名
    'sentinel':[
        ('127.0.0.5:29001', '/tmp/r/sentinel-29001'),
        ('127.0.0.5:29002', '/tmp/r/sentinel-29002'),
        ('127.0.0.5:29003', '/tmp/r/sentinel-29003'),
    ],
    'redis': [
        # master(host:port, install path)#主服务器配置       ,  slave(host:port, install path)#从服务器配置
        ('127.0.0.5:20000', '/tmp/r/redis-20000'), ('127.0.0.5:21000', '/tmp/r/redis-21000'),
        ('127.0.0.5:20001', '/tmp/r/redis-20001'), ('127.0.0.5:21001', '/tmp/r/redis-21001'),
        ('127.0.0.5:20002', '/tmp/r/redis-20002'), ('127.0.0.5:21002', '/tmp/r/redis-21002'),
        ('127.0.0.5:20003', '/tmp/r/redis-20003'), ('127.0.0.5:21003', '/tmp/r/redis-21003'),
    ],
    'nutcracker': [
        ('127.0.0.5:22000', '/tmp/r/nutcracker-22000'),
        ('127.0.0.5:22001', '/tmp/r/nutcracker-22001'),
        ('127.0.0.5:22002', '/tmp/r/nutcracker-22002'),
    ],
}
    原文作者:_Sunshine
    原文地址: https://segmentfault.com/a/1190000002357101
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞