您的位置:首页 > 数据库 > Redis

redis3.2.6 集群安装

2017-03-16 20:01 176 查看
下载

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://download.redis.io/releases/redis-3.2.6.tar.gz
编译安装

[root@localhost src]# tar zxvf redis-3.2.6.tar.gz -C /usr/local/soft/
[root@localhost src]# cd /usr/local/soft/
[root@localhost soft]# cd redis-3.2.6/
[root@localhost redis-3.2.6]# make && make install
[root@localhost redis-3.2.6]# cd /usr/local/soft/
[root@localhost soft]# mkdir redis_cluster
[root@localhost soft]# cd redis_cluster/
[root@localhost redis_cluster]# mkdir 7000 7001 7002
[root@localhost redis_cluster]# cp /usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/7000
[root@localhost redis_cluster]# cp /usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/7001
[root@localhost redis_cluster]# cp /usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/7002

修改配置文件

daemonize yes //redis后台运行

pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7002,7003

port 7000 //端口7000,7002,7003

cluster-enabled yes //开启集群 把注释#去掉

cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002

cluster-node-timeout 5000 //请求超时 设置5秒够了
appendonly yes
bind 真实ip地址

关闭安全模式

redis-cli -p 7000 CONFIG SET protected-mode no

启动redis

[root@localhost redis_cluster]# redis-server /usr/local/soft/redis_cluster/7000/redis.conf
[root@localhost redis_cluster]# redis-server /usr/local/soft/redis_cluster/7001/redis.conf
[root@localhost redis_cluster]# redis-server /usr/local/soft/redis_cluster/7002/redis.conf
[root@localhost redis_cluster]# ps -ef | grep redis
root 5842 1 0 19:41 ? 00:00:00 redis-server 127.0.0.1:7000 [cluster]
root 5862 1 0 19:42 ? 00:00:00 redis-server 127.0.0.1:7001 [cluster]
root 5866 1 0 19:42 ? 00:00:00 redis-server 127.0.0.1:7002 [cluster]
root 5871 2583 0 19:42 pts/0 00:00:00 grep redis
[root@localhost redis_cluster]# netstat -tnpl | grep redis
tcp 0 0 127.0.0.1:17000 0.0.0.0:* LISTEN 5842/redis-server 1
tcp 0 0 127.0.0.1:17001 0.0.0.0:* LISTEN 5862/redis-server 1
tcp 0 0 127.0.0.1:17002 0.0.0.0:* LISTEN 5866/redis-server 1
tcp 0 0 127.0.0.1:7000 0.0.0.0:* LISTEN 5842/redis-server 1
tcp 0 0 127.0.0.1:7001 0.0.0.0:* LISTEN 5862/redis-server 1
tcp 0 0 127.0.0.1:7002 0.0.0.0:* LISTEN 5866/redis-server 1

创建集群

[root@localhost redis_cluster]# cd /usr/local/soft/redis-3.2.6/src/
[root@localhost src]# ./redis-trib.rb
/usr/bin/env: ruby: No such file or directory

如果没有安装ruby,则安装

[root@localhost src]# yum -y install ruby ruby-devel rubygems rpm-build

安装redis接口

[root@localhost src]# gem install redis

查看ruby是否安装成功

[root@localhost src]# ./redis-trib.rb
Usage: redis-trib <command> <options> <arguments ...>

rebalance host:port
--threshold <arg>
--simulate
--weight <arg>
--timeout <arg>
--auto-weights
--pipeline <arg>
--use-empty-masters
info host:port
check host:port
fix host:port
--timeout <arg>
add-node new_host:new_port existing_host:existing_port
--master-id <arg>
--slave
import host:port
--replace
--copy
--from <arg>
reshard host:port
--to <arg>
--from <arg>
--yes
--timeout <arg>
--slots <arg>
--pipeline <arg>
help (show this help)
call host:port command arg arg .. arg
set-timeout host:port milliseconds
del-node host:port node_id
create host1:port1 ... hostN:portN
--replicas <arg>

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

创建集群

[root@localhost src]# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
>>> Creating cluster
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 3 nodes and 1 replicas per node.
*** At least 6 nodes are required.

新开一台机子, 配置如上, 端口号为 7003 7004 7005

开放端口号 7000 7001 7002 7003 7004 7005 17000 17001 17002 17003 17004 17005

再次创建集群

[root@localhost redis_cluster]# /usr/local/soft/redis-3.2.6/src/redis-trib.rb create --replicas 1 192.168.59.128:7000 192.168.59.128:7001 192.168.59.128:7002 192.168.59.129:7003 192.168.59.129:7004 192.168.59.129:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.59.129:7003
192.168.59.128:7000
192.168.59.129:7004
Adding replica 192.168.59.128:7001 to 192.168.59.129:7003
Adding replica 192.168.59.129:7005 to 192.168.59.128:7000
Adding replica 192.168.59.128:7002 to 192.168.59.129:7004
M: bbf1f1150a661ec3adee9ecb37ab140c03290582 192.168.59.128:7000
slots:5461-10922 (5462 slots) master
S: 046219f4f154a5a757877cd1dc0f186423942424 192.168.59.128:7001
replicates ccd1c5d708b1844881c13ac4c6ac467574ff23f7
S: f5e01feb8dd6f085c3b25c35f25753f6b2fa750b 192.168.59.128:7002
replicates c7af24dcbe0ea6c26aec9965573c82130e98718a
M: ccd1c5d708b1844881c13ac4c6ac467574ff23f7 192.168.59.129:7003
slots:0-5460 (5461 slots) master
M: c7af24dcbe0ea6c26aec9965573c82130e98718a 192.168.59.129:7004
slots:10923-16383 (5461 slots) master
S: 0b9385e4fb3a939414891a00585f65c2fa07c29b 192.168.59.129:7005
replicates bbf1f1150a661ec3adee9ecb37ab140c03290582
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.59.128:7000)
M: bbf1f1150a661ec3adee9ecb37ab140c03290582 192.168.59.128:7000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 046219f4f154a5a757877cd1dc0f186423942424 192.168.59.128:7001
slots: (0 slots) slave
replicates ccd1c5d708b1844881c13ac4c6ac467574ff23f7
S: 0b9385e4fb3a939414891a00585f65c2fa07c29b 192.168.59.129:7005
slots: (0 slots) slave
replicates bbf1f1150a661ec3adee9ecb37ab140c03290582
M: ccd1c5d708b1844881c13ac4c6ac467574ff23f7 192.168.59.129:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: f5e01feb8dd6f085c3b25c35f25753f6b2fa750b 192.168.59.128:7002
slots: (0 slots) slave
replicates c7af24dcbe0ea6c26aec9965573c82130e98718a
M: c7af24dcbe0ea6c26aec9965573c82130e98718a 192.168.59.129:7004
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

下载

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://download.redis.io/releases/redis-3.2.6.tar.gz
编译安装

[root@localhost src]# tar zxvf redis-3.2.6.tar.gz -C /usr/local/soft/
[root@localhost src]# cd /usr/local/soft/
[root@localhost soft]# cd redis-3.2.6/
[root@localhost redis-3.2.6]# make && make install
[root@localhost redis-3.2.6]# cd /usr/local/soft/
[root@localhost soft]# mkdir redis_cluster
[root@localhost soft]# cd redis_cluster/
[root@localhost redis_cluster]# mkdir 7000 7001 7002
[root@localhost redis_cluster]# cp /usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/7000
[root@localhost redis_cluster]# cp /usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/7001
[root@localhost redis_cluster]# cp /usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/7002

修改配置文件

daemonize yes //redis后台运行

pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7002,7003

port 7000 //端口7000,7002,7003

cluster-enabled yes //开启集群 把注释#去掉

cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002

cluster-node-timeout 5000 //请求超时 设置5秒够了
appendonly yes
bind 真实ip地址

关闭安全模式

redis-cli -p 7000 CONFIG SET protected-mode no

启动redis

[root@localhost redis_cluster]# redis-server /usr/local/soft/redis_cluster/7000/redis.conf
[root@localhost redis_cluster]# redis-server /usr/local/soft/redis_cluster/7001/redis.conf
[root@localhost redis_cluster]# redis-server /usr/local/soft/redis_cluster/7002/redis.conf
[root@localhost redis_cluster]# ps -ef | grep redis
root 5842 1 0 19:41 ? 00:00:00 redis-server 127.0.0.1:7000 [cluster]
root 5862 1 0 19:42 ? 00:00:00 redis-server 127.0.0.1:7001 [cluster]
root 5866 1 0 19:42 ? 00:00:00 redis-server 127.0.0.1:7002 [cluster]
root 5871 2583 0 19:42 pts/0 00:00:00 grep redis
[root@localhost redis_cluster]# netstat -tnpl | grep redis
tcp 0 0 127.0.0.1:17000 0.0.0.0:* LISTEN 5842/redis-server 1
tcp 0 0 127.0.0.1:17001 0.0.0.0:* LISTEN 5862/redis-server 1
tcp 0 0 127.0.0.1:17002 0.0.0.0:* LISTEN 5866/redis-server 1
tcp 0 0 127.0.0.1:7000 0.0.0.0:* LISTEN 5842/redis-server 1
tcp 0 0 127.0.0.1:7001 0.0.0.0:* LISTEN 5862/redis-server 1
tcp 0 0 127.0.0.1:7002 0.0.0.0:* LISTEN 5866/redis-server 1

创建集群

[root@localhost redis_cluster]# cd /usr/local/soft/redis-3.2.6/src/
[root@localhost src]# ./redis-trib.rb
/usr/bin/env: ruby: No such file or directory

如果没有安装ruby,则安装

[root@localhost src]# yum -y install ruby ruby-devel rubygems rpm-build

安装redis接口

[root@localhost src]# gem install redis

查看ruby是否安装成功

[root@localhost src]# ./redis-trib.rb
Usage: redis-trib <command> <options> <arguments ...>

rebalance host:port
--threshold <arg>
--simulate
--weight <arg>
--timeout <arg>
--auto-weights
--pipeline <arg>
--use-empty-masters
info host:port
check host:port
fix host:port
--timeout <arg>
add-node new_host:new_port existing_host:existing_port
--master-id <arg>
--slave
import host:port
--replace
--copy
--from <arg>
reshard host:port
--to <arg>
--from <arg>
--yes
--timeout <arg>
--slots <arg>
--pipeline <arg>
help (show this help)
call host:port command arg arg .. arg
set-timeout host:port milliseconds
del-node host:port node_id
create host1:port1 ... hostN:portN
--replicas <arg>

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

创建集群

[root@localhost src]# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
>>> Creating cluster
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 3 nodes and 1 replicas per node.
*** At least 6 nodes are required.

新开一台机子, 配置如上, 端口号为 7003 7004 7005

开放端口号 7000 7001 7002 7003 7004 7005 17000 17001 17002 17003 17004 17005

再次创建集群

[root@localhost redis_cluster]# /usr/local/soft/redis-3.2.6/src/redis-trib.rb create --replicas 1 192.168.59.128:7000 192.168.59.128:7001 192.168.59.128:7002 192.168.59.129:7003 192.168.59.129:7004 192.168.59.129:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.59.129:7003
192.168.59.128:7000
192.168.59.129:7004
Adding replica 192.168.59.128:7001 to 192.168.59.129:7003
Adding replica 192.168.59.129:7005 to 192.168.59.128:7000
Adding replica 192.168.59.128:7002 to 192.168.59.129:7004
M: bbf1f1150a661ec3adee9ecb37ab140c03290582 192.168.59.128:7000
slots:5461-10922 (5462 slots) master
S: 046219f4f154a5a757877cd1dc0f186423942424 192.168.59.128:7001
replicates ccd1c5d708b1844881c13ac4c6ac467574ff23f7
S: f5e01feb8dd6f085c3b25c35f25753f6b2fa750b 192.168.59.128:7002
replicates c7af24dcbe0ea6c26aec9965573c82130e98718a
M: ccd1c5d708b1844881c13ac4c6ac467574ff23f7 192.168.59.129:7003
slots:0-5460 (5461 slots) master
M: c7af24dcbe0ea6c26aec9965573c82130e98718a 192.168.59.129:7004
slots:10923-16383 (5461 slots) master
S: 0b9385e4fb3a939414891a00585f65c2fa07c29b 192.168.59.129:7005
replicates bbf1f1150a661ec3adee9ecb37ab140c03290582
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.59.128:7000)
M: bbf1f1150a661ec3adee9ecb37ab140c03290582 192.168.59.128:7000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 046219f4f154a5a757877cd1dc0f186423942424 192.168.59.128:7001
slots: (0 slots) slave
replicates ccd1c5d708b1844881c13ac4c6ac467574ff23f7
S: 0b9385e4fb3a939414891a00585f65c2fa07c29b 192.168.59.129:7005
slots: (0 slots) slave
replicates bbf1f1150a661ec3adee9ecb37ab140c03290582
M: ccd1c5d708b1844881c13ac4c6ac467574ff23f7 192.168.59.129:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: f5e01feb8dd6f085c3b25c35f25753f6b2fa750b 192.168.59.128:7002
slots: (0 slots) slave
replicates c7af24dcbe0ea6c26aec9965573c82130e98718a
M: c7af24dcbe0ea6c26aec9965573c82130e98718a 192.168.59.129:7004
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: