Single point installation
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
tar zxvf redis-4.0.1.tar.gz -C / usr / local
cd /usr/local/redis-4.0.2
make
make test
make PREFIX = / usr / local / redis install
cd / usr / local / redis
mkdir conf log data
cd / usr / local / redis / conf
cp /usr/local/redis-4.0.2/redis.conf.
Modify the kernel parameters:
echo ‘vm.overcommit_memory = 1’ >> /etc/sysctl.conf
sysctl -p
Modify the configuration file
Mainly modify the following values
daemonize no changed to daemonize yes to run in daemon mode
bind 127.0.0.0 changed to bind 0.0.0.0, listening on all ports of the machine
The following is a cluster node redis.conf configuration file
[[email protected] src] # cat /usr/local/redis-cluster-shijing2/redis/conf/7379.conf
bind 0.0.0.0
protected-mode yes
port 7379
requirepass [email protected]
masterauth [email protected]
maxmemory 4000000000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_7379.pid"
loglevel notice
logfile "../log/redis_7379.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "../data"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
cluster-enabled yes
cluster-config-file "7379.conf"
Cluster setup 1. Copy multiple copies of a single point of redis.conf
[[email protected] conf] # pwd
/ usr / local / redis-cluster-shijing2 / redis / conf
[[email protected] conf] # ll
total 28
-rw-r--r-- 1 root root 1362 May 31 16:52 7379.conf
-rw-r--r-- 1 root root 1362 May 31 16:52 7380.conf
-rw-r--r-- 1 root root 1362 May 31 16:53 7381.conf
-rw-r--r-- 1 root root 1362 May 31 16:53 7382.conf
-rw-r--r-- 1 root root 1362 May 31 16:53 7383.conf
-rw-r--r-- 1 root root 1362 May 31 16:53 7384.conf
Where configuration files need to be modified
The values that need to be changed are port pidfile cluster-config-file logfile, which can be changed in batches using the sed command.
The value to be added is cluster-enabled yes
Where dbfilename's file name and dir path can be unchanged
2.cluster initialization
Ruby environment installation
yum -y install gcc ruby ruby-devel rubygems rpm-build zlib
Ruby-redis interface installation (ruby version is too low can be installed using rvm)
gem install redis
Start each node and initialize the cluster
cd to redis / src, find the redis-trib.rb file, execute
redis-trib.rb create --replicas 1 host_ip: prot1 host_ip: port2
Example: ./redis-trib.rb create --replicas 1 10.110.122.196:7379 10.110.122.196:7380 10.110.122.196:7381 10.110.122.196:7382 10.110.122.196:7383 10.110.122.196:7384
Among them --replicas 1 indicates that there is a slave. In the above example, there are 6 instances in total, indicating 3 masters and 3 slaves.
After the execution, the cluster is basically completed;
3.redis-cluster add password
If a password is added to the redis instance, you need to modify the redis-trib.rb file
In the def connect (o = {}) function,
Change @r = Redis.new (: host => @info [: host],: port => @info [: port],: timeout => 60) to
@r = Redis.new (: host => @info [: host],: port => @info [: port],: timeout => 60,: password => "Fill in your redis password")
And then initialize
At the same time, the configuration file in a single instance needs to write the values of requirepass and masterauth in order to save the password permanently
As the following example
requirepass [email protected]
masterauth [email protected]
4. View cluster status
10.110.122.196:7379> CLUSTER info
cluster_state: ok
10.110.122.196:7379> CLUSTER NODES
735d1a01bd4a8cba0d37fab42d1764775cb91cfd 10.110.122.196:[email protected] master-0 1527762245102 3 connected 10923-16383
bfd7678b97b5bb627a34e71d09b67982ecce4a7b 10.110.122.196:[email protected] slave 735d1a01bd4a8cba0d37fab42d1764775cb91cfd 0 1527762247108 6 connected
5. Nodes meet each other
Use meet IP PORT in redis-cli to shake hands with other nodes
redis optimization
password setting
10.110.122.196:7379> config set requirepass [email protected]
Maximum memory setting, it is recommended to set, otherwise it will take up the system's maximum memory
10.110.122.196:7379> CONFIG SET maxmemory 4G
It needs to be set on each node. The maximum memory size of the cluster is the sum of the maximum memory of the master.
After setting, use info to view the maximum memory value
You can also use config get maxmemory
When the above two need to be persisted, they must be written into the configuration file
Corresponds to the instance password write. When the cluster is initialized, you can directly initialize it without specifying it, and then use config set masterauth "[email protected]" and config set requirepass "[email protected]" to specify two in redis-cli. Values, which are saved at the same time using config rewrite, these two values need to be set on all cluster instances
Redis single node installation and cluster installation