解压redis

先到官网https://redis.io/下载redis安装包,然后在CentOS操作系统中解压该安装包:

tar -zxvf redis-3.2.9.tar.gz

编译redis

cd redis-3.2.9

make && make install

此时如果报如下错误:

bash: make: command not found

说明系统没有安装make,所有要先安装make,即:

yum -y install gcc automake autoconf libtool make

如果此时再报如下错误:

Error Downloading Packages:

glibc-headers-2.12-1.107.el6.x86_64: failure: Packages/glibc-headers-2.12-1.107.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

1:perl-Module-Pluggable-3.90-129.el6.x86_64: failure: Packages/perl-Module-Pluggable-3.90-129.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

mpfr-2.4.1-6.el6.x86_64: failure: Packages/mpfr-2.4.1-6.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

1:make-3.81-20.el6.x86_64: failure: Packages/make-3.81-20.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

cloog-ppl-0.15.7-1.2.el6.x86_64: failure: Packages/cloog-ppl-0.15.7-1.2.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

gcc-4.4.7-3.el6.x86_64: failure: Packages/gcc-4.4.7-3.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

libgomp-4.4.7-3.el6.x86_64: failure: Packages/libgomp-4.4.7-3.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

kernel-headers-2.6.32-358.el6.x86_64: failure: Packages/kernel-headers-2.6.32-358.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

autoconf-2.63-5.1.el6.noarch: failure: Packages/autoconf-2.63-5.1.el6.noarch.rpm from c6-media: [Errno 256] No more mirrors to try.

automake-1.11.1-4.el6.noarch: failure: Packages/automake-1.11.1-4.el6.noarch.rpm from c6-media: [Errno 256] No more mirrors to try.

4:perl-libs-5.10.1-129.el6.x86_64: failure: Packages/perl-libs-5.10.1-129.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

3:perl-version-0.77-129.el6.x86_64: failure: Packages/perl-version-0.77-129.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

4:perl-5.10.1-129.el6.x86_64: failure: Packages/perl-5.10.1-129.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

1:perl-Pod-Simple-3.13-129.el6.x86_64: failure: Packages/perl-Pod-Simple-3.13-129.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

glibc-devel-2.12-1.107.el6.x86_64: failure: Packages/glibc-devel-2.12-1.107.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

1:perl-Pod-Escapes-1.04-129.el6.x86_64: failure: Packages/perl-Pod-Escapes-1.04-129.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

libtool-2.2.6-15.5.el6.x86_64: failure: Packages/libtool-2.2.6-15.5.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

ppl-0.10.2-11.el6.x86_64: failure: Packages/ppl-0.10.2-11.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

cpp-4.4.7-3.el6.x86_64: failure: Packages/cpp-4.4.7-3.el6.x86_64.rpm from c6-media: [Errno 256] No more mirrors to try.

说明需要配置本地yum源或者让机器可以上网即可,如果需要配置本地yum源,可以参考另一篇文章《CentOS配置本地yum源》

安装好make后,在redis-3.2.9目录下,再执行

make && make install

出现如下信息,说明执行成功了:

Hint: It's a good idea to run 'make test'

make[1]: Leaving directory `/opt/redis-3.2.9/src'

cd src && make install

make[1]: Entering directory `/opt/redis-3.2.9/src'

Hint: It's a good idea to run 'make test'

INSTALL install

INSTALL install

INSTALL install

INSTALL install

INSTALL install

make[1]: Leaving directory `/opt/redis-3.2.9/src'

此时redis-3.2.9目录下,多了一个src文件夹,里面内容如下:

此时编译redis完成。

创建redis节点

由于要让redis集群正常运行,就至少需要3个主节点,所以在此就在一台主机上创建6个redis节点来演示集群配置,实际生产环境中需要每个节点一台主机。同时对应的redis节点的ip和端口对应关系如下:

192.168.242.10 6380

192.168.242.10 6381

192.168.242.10 6382

192.168.242.10 6383

192.168.242.10 6384

192.168.242.10 6385

在redis-3.2.9目录下,新建一个redis_cluster目录,用于存放各位节点的配置信息:

mkdir redis_cluster

同时在redis_cluster目录下分别新建6380、6381、6382、6383、6384、6385文件夹:

mkdir 6380

mkdir 6381

mkdir 6382

mkdir 6383

mkdir 6384

mkdir 6385

在6380文件夹下,新建redis.conf文件:

touch redis.conf

编辑如下内容:

daemonize yes

pidfile redis_6380.pid

logfile redis_6380.log

appendonly yes

bind 192.168.242.10

port 6380

cluster-enabled yes

cluster-config-file nodes-6380.conf

cluster-node-timeout 15000

cluster-slave-validity-factor 10

cluster-migration-barrier 1

cluster-require-full-coverage yes

集群相关的配置说明:

cluster-enabled 是否开启集群配置

cluster-config-file 集群节点集群信息配置文件,每个节点都有一个,由redis生成和更新,配置时避免名称冲突

cluster-node-timeout 集群节点互连超时的阀值,单位毫秒

cluster-slave-validity-factor 进行故障转移时,salve会 申请成为master。有时slave会和master失联很久导致数据较旧,这样的slave不应该成为master。这个配置用来判断slave是否和master失联时间过长。

同样在其它文件夹下,也新建redis.conf文件,里面的配置信息相应的修改即可。

启动各个节点:

首先进入redis-3.2.9目录下的,src目录,然后再执行启动各个节点:

./redis-server ../redis_cluster/6380/redis.conf

./redis-server ../redis_cluster/6381/redis.conf

./redis-server ../redis_cluster/6382/redis.conf

./redis-server ../redis_cluster/6383/redis.conf

./redis-server ../redis_cluster/6384/redis.conf

./redis-server ../redis_cluster/6385/redis.conf

检查各个节点是否正常启动了:

如果出现如下信息,说明6个节点正常启动了:

创建redis集群

redis官方提供了redis-trib.rb这个工具来创建redis集群,同时这个工具就在redis-3.2.9目录下的src目录中,执行如下命令:

./redis-trib.rb create --replicas 1 192.168.242.10:6380 192.168.242.10:6381 192.168.242.10:6382 192.168.242.10:6383 192.168.242.10:6384 192.168.242.10:6385

此时如果报如下错误,说明没有安装ruby:

/usr/bin/env: ruby: No such file or directory

所以先安装ruby:

yum install ruby

安装完成ruby后,再执行上面的创建集群的命令,此时如果再报如下错误,因为缺少redis和ruby的接口,使用gem安装:

./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)

from ./redis-trib.rb:24

由于安装redis和ruby的接口需要用gem,所以先装gem:

yum install rubygems

然而此时如果报如下错误:

Error Downloading Packages:

rubygems-1.3.7-1.el6.noarch: failure: Packages/rubygems-1.3.7-1.el6.noarch.rpm from c6-media: [Errno 256] No more mirrors to try.

说明在镜像文件中没有rubygems的安装包,此时只能先将rubygems的安装下载下来,然后在安装。

这里将rubygems-1.3.7-5.el6.noarch.rpm文件上传到CentOS中,然后执行安装命令:

rpm -ivh rubygems-1.3.7-5.el6.noarch.rpm

此时会报如下错误:

warning: rubygems-1.3.7-5.el6.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY

error: Failed dependencies:

ruby-rdoc is needed by rubygems-1.3.7-5.el6.noarch

说明需要先将rubygems依赖的软件先安装好,即将ruby-irb和ruby-rdoc先安装:

yum install ruby-irb ruby-rdoc

然后再执行上面安装rubygems-1.3.7-5.el6.noarch.rpm的命令,出现如下信息,说明安装成功了:

再来安装redis和ruby的接口:

gem install redis

出现如下信息,说明安装成功:

此时再来执行创建redis集群的命令:

./redis-trib.rb create --replicas 1 192.168.242.10:6380 192.168.242.10:6381 192.168.242.10:6382 192.168.242.10:6383 192.168.242.10:6384 192.168.242.10:6385

出现如下信息,说明redis集群启动成功:

>>> Creating cluster

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

192.168.242.10:6380

192.168.242.10:6381

192.168.242.10:6382

Adding replica 192.168.242.10:6383 to 192.168.242.10:6380

Adding replica 192.168.242.10:6384 to 192.168.242.10:6381

Adding replica 192.168.242.10:6385 to 192.168.242.10:6382

M: cd9a1cfb495fd728ebf86fe3c2ae484d33a55efa 192.168.242.10:6380

slots:0-5460 (5461 slots) master

M: 86ff5dd6c91f2b1f723d20e0611b6b000b5564b9 192.168.242.10:6381

slots:5461-10922 (5462 slots) master

M: c7124e5837d89a108d4fedce46d18d190d831355 192.168.242.10:6382

slots:10923-16383 (5461 slots) master

S: 1eae195a6d3628b7ac4c2152518cd0afd2dcc4a2 192.168.242.10:6383

replicates cd9a1cfb495fd728ebf86fe3c2ae484d33a55efa

S: 3dd781d5161ac8367cbf16b97414f7ecbb271fd1 192.168.242.10:6384

replicates 86ff5dd6c91f2b1f723d20e0611b6b000b5564b9

S: a942e13b48d63e54f22425a4694fb6ba71b7be89 192.168.242.10:6385

replicates c7124e5837d89a108d4fedce46d18d190d831355

Can I set the above configuration? (type 'yes' to accept): yes

>>> Nodes configuration updated

>>> Assign a different config epoch to each node

>>> Sending CLUSTER MEET messages to join the cluster

Waiting for the cluster to join....

>>> Performing Cluster Check (using node 192.168.242.10:6380)

M: cd9a1cfb495fd728ebf86fe3c2ae484d33a55efa 192.168.242.10:6380

slots:0-5460 (5461 slots) master

1 additional replica(s)

S: a942e13b48d63e54f22425a4694fb6ba71b7be89 192.168.242.10:6385

slots: (0 slots) slave

replicates c7124e5837d89a108d4fedce46d18d190d831355

S: 1eae195a6d3628b7ac4c2152518cd0afd2dcc4a2 192.168.242.10:6383

slots: (0 slots) slave

replicates cd9a1cfb495fd728ebf86fe3c2ae484d33a55efa

M: 86ff5dd6c91f2b1f723d20e0611b6b000b5564b9 192.168.242.10:6381

slots:5461-10922 (5462 slots) master

1 additional replica(s)

M: c7124e5837d89a108d4fedce46d18d190d831355 192.168.242.10:6382

slots:10923-16383 (5461 slots) master

1 additional replica(s)

S: 3dd781d5161ac8367cbf16b97414f7ecbb271fd1 192.168.242.10:6384

slots: (0 slots) slave

replicates 86ff5dd6c91f2b1f723d20e0611b6b000b5564b9

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

验证redis集群

直接通过redis-cli工具来连接集群,该redis-cli工具也是在src目录下的。

./redis-cli -h 192.168.242.10 -c -p 6380

注意:

需要加参数 -c 可连接到集群,-p的端口只要是集群中某个节点的端口就行。

连接成功后,测试往redis集群中存入数据和取数据:

CentOS中搭建Redis伪分布式集群

转自

CentOS中搭建Redis伪分布式集群【转】的更多相关文章

  1. Redis集群搭建,伪分布式集群,即一台服务器6个redis节点

    Redis集群搭建,伪分布式集群,即一台服务器6个redis节点 一.Redis Cluster(Redis集群)简介 集群搭建需要的环境 二.搭建集群 2.1Redis的安装 2.2搭建6台redi ...

  2. Zookeeper 集群搭建--单机伪分布式集群

    一. zk集群,主从节点,心跳机制(选举模式) 二.Zookeeper集群搭建注意点 1.配置数据文件 myid 1/2/3 对应 server.1/2/3 2.通过./zkCli.sh -serve ...

  3. 搭建zookeeper伪分布式集群

    伪分布式集群的意思就是在同一台机子上部署多个zookeeoer,但是他们的端口不一样. 1.安装zookeeper 到/usr/local 2.cd /usr/local/zookeeper 3.cd ...

  4. Hadoop学习---CentOS中hadoop伪分布式集群安装

    注意:此次搭建是在ssh无密码配置.jdk环境已经配置好的情况下进行的 可以参考: Hadoop完全分布式安装教程 CentOS环境下搭建hadoop伪分布式集群 1.更改主机名 执行命令:vi  / ...

  5. hadoop伪分布式集群搭建与安装(ubuntu系统)

    1:Vmware虚拟软件里面安装好Ubuntu操作系统之后使用ifconfig命令查看一下ip; 2:使用Xsheel软件远程链接自己的虚拟机,方便操作.输入自己ubuntu操作系统的账号密码之后就链 ...

  6. hadoop搭建伪分布式集群(centos7+hadoop-3.1.0/2.7.7)

    目录: Hadoop三种安装模式 搭建伪分布式集群准备条件 第一部分 安装前部署 1.查看虚拟机版本2.查看IP地址3.修改主机名为hadoop4.修改 /etc/hosts5.关闭防火墙6.关闭SE ...

  7. Hadoop伪分布式集群环境搭建

    本教程讲述在单机环境下搭建Hadoop伪分布式集群环境,帮助初学者方便学习Hadoop相关知识. 首先安装Hadoop之前需要准备安装环境. 安装Centos6.5(64位).(操作系统再次不做过多描 ...

  8. 摘要: CentOS 6.5搭建Redis3.2.8伪分布式集群

    from https://my.oschina.net/ososchina/blog/856678     摘要: CentOS 6.5搭建Redis3.2.8伪分布式集群 前言 最近在服务器上搭建了 ...

  9. 超详细!CentOS 7 + Hadoop3.0.0 搭建伪分布式集群

    超详细!CentOS 7 + Hadoop3.0.0 搭建伪分布式集群 ps:本文的步骤已自实现过一遍,在正文部分避开了旧版教程在新版使用导致出错的内容,因此版本一致的情况下照搬执行基本不会有大错误. ...

随机推荐

  1. 51nod 1624 取余最短路(set)

    题意: 佳佳有一个n*m的带权矩阵,她想从(1,1)出发走到(n,m)且只能往右往下移动,她能得到的娱乐值为所经过的位置的权的总和. 有一天,她被下了恶毒的诅咒,这个诅咒的作用是将她的娱乐值变为对p取 ...

  2. 堆模板(pascal)洛谷P3378

    题目描述 如题,初始小根堆为空,我们需要支持以下3种操作: 操作1: 1 x 表示将x插入到堆中 操作2: 2 输出该小根堆内的最小数 操作3: 3 删除该小根堆内的最小数 输入输出格式 输入格式: ...

  3. 自动化测试断言Assent的使用

    Assent 断言模板包含如下方法: assert.fail(actual, expected, message, operator) assert.ok(value, [message]) asse ...

  4. pbuilder编译构建工具分析

    1. 简介 pbuilder(personal Debian package builder)是ubuntu环境下维护debian包的专业工具,能够为每个deb包创建纯净的编译构建环境,自动解析和安装 ...

  5. Unity3D动态加载外部MovieTexture视频

    网上大家也写了很多Unity3D中播放视频的教程,关于播放外部视频的还是比较少,所以写这篇文章,不足之处,还望读者指正. 在Unity3D中,我们一般使用播放视频的方法:将*.mov,*.mp4等格式 ...

  6. struts2(s2-052)远程命令执行漏洞复现

    漏洞描述: 2017年9月5日,Apache Struts发布最新安全公告,Apache Struts2的REST插件存在远程代码执行的高危漏洞,该漏洞由lgtm.com的安全研究员汇报,漏洞编号为C ...

  7. 常用Actoin算子 与 内存管理 、共享变量、内存机制

    一.常用Actoin算子 (reduce .collect .count .take .saveAsTextFile . countByKey .foreach ) collect:从集群中将所有的计 ...

  8. oracle 数据库记录

    /*----------------------------------------------------------------------------*/ 问题1[--------] Selec ...

  9. javascript基本介绍

    javascript是一种广泛用于客户端web开发的脚本语言,常采用来给html网页添加动态功能,比如响应客户的各种操作. 脚本语言是什么? (1).脚本语言往往不能独立运行,它和html/jsp/p ...

  10. wireshark 根据域名筛选

    应该去掉引号