你好,游客 登录 注册 搜索
背景:
阅读新闻

SUSE Linux 11下Redis环境搭建

[日期:2017-03-06] 来源:Linux社区  作者:xiaoxiaozhou [字体: ]

因为工作环境中有Redis,所以对Redis进行了学习,当然首先就是从搭建环境开始,下面是我对于搭建Redis环境的记录。

系统是SUSE 11 sp2,

软件环境如下所示:

linux-svnfile:/home/apps/redis # ls

redis-3.0.0.gem    ruby-1.9.2-p290.tar.gz  zlib-1.2.7.tar.gz

redis-3.0.0.tar.gz  rubygems-2.4.6.tgz

redis.conf          zlib-1.2.6.tar.gz

安装基础环境:

linux-svnfile:/home/apps/redis # tar -zxf zlib-1.2.6.tar.gz -C /usr/local/src

linux-svnfile:/usr/local/src/zlib-1.2.6 # ./configure --prefix=/usr/local/zlib

linux-svnfile:/usr/local/src/zlib-1.2.6 # make && make install

linux-svnfile:/home/apps/redis # tar -zxf ruby-1.9.2-p290.tar.gz -C /usr/local/src

linux-svnfile:/usr/local/src/ruby-1.9.2-p290 # ./configure --prefix=/usr/local/ruby

linux-svnfile:/usr/local/src/ruby-1.9.2-p290 # make && make install

linux-svnfile:/usr/local/ruby # ln -s /usr/local/ruby/bin/ruby /usr/local/bin

linux-svnfile:/home/apps/redis # tar xf rubygems-2.4.6.tgz -C /usr/local/src

linux-svnfile:/usr/local/src # mv rubygems-2.4.6 ../gem

linux-svnfile:/usr/local/gem # ruby setup.rb

linux-svnfile:/usr/local/gem # cp bin/gem /usr/local/bin/

linux-svnfile:/home/apps/redis # gem install -l redis-3.0.0.gem

Successfully installed redis-3.0.0

Installing ri documentation for redis-3.0.0

Done installing documentation for redis after 0 seconds

1 gem installed

linux-svnfile:/home/apps/redis # tar -zxf redis-3.0.0.tar.gz -C /usr/local/src

linux-svnfile:/usr/local/src # mv redis-3.0.0 ../redis

linux-svnfile:/usr/local/redis # make

至此基础环境搭建完成

下面进行集群的搭建

linux-svnfile:/usr/local/redis # cp src/redis-server /usr/local/bin/

linux-svnfile:/usr/local/redis # cp src/redis-cli /usr/local/bin/

linux-svnfile:/usr/local/redis # cp src/redis-trib.rb /usr/local/bin

linux-svnfile:/usr/local/redis # mkdir -p /usr/local/cluster/{7000..7005}

linux-svnfile:/usr/local/redis # vi redis.conf

daemonize yes

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7000

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7001

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7002

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7003

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7004

linux-svnfile:/usr/local/redis # cp redis.conf ../cluster/7005

这里需要注意的是文件名对应文件里端口的配置,例如7001文件下的port参数需要改为7001,其他一样做修改。

linux-svnfile:/usr/local/redis # redis-server ../cluster/7000/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7001/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7002/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7003/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7004/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7005/redis.conf

linux-svnfile:/usr/local/redis # ps -ef | grep redis

root    15590    1  0 18:52 ?        00:00:00 redis-server *:7000 [cluster]   

linux-svnfile:/usr/local/redis # redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

>>> Creating cluster

Connecting to node 127.0.0.1:7000: OK

Connecting to node 127.0.0.1:7001: [ERR] Sorry, can't connect to node 127.0.0.1:7001

You have new mail in /var/mail/root

linux-svnfile:/usr/local/cluster/7000 # redis-server redis.conf

linux-svnfile:/usr/local/cluster/7000 # cd ../7001

linux-svnfile:/usr/local/cluster/7001 # redis-server redis.conf

linux-svnfile:/usr/local/cluster/7001 # cd ../7002

linux-svnfile:/usr/local/cluster/7002 # redis-server redis.conf

linux-svnfile:/usr/local/cluster/7002 # cd ../7003

linux-svnfile:/usr/local/cluster/7003 # redis-server redis.conf

linux-svnfile:/usr/local/cluster/7003 # cd ../7004

linux-svnfile:/usr/local/cluster/7004 # redis-server redis.conf

linux-svnfile:/usr/local/cluster/7004 # cd ../7005

linux-svnfile:/usr/local/cluster/7005 # redis-server redis.conf

linux-svnfile:/usr/local/cluster/7005 # ps -ef | grep redis

root    17575    1  0 20:05 ?        00:00:00 redis-server *:7000 [cluster]

root    17590    1  0 20:06 ?        00:00:00 redis-server *:7001 [cluster]

root    17604    1  0 20:06 ?        00:00:00 redis-server *:7002 [cluster]

root    17612    1  0 20:06 ?        00:00:00 redis-server *:7003 [cluster]

root    17616    1  0 20:06 ?        00:00:00 redis-server *:7004 [cluster]

root    17624    1  0 20:06 ?        00:00:00 redis-server *:7005 [cluster]

像是上面在启动服务时需要注意切换到相应的配置文件的目录下,不然相应端口的服务无法启动,例如我之前在/usr/local/redis目录下启动后只有7000对应的服务启动了。

linux-svnfile:/usr/local/redis # redis-server ../cluster/7000/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7001/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7002/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7003/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7004/redis.conf

linux-svnfile:/usr/local/redis # redis-server ../cluster/7005/redis.conf

linux-svnfile:/usr/local/redis # ps -ef | grep redis

root    15144 19064  0 18:37 pts/0    00:00:00 vi redis.conf

root    15590    1  0 18:52 ?        00:00:00 redis-server *:7000 [cluster]         

root    15616 19443  0 18:52 pts/1    00:00:00 grep redis

linux-svnfile:/usr/local/cluster #redis-cli -p 7000

127.0.0.1:7000>

删除slave节点

删除master节点

linux-svnfile:/usr/local/redis # redis-trib.rb reshard 127.0.0.1:7001

How many slots do you want to move (from 1 to 16384)? 5461

What is the receiving node ID? 42929649e533ec8aad7cbb81f204f04c849d4bff

Please enter all the source node IDs. 

  Type 'all' to use all the nodes as source nodes for the hash slots. 

  Type 'done' once you entered all the source nodes IDs. 

Source node #1: 6fe9561e605b7ee85e67a2557f7fb641f482afb4

Source node #2:done 

#Do you want to proceed with the proposed reshard plan (yes/no)? yes 

说明:

5461表示要删除master所有的slot数量

What is the receiving node ID是指将7000的slot迁移的节点7001的node-id

Source node #1是指要删除的master的node-id

下面可以看到7000的slot为0,而7001多了4561

在删除master节点出现如下面所示的错误,是因为删除master节点之前没有删除master节点的slave节点。

上面是在单台机器上做的集群,下面展示两台机器上做集群,其实也很简单。

参考之前的环境编译源码到另一台机器

在两台机器上编辑配置文件

/usr/local/redis # vi redis.conf

daemonize yes

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

cluster-config-file nodes-7001.conf

分别创建目录和文件

linux-svnfile:/usr/local/redis # mkdir -p/usr/local/cluster/{7001..7003}

localhost:/usr/local/redis # mkdir -p/usr/local/cluster/{8001..8003}

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7001

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7002

linux-svnfile:/usr/local/redis # cpredis.conf ../cluster/7003

localhost:/usr/local/redis # cp redis.conf../cluster/8001

localhost:/usr/local/redis # cp redis.conf../cluster/8002

localhost:/usr/local/redis # cp redis.conf../cluster/8003

修改对应目录的配置文件其中port 和cluster-config-file分别对应各自的目录名,可使用sed命令做修改

sed -i "s/7001/7002/g"

启动服务

下面关于Redis的文章您也可能喜欢,不妨参考下:

Ubuntu 14.04下Redis安装及简单测试 http://www.chineselinuxuniversity.net/Linux/2014-05/101544.htm

Redis主从复制基本配置 http://www.chineselinuxuniversity.net/Linux/2015-03/115610.htm

CentOS 7下Redis的安装与配置 http://www.chineselinuxuniversity.net/Linux/2017-02/140363.htm

Ubuntu 14.04安装Redis与简单配置 http://www.chineselinuxuniversity.net/Linux/2017-01/139075.htm

Ubuntu 16.04环境中安装PHP7.0 Redis扩展 http://www.chineselinuxuniversity.net/Linux/2016-09/135631.htm

Redis 单机&集群离线安装部署 http://www.chineselinuxuniversity.net/Linux/2017-03/141403.htm

CentOS 7.0 安装Redis 3.2.1详细过程和使用常见问题 http://www.chineselinuxuniversity.net/Linux/2016-09/135071.htm

Ubuntu 16.04环境中安装PHP7.0 Redis扩展 http://www.chineselinuxuniversity.net/Linux/2016-09/135631.htm

Ubuntu 15.10下Redis集群部署文档 http://www.chineselinuxuniversity.net/Linux/2016-06/132340.htm

Redis实战 中文PDF http://www.chineselinuxuniversity.net/Linux/2016-04/129932.htm

Redis热迁移实战总结  http://www.chineselinuxuniversity.net/Linux/2017-02/141083.htm

Redis3.0配置文件详解  http://www.chineselinuxuniversity.net/Linux/2017-03/141369.htm

Redis 的详细介绍请点这里
Redis 的下载地址请点这里

本文永久更新链接地址http://www.chineselinuxuniversity.net/Linux/2017-03/141428.htm

linux
相关资讯       Redis 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款