搭建Ruby
yum install ruby
yum install rubygems
安装redis 和 gcc,tcl
[root@izwz92bdx6sqk095sd98lez src]# yum install -y gcc-c++
[root@izwz92bdx6sqk095sd98lez src]# wget http://download.redis.io/releases/redis-3.0.0.tar.gz
[root@izwz92bdx6sqk095sd98lez src]# tar -xvzf redis-2.8.3.tar.gz -C /agui/redis/
[root@izwz92bdx6sqk095sd98lez redis-3.0.0]# ll
total 144
-rw-rw-r-- 1 root root 25890 Apr 1 2015 00-RELEASENOTES
-rw-rw-r-- 1 root root 53 Apr 1 2015 BUGS
-rw-rw-r-- 1 root root 1439 Apr 1 2015 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 Apr 1 2015 COPYING
drwxrwxr-x 6 root root 4096 Apr 1 2015 deps
-rw-rw-r-- 1 root root 11 Apr 1 2015 INSTALL
-rw-rw-r-- 1 root root 151 Apr 1 2015 Makefile
-rw-rw-r-- 1 root root 4223 Apr 1 2015 MANIFESTO
-rw-rw-r-- 1 root root 5201 Apr 1 2015 README
-rw-rw-r-- 1 root root 41403 Apr 1 2015 redis.conf
-rwxrwxr-x 1 root root 271 Apr 1 2015 runtest
-rwxrwxr-x 1 root root 280 Apr 1 2015 runtest-cluster
-rwxrwxr-x 1 root root 281 Apr 1 2015 runtest-sentinel
-rw-rw-r-- 1 root root 7109 Apr 1 2015 sentinel.conf
drwxrwxr-x 2 root root 4096 Apr 1 2015 src
drwxrwxr-x 10 root root 4096 Apr 1 2015 tests
drwxrwxr-x 5 root root 4096 Apr 1 2015 utils
[root@izwz92bdx6sqk095sd98lez src]# yum install tcl
[root@izwz92bdx6sqk095sd98lez redis-3.0.0]# make
//最后如下则完成呢
CC latency.o
CC sparkline.o
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
CC redis-check-dump.o
LINK redis-check-dump
CC redis-check-aof.o
LINK redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/agui/redis/redis-3.0.0/src'
[root@izwz92bdx6sqk095sd98lez redis-3.0.0]# make install PREFIX=/agui/redis
cd src && make install
make[1]: Entering directory `/agui/redis/redis-3.0.0/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 `/agui/redis/redis-3.0.0/src'
[root@izwz92bdx6sqk095sd98lez redis]# cd bin
[root@izwz92bdx6sqk095sd98lez bin]# ll
total 8492
-rwxr-xr-x 1 root root 2075208 Mar 16 13:56 redis-benchmark
-rwxr-xr-x 1 root root 25216 Mar 16 13:56 redis-check-aof
-rwxr-xr-x 1 root root 56064 Mar 16 13:56 redis-check-dump
-rwxr-xr-x 1 root root 2199368 Mar 16 13:56 redis-cli
lrwxrwxrwx 1 root root 12 Mar 16 13:56 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 4331072 Mar 16 13:56 redis-server
[root@izwz92bdx6sqk095sd98lez bin]# cd ../
[root@izwz92bdx6sqk095sd98lez redis]# cd redis-3.0.0/
[root@izwz92bdx6sqk095sd98lez redis-3.0.0]# ll
total 144
-rw-rw-r-- 1 root root 25890 Apr 1 2015 00-RELEASENOTES
-rw-rw-r-- 1 root root 53 Apr 1 2015 BUGS
-rw-rw-r-- 1 root root 1439 Apr 1 2015 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 Apr 1 2015 COPYING
drwxrwxr-x 6 root root 4096 Mar 16 13:38 deps
-rw-rw-r-- 1 root root 11 Apr 1 2015 INSTALL
-rw-rw-r-- 1 root root 151 Apr 1 2015 Makefile
-rw-rw-r-- 1 root root 4223 Apr 1 2015 MANIFESTO
-rw-rw-r-- 1 root root 5201 Apr 1 2015 README
-rw-rw-r-- 1 root root 41403 Apr 1 2015 redis.conf
-rwxrwxr-x 1 root root 271 Apr 1 2015 runtest
-rwxrwxr-x 1 root root 280 Apr 1 2015 runtest-cluster
-rwxrwxr-x 1 root root 281 Apr 1 2015 runtest-sentinel
-rw-rw-r-- 1 root root 7109 Apr 1 2015 sentinel.conf
drwxrwxr-x 2 root root 4096 Mar 16 13:39 src
drwxrwxr-x 10 root root 4096 Apr 1 2015 tests
drwxrwxr-x 5 root root 4096 Apr 1 2015 utils
[root@izwz92bdx6sqk095sd98lez redis-3.0.0]# cp redis.conf /agui/redis/bin/
[root@izwz92bdx6sqk095sd98lez redis-3.0.0]# cd ../bin/
[root@izwz92bdx6sqk095sd98lez bin]# ll
total 8536
-rwxr-xr-x 1 root root 2075208 Mar 16 13:56 redis-benchmark
-rwxr-xr-x 1 root root 25216 Mar 16 13:56 redis-check-aof
-rwxr-xr-x 1 root root 56064 Mar 16 13:56 redis-check-dump
-rwxr-xr-x 1 root root 2199368 Mar 16 13:56 redis-cli
-rw-r--r-- 1 root root 41403 Mar 16 14:03 redis.conf
lrwxrwxrwx 1 root root 12 Mar 16 13:56 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 4331072 Mar 16 13:56 redis-server
[root@izwz92bdx6sqk095sd98lez bin]# vim redis.conf
//修改redis.conf 中的 daemonize 为 yes
//如下就可以后端启动了
[root@izwz92bdx6sqk095sd98lez bin]# ./redis-server redis.conf
[root@izwz92bdx6sqk095sd98lez bin]# ps -ef|grep redis
root 5311 1 0 14:07 ? 00:00:00 ./redis-server *:6379
root 5315 2184 0 14:07 pts/0 00:00:00 grep --color=auto redis
[root@izwz92bdx6sqk095sd98lez bin]# cd ../redis-3.0.0/src/
[root@izwz92bdx6sqk095sd98lez src]# ll *.rb
-rwxrwxr-x 1 root root 48141 Apr 1 2015 redis-trib.rb
[root@izwz92bdx6sqk095sd98lez src]#
//将该文件传到服务器:redis-3.0.0.gem
[root@izwz92bdx6sqk095sd98lez redis]# gem install redis-3.0.0.gem
Successfully installed redis-3.0.0
Parsing documentation for redis-3.0.0
Installing ri documentation for redis-3.0.0
1 gem installed
[root@izwz92bdx6sqk095sd98lez redis]#
//以上ruby 环境装好了。
//复制一份 redis install 后的 bin 文件夹。
//修改复制后文件夹中的 redis.conf , 修改端口为 6380 ,打开 cluster-enabled yes
//我是三台服务器,每一台上有一个主一个从,所以我要复制三分,修改三次。
//将我们redis-trib.rb复制出来好操作(不复制也行)。
[root@iz2ze9nu4bhzqni394evcsz redis]# ll
total 72
drwxr-xr-x 2 root root 4096 Mar 16 15:15 bin
drwxr-xr-x 2 root root 4096 Mar 16 15:16 bin-slave
drwxrwxr-x 6 root root 4096 Apr 1 2015 redis-3.0.0
-rw-r--r-- 1 root root 57856 Mar 16 14:35 redis-3.0.0.gem
[root@iz2ze9nu4bhzqni394evcsz redis]# cp redis-3.0.0/src/*.rb /agui/redis/
[root@iz2ze9nu4bhzqni394evcsz redis]# ll
total 120
drwxr-xr-x 2 root root 4096 Mar 16 15:15 bin
drwxr-xr-x 2 root root 4096 Mar 16 15:16 bin-slave
drwxrwxr-x 6 root root 4096 Apr 1 2015 redis-3.0.0
-rw-r--r-- 1 root root 57856 Mar 16 14:35 redis-3.0.0.gem
-rwxr-xr-x 1 root root 48141 Mar 16 15:21 redis-trib.rb
[root@iz2ze9nu4bhzqni394evcsz redis]#
//启动6个redis实例
// 开始创建集群:
// 说明: 如果集群带密码需要找到ruby 安装的 client.rb 文件,去设置密码
// [root@iZ2ze9nu4bhzqni394evcsZ redis]# find / -name "client.rb"
/usr/share/ruby/xmlrpc/client.rb
/usr/local/share/gems/gems/redis-3.0.0/lib/redis/client.rb
//[root@iZ2ze9nu4bhzqni394evcsZ redis]# vim 上面的路径,编辑 password= “43jnrwer34tr5d6”,保存即可。所有的都要改。
./redis-trib.rb create --replicas 1 192.168.25.153:7001 192.168.25.153:7002 192.168.25.153:7003 192.168.25.153:7004 192.168.25.153:7005 192.168.25.153:7006
[root@bogon redis-cluster]# ./redis-trib.rb create --replicas 1 192.168.25.153:7001 192.168.25.153:7002 192.168.25.153:7003 192.168.25.153:7004 192.168.25.153:7005 192.168.25.153:7006
>>> Creating cluster
Connecting to node 192.168.25.153:7001: OK
Connecting to node 192.168.25.153:7002: OK
Connecting to node 192.168.25.153:7003: OK
Connecting to node 192.168.25.153:7004: OK
Connecting to node 192.168.25.153:7005: OK
Connecting to node 192.168.25.153:7006: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.25.153:7001
192.168.25.153:7002
192.168.25.153:7003
Adding replica 192.168.25.153:7004 to 192.168.25.153:7001
Adding replica 192.168.25.153:7005 to 192.168.25.153:7002
Adding replica 192.168.25.153:7006 to 192.168.25.153:7003
M: 5a8523db7e12ca600dc82901ced06741b3010076 192.168.25.153:7001
slots:0-5460 (5461 slots) master
M: bf6f0929044db485dea9b565bb51e0c917d20a53 192.168.25.153:7002
slots:5461-10922 (5462 slots) master
M: c5e334dc4a53f655cb98fa3c3bdef8a808a693ca 192.168.25.153:7003
slots:10923-16383 (5461 slots) master
S: 2a61b87b49e5b1c84092918fa2467dd70fec115f 192.168.25.153:7004
replicates 5a8523db7e12ca600dc82901ced06741b3010076
S: 14848b8c813766387cfd77229bd2d1ffd6ac8d65 192.168.25.153:7005
replicates bf6f0929044db485dea9b565bb51e0c917d20a53
S: 3192cbe437fe67bbde9062f59d5a77dabcd0d632 192.168.25.153:7006
replicates c5e334dc4a53f655cb98fa3c3bdef8a808a693ca
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.....
// 坑说明 :
// redis集群创建执行
/*一直等待 Waiting for the cluster to join 很久都没有反应
/*原因:
/*redis集群不仅需要开通redis客户端连接的端口,而且需要开通集群总线端口
/*集群总线端口为redis客户端连接的端口 + 10000
/*如redis端口为6379
/*则集群总线端口为16379
/*故,所有服务器的点需要开通redis的客户端连接端口和集群总线端口
/*注意:iptables 放开,如果有安全组,也要放开这两个端口*/
>>> Performing Cluster Check (using node 192.168.25.153:7001)
M: 5a8523db7e12ca600dc82901ced06741b3010076 192.168.25.153:7001
slots:0-5460 (5461 slots) master
M: bf6f0929044db485dea9b565bb51e0c917d20a53 192.168.25.153:7002
slots:5461-10922 (5462 slots) master
M: c5e334dc4a53f655cb98fa3c3bdef8a808a693ca 192.168.25.153:7003
slots:10923-16383 (5461 slots) master
M: 2a61b87b49e5b1c84092918fa2467dd70fec115f 192.168.25.153:7004
slots: (0 slots) master
replicates 5a8523db7e12ca600dc82901ced06741b3010076
M: 14848b8c813766387cfd77229bd2d1ffd6ac8d65 192.168.25.153:7005
slots: (0 slots) master
replicates bf6f0929044db485dea9b565bb51e0c917d20a53
M: 3192cbe437fe67bbde9062f59d5a77dabcd0d632 192.168.25.153:7006
slots: (0 slots) master
replicates c5e334dc4a53f655cb98fa3c3bdef8a808a693ca
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@bogon redis-cluster]#
如上配置完毕,接下来测试:
// 说明,不加 -c set 值等会报错。注意这个坑。
[root@bogon redis-cluster]# ./redis-cli -h 192.168.25.153 -p 7002 -c
给集群设置密码 :
//说明 : 所有节点的配置文件redis.conf 中 的 # requirepass foobared 和 masterauth foobared 必须设置为一样。
//第二 修改 client.rb 中的密码 和 上面的密码一样 。 client.rb 是 gem install redis-3.0.0.gem 安装后的产物
[root@iZ2ze9nu4bhzqni394evcsZ bin]# find / -name "client.rb"
/usr/share/ruby/xmlrpc/client.rb
/usr/local/share/gems/gems/redis-3.0.0/lib/redis/client.rb
[root@iZ2ze9nu4bhzqni394evcsZ bin]# vim /usr/local/share/gems/gems/redis-3.0.0/lib/redis/client.rb
class Redis
class Client
DEFAULTS = {
:scheme => "redis",
:host => "127.0.0.1",
:port => 6379,
:path => nil,
:timeout => 5.0,
:password => "43jd6fd",
:db => 0,
}
......................省略。
修改如上密码 和 redis.conf 密码一致。从启 6个节点的服务即可。
测试 :
E:\redis>redis-cli.exe -h 39.134.231 -p 7001 -a 43jnrwed6fd -c
39.107.234.231:7001> set agui guige
-> Redirected to slot [15294] located at 120.79.246.84:7001
OK
120.79.246.84:7001> get agui
"guige"
120.79.246.84:7001> ^C
E:\redis>redis-cli.exe -h 39.107.234.231 -p 7001 -c
39.107.234.231:7001> set agui
(error) ERR wrong number of arguments for 'set' command
39.107.234.231:7001> get agui
(error) NOAUTH Authentication required.
39.107.234.231:7001> ^C
注意 : 客户端连接的时候,要加 -c ,否则无法对redis 集群操作。通过以上也可以看出,redis 设置密码成功。不通过密码连接会进行 身份的验证。