redis集群安装:
安装http://blog.csdn.net/zhu_tianwei/article/details/44928779
安装http://blog.csdn.net/xu470438000/article/details/42971091
jedis坑http://blog.csdn.net/myrainblues/article/details/25881535/
使用淘宝的一个镜像就可以安装redis了
gem sources -a https://ruby.taobao.org/
sudo gem install redis
make时cc: command not found
yum install gcc
再次报错
1、make的时候注意:
如果make的时候提示如下错误:
cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/lua/src/liblua.a: No such file or directory
cc: error: ../deps/jemalloc/lib/libjemalloc.a: No such file or directory
make: *** [redis-server] Error 1
则进入redis下的deps下的运行如下命令,就OK了。
make lua hiredis linenoise
2、make test的时候注意:
[root@openstack-control redis-3.0.2]# make test
cd src && make test
make[1]: Entering directory `/root/redis-3.0.2/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/root/redis-3.0.2/src'
make: *** [test] Error 2
则yum install tcl即可。
3、make PREFIX=/usr/local/redis install
4、 make: *** No rule to make target
删掉redis-x.x.x目录重新解压
#如果没有开发所配置的端口,那么打开端口
#我们除了看到 配置文件中设置的端口700X 还有700X+10000 (1700X), 前者是客户端访问的, 后者是集群内部节点之间访问的.
iptables -A INPUT -p tcp --dport 700X -j ACCEPT
iptables -A INPUT -p tcp --dport 1700X -j ACCEPT
我的安装过程
cd /usr/local/mkdir cluster
cd cluster/
mkdir 7000 7001 7002 7003 7004 7005
cd ../redis3.0/
cp -r * ../cluster/7000
cp -r * ../cluster/7001
cp -r * ../cluster/7002
cp -r * ../cluster/7003
cp -r * ../cluster/7004
cp -r * ../cluster/7005
cd ../cluster/
ll
cd 7000
ll
#修改端口,cp到其他目录依次修改对应的端口
vi redis.conf
ll
cd src
ll
#启动redis
redis-server ../redis.conf
#查看启动结果
ps aux | grep redis
cd /usr/local/cluster/
7001/src/redis-server 7001/redis.conf
cd 7001/src
ll
redis-server ../redis.conf
cd ../../7002/src
redis-server ../redis.conf
cd ../../7003/src
redis-server ../redis.conf
cd ../../7004/src
redis-server ../redis.conf
cd ../../7005/src
redis-server ../redis.conf
ps aux | grep redis
cd /usr/local/redis3.0/
cd src/
#创建集群
./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
ll
./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
ll
#如果缺少ruby库,安装
yum install ruby
yum install rubygems
./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
#可能会没有执行权限,授权
chmod 777 redis-trib.rb
./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
#登陆集群
redis-cli -c -p 7000
redis3.0集群密码设置
1.使用redis-trib.rb构建集群 完成前不要配置密码2.集群构建完再通过config set + config rewrite命令逐个实例设置密码
3.对集群设置密码,requirepass和masterauth都需要设置
4.各个节点密码都必须一致,否则Redirected就会失败
-----------------------------------------
config set masterauth aaaaaa
config set requirepass aaaaaa
config rewrite
设置密码后,redis-trib.rb check 192.168.0.107:6379 报错连接不上实例,解决方法:
vim /usr/lib/ruby/gems/1.8/gems/redis-3.3.0/lib/redis/client.rb
class Redis
class Client
DEFAULTS = {
:url => lambda { ENV["REDIS_URL"] },
:scheme => "redis",
:host => "127.0.0.1",
:port => 6379,
:path => nil,
:timeout => 5.0,
:password => "aaaaaa",
:db => 0,
:driver => nil,
:id => nil,
:tcp_keepalive => 0,
:reconnect_attempts => 1,
:inherit_socket => false
}
修改下默认密码就可以了
jedis连接redis集群
无密码版旧版jedis
redis集群环境搭建以及java中jedis客户端集群代码实现
有密码版新版jedis2.9
redis学习笔记(二)JedisCluster + redis 3.2.5集群http://blog.csdn.net/liubenlong007/article/details/53689306
在jedis连接redis集群过程中出现异常
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
但是使用客户端是可以连接,后来打印了一下System.out.println(jedisCluster.getClusterNodes());发现结果是
{127.0.0.1:7005=redis.clients.jedis.JedisPool@3904e3f1, 127.0.0.1:7004=redis.clients.jedis.JedisPool@70110075, 127.0.0.1:7003=redis.clients.jedis.JedisPool@6c353acd, 127.0.0.1:7002=redis.clients.jedis.JedisPool@1aa7a03b, 127.0.0.1:7001=redis.clients.jedis.JedisPool@73088f28, 127.0.0.1:7000=redis.clients.jedis.JedisPool@36eec618}
这明显是创建集群的时候写的单个redis的地址是127.0.0.1。然后我在创建集群的时候写成内网ip./redis-trib.rb create --replicas 1 192.168.1.80:7000 192.168.1.80:7001 192.168.1.80:7002 192.168.1.80:7003 192.168.1.80:7004 192.168.1.80:7005
再通过jedis进行连接之后就没有问题了。