Linux builds Redis cluster __linux

Source: Internet
Author: User
Tags allkeys redis volatile redis cluster

First, the preparation of more than one Linux machine, the normal production environment in accordance with the deployment of Redis cluster is required 3 machines, 1 s machine dual-node (master node, from node), 3 machines 6 nodes cluster. Redis Cluster official has given a standard that must be 6 nodes above the cluster. (Of course I can learn to build one, but to set 6 nodes)

Second, prepare the required installation kits and other tools:

Baidu Network disk: Https://pan.baidu.com/s/1RQhrdnMXHU-yGc6Izz7xoA Password: SFZN

Inside is the Linux edition Redis installs the package, constructs the cluster needs the plug-in Redis-3.3.3.gem, a visual client

Third, the preparation of environmental installation:

1. Decompression Redis installation package: TAR-ZXVF redis-3.2.8.tar.gz

2.cd into the redis-3.2.8 folder (if you are unfamiliar with Linux commands, you can see my previous blog Learning: Linux Command Encyclopedia)

3.make (compilation environment)

4.cd into/opt/redis-3.2.8/src/execution: make install Prefix=/opt/redis

Note: If intermediate compile error, it is your machine does not install C + + What kind of compilation environment because Redis is the C language development needs these environment support, the machine can connect the external network can direct source command Download press: Yum Install gcc-c++

Can not connect the external network is very, very, very troublesome, you need to go to the Internet to download a package, one by one installation and can not appear in the middle of a mistake.

The steps above are common steps for 3 machines

Four, Cp/opt/redis/redis-3.2.8/src/redis-trib.rb/opt/redis/bin #只需要第一台机器操作

create two instances on each machine use the steps

1.mkdir-p/opt/redis/instance/ins Port number/conf

2. Mkdir-p/opt/redis/instance/ins Port number/data

3. Mkdir-p/opt/redis/instance/ins Port number/data

4. Mkdir-p/opt/redis/instance/ins Port number/log

5.vim/opt/redis/instance/ins Port number/conf/redis.conf

The content is as follows (general configuration): need to pay attention to the place marked red

#GENERAL

Protected-mode No

Bind 192.168.0.182 127.0.0.1

Daemonize Yes

Tcp-backlog 511

Timeout 0

Tcp-keepalive 0

LogLevel Notice

Databases 16

Dir/opt/redis/instance/ins7000/data

Slave-serve-stale-data Yes

#slave只读

Slave-read-only Yes

#not Use default

Repl-disable-tcp-nodelay Yes

Slave-priority 100

#打开aof持久化

AppendOnly Yes

#每秒一次aof写

Appendfsync everysec

Fsync the new write operation when #关闭在aof rewrite

No-appendfsync-on-rewrite Yes

Auto-aof-rewrite-min-size 64MB

Lua-time-limit 5000

#打开redis集群

cluster-enabled Yes

#节点互连超时的阀值

Cluster-node-timeout 15000

Cluster-migration-barrier 1

Slowlog-log-slower-than 10000

Slowlog-max-len 128

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

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

#包含通用配置

#include/root/redis/conf/redis-common.conf

#监听tcp端口

Port 7000

#最大可用内存

MaxMemory 100m

#内存耗尽时采用的淘汰策略:

# VOLATILE-LRU-> Remove the key with a expire set using an LRU algorithm

# ALLKEYS-LRU-> Remove any key accordingly to the LRU algorithm

# volatile-random-> Remove a random key with a expire set

# allkeys-random-> Remove a random key, any key

# Volatile-ttl-> Remove the key with the nearest Expire time (minor TTL)

# noeviction-> don ' t expire at all, just return a error on write operations

Maxmemory-policy ALLKEYS-LRU

#aof存储文件

Appendfilename "Appendonly.aof"

#不开启rdb存储, only for adding slave procedures

Dbfilename Dump.rdb

#cluster配置文件 (Start automatic generation)

Cluster-config-file nodes.conf

#部署在同一机器的redis实例, the Auto-aof-rewrite to rub open, because the cluster environment memory footprint is basically the same.

#防止同意机器下瞬间fork所有redis进程做aof rewrite, consuming a lot of memory

Auto-aof-rewrite-percentage 80-100

Five, start all 6 instances./redis-server Conf configuration file Address

/opt/redis/bin/redis-server/opt/redis/instance/ins Port number/conf/redis.conf

Install yum install ruby RubyGems on a single machine to build a cluster environment

Install the plugin gem install-l Redis-3.3.3.gem (This is very important and is a tool for managing Redis clusters)

Six, create the cluster/opt/redis/bin/redis-trib.rb created--replicas 1 ip1:port1 ip2:port2 ...

After the creation, if there is no error message will display the master and slave node information of the cluster

Vii. using the REDIS-TRIB.RB command Redis cluster management tools

1. View cluster information./REDIS-TRIB.RB Info 192.168.0.181:7001 (any node in the cluster can)

1, create: Creating a Cluster
2, check: Inspection cluster
3, Info: View the cluster information
4. FIX: Fix the cluster
5, Reshard: Online migration slot
6, Rebalance: Balance cluster node slot number
7, Add-node: The new node to join the cluster
8, Del-node: Remove the node from the cluster
9. Set-timeout: Set timeout for heartbeat connection between cluster nodes
10. Call: Execute commands on all nodes of the cluster

11, import: The external Redis data into the cluster

The specific self-Baidu bar


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.