1...下载redis
https://redis.io/
2...上传服务器,解压,编译
mv redis-3.2.9.tar.gz redis3.0
cd /usr/local/dev/redis-3.2.9
make
make install PREFIX=/usr/local/redis
(make之前要注意几个内容报错)
2.1./bin/sh: cc: command not found
安装gcc:yum install gcc
安装g++: yum install gcc-c++
2.2.zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or director
解决方案:make MALLOC=libc
2.3.安装后可以运行make test检测是否安装成功,这个时候可能出现的问题:
You need tcl 8.5 or newer in order to run the Redis test
安装tcl测试 : yum install tcl
下面代表测试通过:
\o/ All tests passed without errors!
Cleanup: may take some time... OK
3.创建所需要的目录(至少需要6个)
cd /usr/local/dev/redisCluster
mkdir 7000
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
拷贝执行文件到对应文件夹:(目录取决于你的安装目录 即PREFIX=/usr/local/redis)
cp -r /usr/local/redis/bin/* /usr/local/dev/redisCluster/7001
............
4:修改配置文件redis.conf(也可以直接使用附件中文件)
/usr/local/dev/redis-3.2.9
##修改配置文件中的下面选项
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
如果需要带密码验证的redis,需要在配置的最后一行(推荐在最后一行) 添加自己的认证密码:
masterauth "qwerty"
requirepass "qwerty"
##修改完redis.conf配置文件中的这些配置项之后把这个配置文件分别拷贝到7000/7001/7002/7003/7004/7005目录下面
##注意:拷贝完成之后要修改7001/7002/7003/7004/7005目录下面redis.conf文件中的port参数,分别改为对应的文件夹的名称(推荐使用notepad++的NppFTP插件进行修改)
5:分别启动这6个redis实例(也可以使用附件中的脚本runAll.sh放到对应位置进行启动)
redis-server redis.conf
cd /usr/local/dev/redisCluster/7001
redis-server redis.conf
cd /usr/local/dev/redisCluster/7002
redis-server redis.conf
cd /usr/local/dev/redisCluster/7003
redis-server redis.conf
cd /usr/local/dev/redisCluster/7004
redis-server redis.conf
cd /usr/local/dev/redisCluster/7005
redis-server redis.conf
6:执行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
6.1执行上面的命令的时候会报错,因为是执行的ruby的脚本,需要ruby的环境
错误内容:/usr/bin/env: ruby: No such file or directory
所以需要安装ruby的环境,这里推荐使用yum install ruby安装
6.2然后再执行第6步的创建集群命令,还会报错,提示缺少rubygems组件,使用yum安装
错误内容:
./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)
from ./redis-trib.rb:24
6.3再次执行第6步的命令,还会报错,提示不能加载redis,是因为缺少redis和ruby的接口,使用gem 安装
错误内容:
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from ./redis-trib.rb:25
注意:gem install redis --version 3.3.3 失败的话,需要修改一下gem的源
gem sources -a https://ruby.taobao.org/
6.4 再次执行第6步的命令,正常执行
这个地方如果前面你配置了密码会报错:
Sorry, can't connect to node 127.0.0.1:7000
前面加入密码验证的步骤的验证完以后需要修改ruby的一个文件才能生效(因为要用到ruby来创建redis集群),命令如下:
-----前提是安装了ruby-gems,
340 yum install ruby 安装ruby
341 yum install rubygems 安装ruby的基础gems
342 gem install redis --version 3.3.3 安装redis的gems
343 gem sources --remove https://rubygems.org/
344 gem sources -a https://ruby.taobao.org/ 这两步是删除自带的地址换为淘宝的源
345 gem install redis --version 3.3.3
需要ruby文件
find / -name "client.rb"
vi /usr/local/share/gems/gems/redis-3.3.3/lib/redis/client.rb
将下面的属性修改为和上面conf里面同样的
DEFAULTS = {
:url => lambda { ENV["REDIS_URL"] },
:scheme => "redis",
:host => "127.0.0.1",
:port => 6379,
:path => nil,
:timeout => 5.0,
:password => "qwerty",
:db => 0,
:driver => nil,
:id => nil,
:tcp_keepalive => 0,
:reconnect_attempts => 1,
:inherit_socket => false
}
安装成功!!!!
启动某个端口的redis:
./redis-cli -c -p 7002 -a qwerty(带上认证)(-a 是认证英语的缩写)
补充篇:
ruby的gems管理:
gem query –remote-----查询出当前安装的gems和版本
*** LOCAL GEMS ***
bigdecimal (1.2.0)
io-console (0.4.2)
json (1.7.7)
psych (2.0.0)
rdoc (4.0.0)
redis (3.3.3)
gem uninstall redis ----如果多个版本的他会问你输入版本号
增加对bind ip的操作和理解:
在redis.conf里面有一段配置:
################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1
bind 192.168.1.97 127.0.0.1
它的默认端口为6379,如果你是使用linux本身操作,那么默认bind的ip是127.0.0.1,如果你想要通过windows来访问redis,那么bind的ip更改成你linux的ip,使用ifconfig来查看linux的ip。
这段话的意思不是绑定了那些IP可以访问,而是开放了那些接口或者说是网卡供外界访问,这里很容易让人误认为是白名单ip
如果这个地方你配置了,那么下面的创建集群命令可能会有一些变化
6、开始集群使用以下命令,可将它写在一个shell脚本中
./redis-trib.rb create --replicas 1 192.168.243.128:7001 192.168.243.128:7002 192.168.243.128:7003 192.168.243.128:7004 192.168.243.128:7005 192.168.243.128:7006
写在一个叫cluster.sh的脚本中,执行当然你直接将上面的命令输入也可以,这里的ip地址是你在redis.conf绑定的ip
更详细的内容 请参考
http://www.cnblogs.com/honger/p/5852005.html