- 浏览: 269745 次
- 性别:
- 来自: 天津
文章分类
- 全部博客 (183)
- oracle (4)
- informix (1)
- web开发 (6)
- java (49)
- hibernate (1)
- hadoop (1)
- spring (23)
- 非技术 (8)
- ibatis2 (5)
- Linux (6)
- tomcat (14)
- nginx (7)
- dubbo (3)
- myibatis (7)
- webservice 开发 (2)
- mysql (2)
- svn (2)
- redis (7)
- 分布式技术 (17)
- zookeeper (2)
- kafka (2)
- velocity (1)
- maven (7)
- js (1)
- freemarker (1)
- Thymeleaf (3)
- 代码审计 (1)
- ibatis3 (1)
- rabbitmq (1)
最新评论
[root@yunboce ]# tar -zxvf redis-3.2.8.tar.gz
[root@yunboce cluster]# cd redis-3.2.8
[root@yunboce cluster]#make
[root@yunboce cluster]#cd src
[root@yunboce cluster]# make install
[root@yunboce src]# mkdir /opt/cluster/redis_bin
[root@yunboce src]# cp redis* /opt/cluster/redis_bin/
[root@yunboce src]# ls /opt/cluster/redis_bin/
redis-check-aof redis-check-aof.o redis-check-rdb.c redis-cli redis-server
redis-benchmark redis-check-rdb redis-sentinel redis-trib.rb
[root@yunboce cluster]# cd redis_bin/
[root@yunboce redis_bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb
[root@yunboce redis_bin]# chmod +x redis*
[root@yunboce redis_bin]# ll
总用量 34032
-rwxr-xr-x 1 root root 5574263 9月 12 16:18 redis-benchmark
-rwxr-xr-x 1 root root 22225 9月 12 16:18 redis-check-aof
-rwxr-xr-x 1 root root 7823906 9月 12 16:18 redis-check-rdb
-rwxr-xr-x 1 root root 5703131 9月 12 16:18 redis-cli
-rwxr-xr-x 1 root root 7823906 9月 12 16:18 redis-sentinel
-rwxr-xr-x 1 root root 7823906 9月 12 16:18 redis-server
-rwxr-xr-x 1 root root 60852 9月 12 16:18 redis-trib.rb
[root@yunboce redis_bin]# cd ..
[root@yunboce cluster]# ls
7000 7001 7002 7003 7004 7005 redis-3.2.8 redis-3.2.8.tar.gz redis_bin
[root@yunboce cluster]# mv 7005 redis_bin/
[root@yunboce cluster]# ll
总用量 1520
drwxrwxr-x 6 root root 4096 2月 12 2017 redis-3.2.8
-rw-r--r-- 1 root root 1547237 9月 12 15:41 redis-3.2.8.tar.gz
drwxr-xr-x 8 root root 4096 9月 12 16:24 redis_bin
[root@yunboce cluster]#
[root@yunboce cluster]#
[root@yunboce cluster]# cd redis_bin
[root@yunboce cluster]#make 7000
[root@yunboce cluster]#cp /opt/cluster/redis-3.2.8/redis.conf /opt/cluster/redis_bin/7000/redis.conf
修改redis.conf 中的内容如下:
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002,7003
port 7000 //端口7000,7002,7003
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout 5000 //请求超时 设置5秒够了
bind 192.168.6.24 127.0.0.1 //绑定id (注意本机id一定是第一个)
appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志
logfile "/var/log/redis/7000.log"
7001 7002 7003 7004 7005 操作与7000相同
[root@yunboce redis_bin]# ls
7000 7001 7002 7003 7004 7005 redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb
[root@yunboce redis_bin]#
redis-sentinel redis-server
[root@yunboce redis_bin]# ./redis-server 7000/redis.conf
[root@yunboce redis_bin]# ./redis-server 7001/redis.conf
[root@yunboce redis_bin]# ./redis-server 7002/redis.conf
[root@yunboce redis_bin]# ./redis-server 7003/redis.conf
[root@yunboce redis_bin]# ./redis-server 7004/redis.conf
[root@yunboce redis_bin]# ./redis-server 7005/redis.conf
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# ps -ef|grep redis
root 23389 1 0 16:24 ? 00:00:00 ./redis-server 192.168.6.24:7000 [cluster]
root 23393 1 0 16:24 ? 00:00:00 ./redis-server 192.168.6.24:7001 [cluster]
root 23424 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7002 [cluster]
root 23428 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7003 [cluster]
root 23432 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7004 [cluster]
root 23436 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7005 [cluster]
root 23440 16719 0 16:25 pts/10 00:00:00 grep redis
[root@yunboce redis_bin]# netstat -tnlp | grep redis
[root@yunboce redis_bin]# yum -y install ruby ruby-devel rubygems rpm-build
[root@yunboce redis_bin]# gem install redis
ERROR: Error installing redis:
redis requires Ruby version >= 2.2.2.
[root@yunboce redis_bin]# rvm list known
[root@yunboce redis_bin]#
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# sudo yum install curl
[root@yunboce redis_bin]# curl -L get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24090 100 24090 0 0 10411 0 0:00:02 0:00:02 --:--:-- 185k
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: 于 2017年09月11日 星期一 04时59分21秒 CST 创建的签名,使用 RSA,钥匙号 BF04FF17
gpg: 无法检查签名:No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.3.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
the key can be compared with:
https://rvm.io/mpapis.asc
https://keybase.io/mpapis
NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.
[root@yunboce redis_bin]# command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import
gpg: 密钥 D39DC0E3:公钥“Michal Papis (RVM signing) <mpapis@gmail.com>”已导入
gpg: 合计被处理的数量:1
gpg: 已导入:1 (RSA: 1)
gpg: 没有找到任何绝对信任的密钥
[root@yunboce redis_bin]# curl -L get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24090 100 24090 0 0 11593 0 0:00:02 0:00:02 --:--:-- 11593
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: 于 2017年09月11日 星期一 04时59分21秒 CST 创建的签名,使用 RSA,钥匙号 BF04FF17
gpg: 完好的签名,来自于“Michal Papis (RVM signing) <mpapis@gmail.com>”
gpg: 亦即“Michal Papis <michal.papis@toptal.com>”
gpg: 亦即“[jpeg image of size 5015]”
gpg: 警告:这把密钥未经受信任的签名认证!
gpg: 没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3
子钥指纹: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17
GPG verified '/usr/local/rvm/archives/rvm-1.29.3.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
source /etc/profile
Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows, in rare cases you need to reopen all shell windows.
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# source /usr/local/rvm/scripts/rvm
查看ruby 版本
[root@yunboce redis_bin]# rvm list known
# MRI Rubies
查看当前版本
[root@yunboce redis_bin]#ruby -v
插入 ruby2.3.3
[root@yunboce redis_bin]# rvm install 2.3.3
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/6/x86_64/ruby-2.3.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: libffi-devel, libyaml-devel.......
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.3.3, this may take a while depending on your cpu(s)...
ruby-2.3.3 - #downloading ruby-2.3.3, this may take a while depending on your connection...
curl: (35) SSL connect error
There was an error(35).
Checking fallback: https://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.bz2
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
This may have known and unaccounted for security vulnerabilities.
Please consider upgrading to ruby-2.4.1 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri
使用ruby 2.3.3
[root@yunboce redis_bin]# rvm use 2.3.3 或者 rvm use 2.3.3 --default
Using /usr/local/rvm/gems/ruby-2.3.3
[root@yunboce redis_bin]# rvm remove 1.8.7
查看当前版本
[root@yunboce redis_bin]# ruby --version
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
[root@yunboce redis_bin]#
执行集群命令
[root@yunboce redis_bin]# gem install redis
Fetching: redis-4.0.0.gem (100%)
Successfully installed redis-4.0.0
Parsing documentation for redis-4.0.0
Installing ri documentation for redis-4.0.0
Done installing documentation for redis after 2 seconds
1 gem installed
[root@yunboce redis_bin]# cd ../redis-3.2.8/src
[root@yunboce src]#
建立集群
解释下, --replicas 1 表示 自动为每一个master节点分配一个slave节点 上面有6个节点,程序会按照一定规则生成 3个master(主)3个slave(从)
[root@yunboce src]# ./redis-trib.rb create --replicas 1 192.168.6.24:7000 192.168.6.24:7001 192.168.6.24:7002 192.168.6.24:7003 192.168.6.24:7004 192.168.6.24:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.6.24:7000
192.168.6.24:7001
192.168.6.24:7002
Adding replica 192.168.6.24:7003 to 192.168.6.24:7000
Adding replica 192.168.6.24:7004 to 192.168.6.24:7001
Adding replica 192.168.6.24:7005 to 192.168.6.24:7002
M: 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000
slots:0-5460 (5461 slots) master
M: 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 192.168.6.24:7001
slots:5461-10922 (5462 slots) master
M: 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 192.168.6.24:7002
slots:10923-16383 (5461 slots) master
S: 96f4f6da5b172544fd90e18990f64868bd18a14c 192.168.6.24:7003
replicates 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb
S: dfd4d0e5dc242533af6cb7699e7052e11b10d619 192.168.6.24:7004
replicates 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3
S: e83888d36f4b8c56e150015be38d7dd7a0ddcc39 192.168.6.24:7005
replicates 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a
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.6.24:7000)
M: 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: e83888d36f4b8c56e150015be38d7dd7a0ddcc39 127.0.0.1:7005
slots: (0 slots) slave
replicates 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a
S: 96f4f6da5b172544fd90e18990f64868bd18a14c 127.0.0.1:7003
slots: (0 slots) slave
replicates 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb
M: 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: dfd4d0e5dc242533af6cb7699e7052e11b10d619 127.0.0.1:7004
slots: (0 slots) slave
replicates 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
安装完毕.
测试redis集群
[root@yunboce redis]# ls
7000 7003 appendonly.aof nodes-7001.conf nodes-7004.conf redis-check-aof redis-sentinel
7001 7004 dump.rdb nodes-7002.conf nodes-7005.conf redis-check-rdb redis-server
7002 7005 nodes-7000.conf nodes-7003.conf redis-benchmark redis-cli redis-trib.rb
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]# ./redis-cli -c -p 7000
127.0.0.1:7000> set test1 bocehellowolrd
OK
127.0.0.1:7000> get test1
"bocehellowolrd"
127.0.0.1:7000> cluster nodes
e83888d36f4b8c56e150015be38d7dd7a0ddcc39 192.168.6.24:7005 slave 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 0 1505283170587 6 connected
82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000 myself,master - 0 0 1 connected 0-5460
dfd4d0e5dc242533af6cb7699e7052e11b10d619 192.168.6.24:7004 slave 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 0 1505283171088 5 connected
1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 192.168.6.24:7002 master - 0 1505283171589 3 connected 10923-16383
96f4f6da5b172544fd90e18990f64868bd18a14c 192.168.6.24:7003 slave 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 0 1505283172592 4 connected
4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 192.168.6.24:7001 master - 0 1505283169584 2 connected 5461-10922
127.0.0.1:7000>
127.0.0.1:7000> quit
[root@yunboce redis]# ./redis-cli -c -p 7001
127.0.0.1:7001> get test1
-> Redirected to slot [4768] located at 192.168.6.24:7000
"bocehellowolrd"
192.168.6.24:7000>
Java测试代码:
package com.alibaba.dubbo.demo.consumer;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
public class JedisClusterTest {
JedisCluster jedisCluster = null;
private String nameKey="test1";
/**
* 因为是测试,这里没有写单例
*/
public void before(){
Set<HostAndPort> nodes = new HashSet<HostAndPort>();
nodes.add(new HostAndPort("192.168.6.24",7000));
nodes.add(new HostAndPort("192.168.6.24",7001));
nodes.add(new HostAndPort("192.168.6.24",7002));
nodes.add(new HostAndPort("192.168.6.24",7003));
nodes.add(new HostAndPort("192.168.6.24",7004));
nodes.add(new HostAndPort("192.168.6.24",7005));
//注意:这里超时时间不要太短,他会有超时重试机制。而且其他像httpclient、dubbo等RPC框架也要注意这点
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxIdle(200);
config.setMaxTotal(300);
config.setTestOnReturn(true);
jedisCluster = new JedisCluster(nodes, 10000, 1000, 1,
config);
System.out.println(jedisCluster+"===");
System.out.println(jedisCluster.set("test1", "张三"));
System.out.println(jedisCluster.get("test1"));
}
/**
* 简单字符串读写
*/
public void setStringData(){
// System.out.println(jedisCluster.set("test1", "张三"));
System.out.println(jedisCluster.get("test1"));
}
/**
* setnx : 如果key存在,返回0,如果不存在,则设置成功。
* setnx的意思是set if not exist.
*/
public void setnxTest(){
// System.out.println(jedisCluster.setnx(nameKey, "张三"));//key不存在,返回值为1
System.out.println(jedisCluster.get(nameKey));
// System.out.println(jedisCluster.setnx(nameKey, "张三"));//已经存在,返回值为0
System.out.println(jedisCluster.get(nameKey));
}
public static void main(String[] args) {
JedisClusterTest test = new JedisClusterTest();
test.before();
test.setStringData();
test.setnxTest();
}
}
redis cluster配置好,并运行一段时间后,我们想添加节点,或者删除节点
可以参照:
http://blog.51yip.com/nosql/1726.html
[root@yunboce cluster]# cd redis-3.2.8
[root@yunboce cluster]#make
[root@yunboce cluster]#cd src
[root@yunboce cluster]# make install
[root@yunboce src]# mkdir /opt/cluster/redis_bin
[root@yunboce src]# cp redis* /opt/cluster/redis_bin/
[root@yunboce src]# ls /opt/cluster/redis_bin/
redis-check-aof redis-check-aof.o redis-check-rdb.c redis-cli redis-server
redis-benchmark redis-check-rdb redis-sentinel redis-trib.rb
[root@yunboce cluster]# cd redis_bin/
[root@yunboce redis_bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb
[root@yunboce redis_bin]# chmod +x redis*
[root@yunboce redis_bin]# ll
总用量 34032
-rwxr-xr-x 1 root root 5574263 9月 12 16:18 redis-benchmark
-rwxr-xr-x 1 root root 22225 9月 12 16:18 redis-check-aof
-rwxr-xr-x 1 root root 7823906 9月 12 16:18 redis-check-rdb
-rwxr-xr-x 1 root root 5703131 9月 12 16:18 redis-cli
-rwxr-xr-x 1 root root 7823906 9月 12 16:18 redis-sentinel
-rwxr-xr-x 1 root root 7823906 9月 12 16:18 redis-server
-rwxr-xr-x 1 root root 60852 9月 12 16:18 redis-trib.rb
[root@yunboce redis_bin]# cd ..
[root@yunboce cluster]# ls
7000 7001 7002 7003 7004 7005 redis-3.2.8 redis-3.2.8.tar.gz redis_bin
[root@yunboce cluster]# mv 7005 redis_bin/
[root@yunboce cluster]# ll
总用量 1520
drwxrwxr-x 6 root root 4096 2月 12 2017 redis-3.2.8
-rw-r--r-- 1 root root 1547237 9月 12 15:41 redis-3.2.8.tar.gz
drwxr-xr-x 8 root root 4096 9月 12 16:24 redis_bin
[root@yunboce cluster]#
[root@yunboce cluster]#
[root@yunboce cluster]# cd redis_bin
[root@yunboce cluster]#make 7000
[root@yunboce cluster]#cp /opt/cluster/redis-3.2.8/redis.conf /opt/cluster/redis_bin/7000/redis.conf
修改redis.conf 中的内容如下:
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002,7003
port 7000 //端口7000,7002,7003
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout 5000 //请求超时 设置5秒够了
bind 192.168.6.24 127.0.0.1 //绑定id (注意本机id一定是第一个)
appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志
logfile "/var/log/redis/7000.log"
7001 7002 7003 7004 7005 操作与7000相同
[root@yunboce redis_bin]# ls
7000 7001 7002 7003 7004 7005 redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb
[root@yunboce redis_bin]#
redis-sentinel redis-server
[root@yunboce redis_bin]# ./redis-server 7000/redis.conf
[root@yunboce redis_bin]# ./redis-server 7001/redis.conf
[root@yunboce redis_bin]# ./redis-server 7002/redis.conf
[root@yunboce redis_bin]# ./redis-server 7003/redis.conf
[root@yunboce redis_bin]# ./redis-server 7004/redis.conf
[root@yunboce redis_bin]# ./redis-server 7005/redis.conf
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# ps -ef|grep redis
root 23389 1 0 16:24 ? 00:00:00 ./redis-server 192.168.6.24:7000 [cluster]
root 23393 1 0 16:24 ? 00:00:00 ./redis-server 192.168.6.24:7001 [cluster]
root 23424 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7002 [cluster]
root 23428 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7003 [cluster]
root 23432 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7004 [cluster]
root 23436 1 0 16:25 ? 00:00:00 ./redis-server 192.168.6.24:7005 [cluster]
root 23440 16719 0 16:25 pts/10 00:00:00 grep redis
[root@yunboce redis_bin]# netstat -tnlp | grep redis
[root@yunboce redis_bin]# yum -y install ruby ruby-devel rubygems rpm-build
[root@yunboce redis_bin]# gem install redis
ERROR: Error installing redis:
redis requires Ruby version >= 2.2.2.
[root@yunboce redis_bin]# rvm list known
[root@yunboce redis_bin]#
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# sudo yum install curl
[root@yunboce redis_bin]# curl -L get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24090 100 24090 0 0 10411 0 0:00:02 0:00:02 --:--:-- 185k
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: 于 2017年09月11日 星期一 04时59分21秒 CST 创建的签名,使用 RSA,钥匙号 BF04FF17
gpg: 无法检查签名:No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.3.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
the key can be compared with:
https://rvm.io/mpapis.asc
https://keybase.io/mpapis
NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.
[root@yunboce redis_bin]# command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import
gpg: 密钥 D39DC0E3:公钥“Michal Papis (RVM signing) <mpapis@gmail.com>”已导入
gpg: 合计被处理的数量:1
gpg: 已导入:1 (RSA: 1)
gpg: 没有找到任何绝对信任的密钥
[root@yunboce redis_bin]# curl -L get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24090 100 24090 0 0 11593 0 0:00:02 0:00:02 --:--:-- 11593
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: 于 2017年09月11日 星期一 04时59分21秒 CST 创建的签名,使用 RSA,钥匙号 BF04FF17
gpg: 完好的签名,来自于“Michal Papis (RVM signing) <mpapis@gmail.com>”
gpg: 亦即“Michal Papis <michal.papis@toptal.com>”
gpg: 亦即“[jpeg image of size 5015]”
gpg: 警告:这把密钥未经受信任的签名认证!
gpg: 没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3
子钥指纹: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17
GPG verified '/usr/local/rvm/archives/rvm-1.29.3.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
source /etc/profile
Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows, in rare cases you need to reopen all shell windows.
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# source /usr/local/rvm/scripts/rvm
查看ruby 版本
[root@yunboce redis_bin]# rvm list known
# MRI Rubies
查看当前版本
[root@yunboce redis_bin]#ruby -v
插入 ruby2.3.3
[root@yunboce redis_bin]# rvm install 2.3.3
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/6/x86_64/ruby-2.3.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: libffi-devel, libyaml-devel.......
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.3.3, this may take a while depending on your cpu(s)...
ruby-2.3.3 - #downloading ruby-2.3.3, this may take a while depending on your connection...
curl: (35) SSL connect error
There was an error(35).
Checking fallback: https://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.bz2
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
This may have known and unaccounted for security vulnerabilities.
Please consider upgrading to ruby-2.4.1 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri
使用ruby 2.3.3
[root@yunboce redis_bin]# rvm use 2.3.3 或者 rvm use 2.3.3 --default
Using /usr/local/rvm/gems/ruby-2.3.3
[root@yunboce redis_bin]# rvm remove 1.8.7
查看当前版本
[root@yunboce redis_bin]# ruby --version
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
[root@yunboce redis_bin]#
执行集群命令
[root@yunboce redis_bin]# gem install redis
Fetching: redis-4.0.0.gem (100%)
Successfully installed redis-4.0.0
Parsing documentation for redis-4.0.0
Installing ri documentation for redis-4.0.0
Done installing documentation for redis after 2 seconds
1 gem installed
[root@yunboce redis_bin]# cd ../redis-3.2.8/src
[root@yunboce src]#
建立集群
解释下, --replicas 1 表示 自动为每一个master节点分配一个slave节点 上面有6个节点,程序会按照一定规则生成 3个master(主)3个slave(从)
[root@yunboce src]# ./redis-trib.rb create --replicas 1 192.168.6.24:7000 192.168.6.24:7001 192.168.6.24:7002 192.168.6.24:7003 192.168.6.24:7004 192.168.6.24:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.6.24:7000
192.168.6.24:7001
192.168.6.24:7002
Adding replica 192.168.6.24:7003 to 192.168.6.24:7000
Adding replica 192.168.6.24:7004 to 192.168.6.24:7001
Adding replica 192.168.6.24:7005 to 192.168.6.24:7002
M: 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000
slots:0-5460 (5461 slots) master
M: 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 192.168.6.24:7001
slots:5461-10922 (5462 slots) master
M: 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 192.168.6.24:7002
slots:10923-16383 (5461 slots) master
S: 96f4f6da5b172544fd90e18990f64868bd18a14c 192.168.6.24:7003
replicates 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb
S: dfd4d0e5dc242533af6cb7699e7052e11b10d619 192.168.6.24:7004
replicates 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3
S: e83888d36f4b8c56e150015be38d7dd7a0ddcc39 192.168.6.24:7005
replicates 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a
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.6.24:7000)
M: 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: e83888d36f4b8c56e150015be38d7dd7a0ddcc39 127.0.0.1:7005
slots: (0 slots) slave
replicates 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a
S: 96f4f6da5b172544fd90e18990f64868bd18a14c 127.0.0.1:7003
slots: (0 slots) slave
replicates 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb
M: 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: dfd4d0e5dc242533af6cb7699e7052e11b10d619 127.0.0.1:7004
slots: (0 slots) slave
replicates 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
安装完毕.
测试redis集群
[root@yunboce redis]# ls
7000 7003 appendonly.aof nodes-7001.conf nodes-7004.conf redis-check-aof redis-sentinel
7001 7004 dump.rdb nodes-7002.conf nodes-7005.conf redis-check-rdb redis-server
7002 7005 nodes-7000.conf nodes-7003.conf redis-benchmark redis-cli redis-trib.rb
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]# ./redis-cli -c -p 7000
127.0.0.1:7000> set test1 bocehellowolrd
OK
127.0.0.1:7000> get test1
"bocehellowolrd"
127.0.0.1:7000> cluster nodes
e83888d36f4b8c56e150015be38d7dd7a0ddcc39 192.168.6.24:7005 slave 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 0 1505283170587 6 connected
82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000 myself,master - 0 0 1 connected 0-5460
dfd4d0e5dc242533af6cb7699e7052e11b10d619 192.168.6.24:7004 slave 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 0 1505283171088 5 connected
1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 192.168.6.24:7002 master - 0 1505283171589 3 connected 10923-16383
96f4f6da5b172544fd90e18990f64868bd18a14c 192.168.6.24:7003 slave 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 0 1505283172592 4 connected
4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 192.168.6.24:7001 master - 0 1505283169584 2 connected 5461-10922
127.0.0.1:7000>
127.0.0.1:7000> quit
[root@yunboce redis]# ./redis-cli -c -p 7001
127.0.0.1:7001> get test1
-> Redirected to slot [4768] located at 192.168.6.24:7000
"bocehellowolrd"
192.168.6.24:7000>
Java测试代码:
package com.alibaba.dubbo.demo.consumer;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
public class JedisClusterTest {
JedisCluster jedisCluster = null;
private String nameKey="test1";
/**
* 因为是测试,这里没有写单例
*/
public void before(){
Set<HostAndPort> nodes = new HashSet<HostAndPort>();
nodes.add(new HostAndPort("192.168.6.24",7000));
nodes.add(new HostAndPort("192.168.6.24",7001));
nodes.add(new HostAndPort("192.168.6.24",7002));
nodes.add(new HostAndPort("192.168.6.24",7003));
nodes.add(new HostAndPort("192.168.6.24",7004));
nodes.add(new HostAndPort("192.168.6.24",7005));
//注意:这里超时时间不要太短,他会有超时重试机制。而且其他像httpclient、dubbo等RPC框架也要注意这点
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxIdle(200);
config.setMaxTotal(300);
config.setTestOnReturn(true);
jedisCluster = new JedisCluster(nodes, 10000, 1000, 1,
config);
System.out.println(jedisCluster+"===");
System.out.println(jedisCluster.set("test1", "张三"));
System.out.println(jedisCluster.get("test1"));
}
/**
* 简单字符串读写
*/
public void setStringData(){
// System.out.println(jedisCluster.set("test1", "张三"));
System.out.println(jedisCluster.get("test1"));
}
/**
* setnx : 如果key存在,返回0,如果不存在,则设置成功。
* setnx的意思是set if not exist.
*/
public void setnxTest(){
// System.out.println(jedisCluster.setnx(nameKey, "张三"));//key不存在,返回值为1
System.out.println(jedisCluster.get(nameKey));
// System.out.println(jedisCluster.setnx(nameKey, "张三"));//已经存在,返回值为0
System.out.println(jedisCluster.get(nameKey));
}
public static void main(String[] args) {
JedisClusterTest test = new JedisClusterTest();
test.before();
test.setStringData();
test.setnxTest();
}
}
redis cluster配置好,并运行一段时间后,我们想添加节点,或者删除节点
可以参照:
http://blog.51yip.com/nosql/1726.html
发表评论
-
解决redisCluster 连接失败的问题
2017-09-25 10:53 1666使用redis3.2.8 建立集群后,发现在连接redis 经 ... -
redis 在Linux 中设置开机自启动
2017-07-20 10:02 2381首先在 /etc/init.d中建立redis 文件,文件 ... -
使用spring4的cache操作redis
2017-07-19 10:59 9201.下载: <dependency> ... -
redis 命令
2017-03-23 14:59 4121.连接redis ,redis-client -h ip地 ... -
redis 实现分布式锁以及测试
2017-03-22 16:23 10341.准备jar包 compile group: 'red ... -
redis 安装以及 主从同步
2017-02-24 16:48 4851.使用redis 2.8.24 2.下载 redi ...
相关推荐
在本教程中,我们将深入探讨如何在Ubuntu 16.04上安装Redis 3.2.8,这是一个流行的开源键值存储系统,常用于缓存、消息队列和其他高性能数据处理场景。以下是你需要知道的关键步骤和相关知识点: 1. **了解Redis**...
本文将深入探讨Redis 3.2.8的核心功能以及配置集群的相关知识。 首先,Redis 3.2.8对主从复制(Replication)进行了优化,提升了数据同步的效率。主节点可以批量传输RDB快照或者AOF日志到从节点,减少了网络传输的...
最近在服务器上搭建了一套Redis3.0伪分布式集群,发现一个问题,就是Shell脚本编写能力和运维工具的重要性亟待提高。 集群环境安装 1.安装Redis $ cd /usr/local #安装目录 $ wget ...
现在,我们来讨论如何安装 Redis 3.2.8: 1. **解压**:首先,你需要解压下载的 "redis-3.2.8.tar.gz" 文件,通常可以使用 `tar -zxvf redis-3.2.8.tar.gz` 命令完成。 2. **编译**:进入解压后的目录,运行 `make...
在Linux上安装Redis 3.2.8的步骤如下: 1. **下载源码**:通过wget或curl命令从官网或者镜像站点下载"redis-3.2.8.tar.gz"。 2. **解压**:使用tar命令解压源码包,例如`tar -zxvf redis-3.2.8.tar.gz`。 3. **...
它允许用户通过直观的界面来管理和操作Redis实例,包括查看、添加、修改和删除数据,执行命令,监控服务器状态,以及管理复制和集群。Redis Desktop Manager的主要特性有: 1. **多语言支持**:支持多种语言界面,...
6. **Cluster支持**:Redis 3.2对Cluster集群的支持更加完善,可以水平扩展Redis的存储能力,实现数据的自动分片和冗余备份。 7. **RDB持久化优化**:在3.2版本中,Redis改进了RDB持久化策略,使得在生成RDB快照时...
以下将详细介绍如何在Linux系统上安装Redis集群。 首先,安装必要的依赖。在大多数Linux发行版中,Redis的构建需要`gcc-c++`、`automake`、`autoconf`、`libtool`和`make`等工具。此外,由于集群配置会用到Ruby脚本...
标题中的“mac redis-3.2.8”指的是在苹果Mac操作系统上安装并使用的Redis数据库版本3.2.8。Redis是一个开源的、基于键值对的数据存储系统,常用于缓存、消息队列和数据结构服务器。版本3.2.8是其历史版本之一,可能...
- 主从复制:Redis 支持单向主从复制,可以构建高可用性集群,确保数据安全。 - 复制流:在3.2.8中,复制流允许客户端监听主节点到从节点的数据传输,用于监控和故障排查。 3. **事务**: - Redis 支持多条命令...
基于redis版本3.2.8离线搭建集群(包含gcc离线安装包,openssl,zlib,ruby,rubygems,redis-3.3.3.gem,redis-3.2.8.tar.gz) Redis集群离线部署搭建.docx README.txt
本篇将详细介绍如何在Linux上安装和配置Redis 3.2.8版本,以及通过提供的文件`redis-3.2.8.tar.gz`进行操作。 首先,我们需要从`redis-3.2.8.tar.gz`这个压缩包中解压文件。在Linux终端中,可以使用以下命令: ```...
从Codis1.9配合Redis2.8.13到Codis2.0搭配Redis2.8.21,再到Codis3.x与Redis3.2.8的结合,每次版本升级都体现了对性能、稳定性和易用性的关注。但这个过程中也面临着组件众多、部署复杂、中间件性能损失以及部分功能...
在生产环境中,由于Redis是单进程的,所以考虑使用哨兵(Sentinel)或集群(Cluster)来提高可用性和可扩展性。另外,Redis支持的数据结构包括字符串、哈希、列表、集合和有序集合,使其在处理各种数据操作时非常...
下面将详细介绍如何利用这个压缩包进行Redis的安装与集群配置。 1. **Redis的安装** - 首先,你需要解压`redis-3.2.8.tar.gz`文件,这是Redis的源代码包。进入解压后的目录,运行`make`命令编译源码,然后使用`...
- 解压 Redis 压缩包:`tar -xvf redis-3.2.8.tar.gz` - 进入解压后的目录并执行编译命令:`make` - 安装:`make install` ##### 4.3 启动与停止 - **启动 Redis**:`redis-server` - 如果需要后台运行:`redis-...
数据备份可通过主从复制实现,而Redis集群则用于扩展到多个节点,提高可用性和数据安全性。 与Python交互可以通过redis-py库,这是一个Python的Redis客户端,提供了丰富的API来执行各种Redis命令。安装redis-py可以...