redis cluster搭建

1、安装redis

yum -y install gcc

cd /usr/local/
tar xzvf /root/redis-4.0.8.tar.gz
mv redis-4.0.8/ redis
cd redis
make
cd src
make install PREFIX=/usr/local/redis
cp redis-trib.rb /bin/
cd /usr/local/redis/bin/
cp redis-server /bin/
cp redis-cli /bin/

2、安装ruby依赖

yum install ruby rubygems –y
[root@i-1s2os7sd src]# gem install redis

ERROR: Error installing redis:
redis requires Ruby version >= 2.2.2.
[root@i-1q2oh7sd src]# gem install redis --version 3.0.0
3、本机下载安装gem-redis
下载:https://rubygems.org/gems/redis/versions/3.2.2

mv redis-3.2.2.gem /opt/
gem install -l /opt/redis-3.2.2.gem

4、内核调优

cat >> /etc/sysctl.conf<

cat >>/etc/security/limits.conf<<EOF2

  • soft nproc 65535
  • hard nproc 65535
  • soft nofile 65535
  • hard nofile 65535
    EOF2
    sysctl -p
    cat /etc/sysctl.conf
    cat /etc/security/limits.conf

5、建立目录

mkdir /data/redis-cluster/log -p
mkdir /data/redis-cluster/conf -p
mkdir /data/redis-cluster/rdb -p
mkdir /data/redis-cluster/run -p

6、撰写redis配置文件(cp配置文件注意修改端口)(三台机器相同)
vi /data/redis-cluster/conf/redis_6300.conf

bind 0.0.0.0
daemonize yes
pidfile /data/redis-cluster/run/redis-6300.pid
port 6300
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
maxmemory 10gb    #5/8
logfile "/data/redis-cluster/log/redis-6300.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-6300.rdb
dir /data/redis-cluster/rdb
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
appendonly yes
appendfilename "redis-6300.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-6300.conf
cluster-node-timeout 15000
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-entries 512
list-max-ziplist-value 64
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

vi /data/redis-cluster/conf/redis_6301.conf

bind 0.0.0.0
daemonize yes
pidfile /data/redis-cluster/run/redis-6301.pid
port 6301
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile "/data/redis-cluster/log/redis-6301.log"
databases 16
save 900 1
save 300 10
save 60 10000
maxmemory 10gb    #5/8
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-6301.rdb
dir /data/redis-cluster/rdb
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
appendonly yes
appendfilename "redis-6301.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-6301.conf
cluster-node-timeout 15000
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-entries 512
list-max-ziplist-value 64
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

7、启动服务
redis-server /data/redis-cluster/conf/redis_6300.conf
redis-server /data/redis-cluster/conf/redis_6301.conf
echo “redis-server /data/redis-cluster/conf/redis_6300.conf” >> /etc/rc.local
echo “redis-server /data/redis-cluster/conf/redis_6301.conf” >> /etc/rc.local

8、初始化集群

#节点角色由顺序决定,先master之后是slave,本文中6300是master,6301是slave

/redis-trib.rb create --replicas 1 10.15.35.24:6300 10.15.35.24:6301 10.15.35.25:6300 10.15.35.25:6301 10.15.35.26:6300 10.15.35.26:6301

redis-trib.rb create --replicas 1 10.15.45.32:6300 10.15.45.32:6301 10.15.45.32:6302 10.15.45.32:6303 10.15.45.32:6304 10.15.45.32:6305

使用create命令 --replicas 1 参数表示为每个主节点创建一个从节点,其他参数是实例的地址集合。

9.开启认证(6个节点都做)
[root@i-6vnbqlew src]# redis-cli -p 6300
127.0.0.1:6300> config set masterauth “mypassword”
OK
127.0.0.1:6300> config set requirepass “mypassword”
OK
127.0.0.1:6300> exit

config set masterauth “mypassword”
config set requirepass “mypassword”
127.0.0.1:6300> exit

[root@i-6vnbqlew src]# redis-cli -p 6300 -a mypassword
127.0.0.1:6300> config rewrite

10.连接
●redis-cli -c -p 6300 -a mypassword --连接整 个集群
● redis-cli -p 6300 -a mypassword --连接单个节点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值