标签:sed lazy ace 端口 normal 其它 单节点 执行 tag
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 .
修改内核参数:
echo ‘vm.overcommit_memory = 1‘ >> /etc/sysctl.conf
sysctl -p
修改配置文件
主要修改以下值
daemonize no改为daemonize yes,以守护进程模式运行
bind 127.0.0.0改为bind 0.0.0.0,监听本机所有端口
以下为一个cluster node redis.conf配置文件
[root@10-110-122-196 src]# cat /usr/local/redis-cluster-shijing2/redis/conf/7379.conf
bind 0.0.0.0
protected-mode yes
port 7379
requirepass bigdata1234@le.com
masterauth bigdata1234@le.com
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"
[root@10-110-122-196 conf]# pwd
/usr/local/redis-cluster-shijing2/redis/conf
[root@10-110-122-196 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
配置文件需要修改的地方
需要更改的值有port pidfile cluster-config-file logfile
,使用sed命令进行批量统一更改即可
需要加入的值为 cluster-enabled yes
其中dbfilename的文件名和dir路径可以不变
ruby环境安装
yum -y install gcc ruby ruby-devel rubygems rpm-build zlib
ruby-redis接口安装(ruby版本太低可以使用rvm安装)
gem install redis
启动各节点,初始化集群
cd到 redis/src中,找到redis-trib.rb文件,执行
redis-trib.rb create --replicas 1 host_ip:prot1 host_ip:port2
例:./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
其中--replicas 1表示有一个slave,以上例子中共6个实例,表示3主3从
执行到这里之后基本就完成了集群的搭建;
如果redis实例添加了密码,则需要修改redis-trib.rb文件
在def connect(o={})
这个函数中,
将@r = Redis.new(:host => @info[:host], :port => @info[:port], :timeout => 60)
改成
@r = Redis.new(:host => @info[:host], :port => @info[:port], :timeout => 60, :password => "填入你的redis密码")
然后再在初始化
同时单个实例中的配置文件需要写入requirepass
和masterauth
的值,以便密码永久保存
如下例
requirepass bigdata1234@le.com
masterauth bigdata1234@le.com
10.110.122.196:7379> CLUSTER info
cluster_state:ok
10.110.122.196:7379> CLUSTER NODES
735d1a01bd4a8cba0d37fab42d1764775cb91cfd 10.110.122.196:7381@17381 master - 0 1527762245102 3 connected 10923-16383
bfd7678b97b5bb627a34e71d09b67982ecce4a7b 10.110.122.196:7384@17384 slave 735d1a01bd4a8cba0d37fab42d1764775cb91cfd 0 1527762247108 6 connected
在redis-cli 中 使用 meet IP PORT
即可与其它节点握手
10.110.122.196:7379> config set requirepass Bigdata4321@le.com
10.110.122.196:7379> CONFIG SET maxmemory 4G
每个节点上面都需要设置,集群最大内存大小为master最大内存总和
设置之后,使用info可以查看到最大内存值
也可以使用config get maxmemory
以上两者需要持久化保持时,必须写入配置文件中
config set masterauth "bigdata1234@le.com"
和config set requirepass "bigdata1234@le.com"
指定两个值,同时在使用config rewrite
保存,这两个值需要在所有集群实例上进行设定标签:sed lazy ace 端口 normal 其它 单节点 执行 tag
原文地址:https://www.cnblogs.com/marility/p/9816649.html