wget http://download.redis.io/releases/redis-3.0.4.tar.gz #下载软件 yum install -y gcc-c++ #安装gcc-c++依赖,初始最小化系统未安装,需安装 tar zxvf redis-3.0.4.tar.gz cd redis-3.0.4 make PREFIX=/usr/local/redis6379 install #一台服务器安装两个redis,所以命名以端口区分 make PREFIX=/usr/local/redis6380 install
[root@redis01 redis-3.0.4]# cd utils/ [root@redis01 utils]# sh install_server.sh ##redis6379的初始化配置 Welcome to the redis service installer This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] #默认6379端口,不需要修改,直接回车即可 Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] #默认,直接回车即可 Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] /data/weblogs/redis/redis_6379.log #修改redis6379的日志路径 Please select the data directory for this instance [/var/lib/redis/6379] /data/redis/6379 #修改redis6379实例数据位置 Please select the redis executable path [] /usr/local/redis6379/bin/redis-server #redis6379的执行文件目录 Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /data/weblogs/redis/redis_6379.log Data dir : /data/redis/6379 Executable : /usr/local/redis6379/bin/redis-server Cli Executable : /usr/local/redis6379/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!
[root@redis01 utils]# sh install_server.sh ##redis6380的初始化配置 Welcome to the redis service installer This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] 6380 ##配置redis6380的端口为6380 Please select the redis config file name [/etc/redis/6380.conf] #配置文件路径,直接回车即可 Selected default - /etc/redis/6380.conf Please select the redis log file name [/var/log/redis_6380.log] /data/weblogs/redis/redis_6380.log #修改redis6380的日志路径 Please select the data directory for this instance [/var/lib/redis/6380] /data/redis/6380 #修改redis6380实例数据位置 Please select the redis executable path [] /usr/local/redis6380/bin/redis-server #redis6380的执行文件目录 Selected config: Port : 6380 Config file : /etc/redis/6380.conf Log file : /data/weblogs/redis/redis_6380.log Data dir : /data/redis/6380 Executable : /usr/local/redis6380/bin/redis-server Cli Executable : /usr/local/redis6380/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6380.conf => /etc/init.d/redis_6380 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!
开启redis持久化
1.修改redis配置文件
1 2
sed -i 's/appendonly no/appendonly yes/g' /etc/redis/6379.conf sed -i 's/appendonly no/appendonly yes/g' /etc/redis/6380.conf
2.重启生效
1 2 3 4 5 6 7 8 9 10
#重启服务 service redis_6379 restart service redis_6380 restart
#查看是否有持久化文件 ls /data/redis/6379/ appendonly.aof dump.rdb
ls /data/redis/6380/ appendonly.aof dump.rdb
集群配置
以redis01为例,另外两台操作相同
开启redis集群相关配置项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#修改redis6379 [root@redis01 ~]# sed -i 's/# cluster-enabled yes/cluster-enabled yes/g' /etc/redis/6379.conf [root@redis01 ~]# sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes-6379.conf/g' /etc/redis/6379.conf [root@redis01 ~]# sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' /etc/redis/6379.conf
#修改redis6380 [root@redis01 ~]# sed -i 's/# cluster-enabled yes/cluster-enabled yes/g' /etc/redis/6380.conf [root@redis01 ~]# sed -i 's/# cluster-config-file nodes-6379.conf/cluster-config-file nodes-6380.conf/g' /etc/redis/6380.conf [root@redis01 ~]# sed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 5000/g' /etc/redis/6380.conf
./src/redis-trib.rb del-node 192.168.122.112:6380 c67e2adf957cb6f123103c677fb998135ca61a5b #删除192.168.122.112:6380这个从节点 >>> Removing node c67e2adf957cb6f123103c677fb998135ca61a5b from cluster 192.168.122.112:6380 Connecting to node 192.168.122.112:6380: OK Connecting to node 192.168.122.217:6380: OK Connecting to node 192.168.122.217:6379: OK Connecting to node 192.168.122.132:6379: OK Connecting to node 192.168.122.112:6379: OK Connecting to node 192.168.122.132:6380: OK >>> Sending CLUSTER FORGET messages to the cluster... >>> SHUTDOWN the node.
2.删除主节点
主节点的删除分三步
1.首先需要删除对应主节点的从节点,参考删除从节点
2.移除主节点上的数据槽(分配的slot)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
./src/redis-trib.rb reshard 192.168.122.217:6379 ... #省略号表示省略无关内容 How many slots do you want to move (from 1 to 16384)? 16384 #被移除的数据槽,可根据cluster nodes 查看 ... What is the receiving node ID? 28cca88d789477a1bae4abfbe20c187bb54583cf #接收被删除节点数据的主节点 ... Source node #1:6343d46d255182e0e116dfad536028702e776251 #被删除主节点的node-id Source node #2:done #结束标志,开始执行 ... Do you want to proceed with the proposed reshard plan (yes/no)? yes #删除要被删除节点的slot后,重新分配 [root@redis01 redis-3.0.4]# /usr/local/redis6379/bin/redis-cli -c -p 6379 cluster nodes #查看节点信息 28cca88d789477a1bae4abfbe20c187bb54583cf 192.168.122.217:6380 master - 0 1478593786321 7 connected 0-10922 6343d46d255182e0e116dfad536028702e776251 192.168.122.217:6379 myself,master - 0 0 1 connected #此时要被删除的主节点的slot信息没有了 c18bae19c335c2bfad4c4628d562bd937bd608ec 192.168.122.112:6379 slave 28cca88d789477a1bae4abfbe20c187bb54583cf 0 1478593786823 7 connected 3bde122a2d531d562f932657a67ae0461479cbd1 192.168.122.132:6379 master - 0 1478593785820 3 connected 10923-16383 5f25c4e5e0891530e54570f51cf9de8015c08d9e 192.168.122.132:6380 slave 3bde122a2d531d562f932657a67ae0461479cbd1 0 1478593787322 4 connected
[root@redis01 redis-3.0.4]# ./src/redis-trib.rb reshard 192.168.122.217:6379 Connecting to node 192.168.122.217:6379: OK Connecting to node 192.168.122.217:6380: OK Connecting to node 192.168.122.112:6379: OK Connecting to node 192.168.122.132:6380: OK Connecting to node 192.168.122.132:6379: OK >>> Performing Cluster Check (using node 192.168.122.217:6379) ...... #s省略号表示省略无关信息 >>> Check slots coverage... [OK] All 16384 slots covered. How many slots do you want to move (from 1 to 16384)? 5600 #设置solt,设置每个节点的solt区间范围 What is the receiving node ID? e0fab3c8d591f84535c46841c16c9c287c6d73e2 #此处填新添加的节点的nodeID Please enter all the source node IDs. Type 'all' to use all the nodes as source nodes for the hash slots. Type 'done' once you entered all the source nodes IDs. Source node #1:all #表示全部重新分配 .... Do you want to proceed with the proposed reshard plan (yes/no)? yes #确认重启分配