[lemcoden@hadoop01 utils](install_server.sh 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 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] Selected default - /var/log/redis_6380.log Please select the data directory for this instance [/var/lib/redis/6380] Selected default - /var/lib/redis/6380 Please select the redis executable path [](redis-server Selected config: Port : 6380 Config file : /etc/redis/6380.conf Log file : /var/log/redis_6380.log Data dir : /var/lib/redis/6380 Executable : /opt/bigdata/module/redis5/bin/redis-server Cli Executable : /opt/bigdata/module/redis5/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!
拷贝配置文件到测试目录
1 2 3 4 5 6 7
[lemcoden@hadoop01 test]( [lemcoden@hadoop01 test]$ ls 6379.conf 6380.conf 6381.conf [lemcoden@hadoop01 test]$ vim 6379.conf daemonize no #logfile /var/lib/redis/6379.log appendonly no
127.0.0.1:6379> set k3 aaa OK 127.0.0.1:6379> set k4 444 OK 127.0.0.1:6379> set k2 4123313 OK 127.0.0.1:6379> set k5 141jddpfipj OK 127.0.0.1:6379> set k6 sada OK
[lemcoden@hadoop01 ~]$ redis-cli -p 6379 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:22121> MULTI Error: Server closed the connection
[lemcoden@hadoop01 create-cluster]$ vim create-cluster [lemcoden@hadoop01 create-cluster](create-cluster start Starting 30001 Starting 30002 Starting 30003 Starting 30004 Starting 30005 Starting 30006 [lemcoden@hadoop01 create-cluster](create-cluster create >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 127.0.0.1:30005 to 127.0.0.1:30001 Adding replica 127.0.0.1:30006 to 127.0.0.1:30002 Adding replica 127.0.0.1:30004 to 127.0.0.1:30003 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: a403574ce40177866a188d16a615848bd5b5459a 127.0.0.1:30001 slots:[0-5460] (5461 slots) master M: 638ac8a174e8a66b1e46bb19155860a5c3aa415b 127.0.0.1:30002 slots:[5461-10922] (5462 slots) master M: 6a2c3dd007e7d44c95c51d33002e9cc0fdc429ba 127.0.0.1:30003 slots:[10923-16383] (5461 slots) master S: 69313ced470329f55a5bdf408e4285f345a24154 127.0.0.1:30004 replicates 6a2c3dd007e7d44c95c51d33002e9cc0fdc429ba S: 967818092ca216fe22a90160587fbdbfc23dd70b 127.0.0.1:30005 replicates a403574ce40177866a188d16a615848bd5b5459a S: 00e70c8bebff2e59e89ed3e1e152d6805ad36eff 127.0.0.1:30006 replicates 638ac8a174e8a66b1e46bb19155860a5c3aa415b Can I set the above configuration? (type 'yes' to accept): >>> 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 127.0.0.1:30001) M: a403574ce40177866a188d16a615848bd5b5459a 127.0.0.1:30001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 967818092ca216fe22a90160587fbdbfc23dd70b 127.0.0.1:30005 slots: (0 slots) slave replicates a403574ce40177866a188d16a615848bd5b5459a S: 00e70c8bebff2e59e89ed3e1e152d6805ad36eff 127.0.0.1:30006 slots: (0 slots) slave replicates 638ac8a174e8a66b1e46bb19155860a5c3aa415b S: 69313ced470329f55a5bdf408e4285f345a24154 127.0.0.1:30004 slots: (0 slots) slave replicates 6a2c3dd007e7d44c95c51d33002e9cc0fdc429ba M: 638ac8a174e8a66b1e46bb19155860a5c3aa415b 127.0.0.1:30002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) M: 6a2c3dd007e7d44c95c51d33002e9cc0fdc429ba 127.0.0.1:30003 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.
客户端 [lemcoden@hadoop01 create-cluster]$ redis-cli -p 30001 127.0.0.1:30001> set k1 sdfsdf (error) MOVED 12706 127.0.0.1:30003 127.0.0.1:30001> [lemcoden@hadoop01 create-cluster]$ redis-cli -p 30001 127.0.0.1:30001> set k1 sdfsdf (error) MOVED 12706 127.0.0.1:30003 127.0.0.1:30001> [lemcoden@hadoop01 create-cluster]$ redis-cli -c -p 30001 (cluster集群模式) 127.0.0.1:30001> set k1 sdfsdf -> Redirected to slot [12706] located at 127.0.0.1:30003 OK 127.0.0.1:30003> get k1 "sdfsdf" 127.0.0.1:30003> set k2 sdfsdsf -> Redirected to slot [449] located at 127.0.0.1:30001 OK 127.0.0.1:30001> get k2 "sdfsdsf" 127.0.0.1:30001> get k1 -> Redirected to slot [12706] located at 127.0.0.1:30003 "sdfsdf" 127.0.0.1:30003> WATCH k2 -> Redirected to slot [449] located at 127.0.0.1:30001 OK 127.0.0.1:30001> MULTI OK 127.0.0.1:30001> set k1 232323456 -> Redirected to slot [12706] located at 127.0.0.1:30003 OK 127.0.0.1:30003> set sdfsdf sdfsdf OK 127.0.0.1:30003> exec (error) ERR EXEC without MULTI (事务中重定向不同的进程的命令会失败)
127.0.0.1:30003> set {oo}k1 sdfsdf -> Redirected to slot [1629] located at 127.0.0.1:30001 OK 127.0.0.1:30001> set {oo}k2 sdfsdf OK 127.0.0.1:30001> set {oo}k3 sdfsdf OK 127.0.0.1:30001> WATCH {oo}k1 OK 127.0.0.1:30001> MULTI OK 127.0.0.1:30001> set {oo}k2 234234 QUEUED 127.0.0.1:30001> get {oo}k3 QUEUED 127.0.0.1:30001> exec 1) OK 2) "sdfsdf" (可以在事务中给key添加相同的前缀)
[lemcoden@hadoop01 create-cluster]$ redis-cli --cluster reshard 127.0.0.1:30001 >>> Performing Cluster Check (using node 127.0.0.1:30001) M: 8271c8dcb899de726fe6c6ffe0ebcdb9a494eb0a 127.0.0.1:30001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: c41870d1a555d7674b8a13f2e52cfd926113fd1e 127.0.0.1:30004 slots: (0 slots) slave replicates 0d0f70ad6b408f7c56897450eb605aa9e95e10ab M: 0d0f70ad6b408f7c56897450eb605aa9e95e10ab 127.0.0.1:30002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) M: 55c02c59f51913c654087fbf0ab2e8ee2464d017 127.0.0.1:30003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: 8ccf40a81064e64afb56999dbd931636e7b49519 127.0.0.1:30005 slots: (0 slots) slave replicates 55c02c59f51913c654087fbf0ab2e8ee2464d017 S: 85aa8ac690ba144599e7fb47b733d22dc365c036 127.0.0.1:30006 slots: (0 slots) slave replicates 8271c8dcb899de726fe6c6ffe0ebcdb9a494eb0a [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. How many slots do you want to move (from 1 to 16384)? 2000 What is the receiving node ID? 0d0f70ad6b408f7c56897450eb605aa9e95e10ab 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: 8271c8dcb899de726fe6c6ffe0ebcdb9a494eb0a Source node #2: done