Home Database Mysql Tutorial Redis 3.0.3集群搭建

Redis 3.0.3集群搭建

Jun 07, 2016 pm 03:10 PM
redis cluster

Redis3.0版本之后支持Cluster,具体介绍redis集群我就不多说,了解请看redis中文简介。首先,直接访问redis.io官网,下载redis.t

Redis3.0版本之后支持Cluster,具体介绍redis集群我就不多说,了解请看redis中文简介。

首先,直接访问redis.io官网,下载redis.tar.gz,现在版本3.0.3,我下面已经在虚拟机启动了两个linux来部署redis。

1. 下载和解包

  cd /usr/local/

  wget

  tar -zxvf redis-3.0.3.tar.gz

  mv redis-3.0.3  redis

2. 编译安装

  cd redis

  make && make install

  有些人在这里可能会碰到一个错误导致编译不过(如下)

 

make[1]: Entering directory `/redis/src'
CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/redis/src'
make: *** [all] Error 2

 

  原因是没有安装jemalloc内存分配器,可以安装jemalloc 或 直接 输入make MALLOC=libc  && make install

3. 创建redis节点

    我们将在两台Server上创建六个节点,每台3个,3主3从。

  1)Server1

    cd /usr/local/

    mkdir redis_cluster  //创建集群目录

    mkdir 7000 7001 7002  //分别代表三个节点    其对应端口 7000 7001 7002

    创建7000节点为例,

    cd ./7000

    cp /usr/local/redis/redis.conf  ./    //拷贝到当前7000目录

    vi redis.conf    //编辑配置  主要修改一下几个参数

 

daemonize    yes                          //redis后台运行
pidfile  /var/run/redis_7000.pid    //pidfile文件对应7000
port  7000                                  //端口7000
cluster-enabled  yes                    //开启集群  把注释#去掉
cluster-config-file  nodes.conf      //集群的配置  配置文件首次启动自动生成
cluster-node-timeout  5000      //请求超时  设置5秒够了
appendonly  yes                        //aof日志开启  有需要就开启,它会每次写操作都记录一条日志

 

    配置好了,就相应地把这个修改后的配置文件拷贝到 7001  7002目录,注意要修改监听端口port 7001 7002.

    接下来,启动服务,进入节点目录

    依次执行  redis-server  redis.conf

    可以看到生成了appendonly.aof  nodes.conf

    ps -ef | grep redis 查看是否启动成功

      root 885 0.8 0.2 129452 2620 ? Ssl 20:10 0:21 redis-server *:7000 [cluster]
      root 887 0.8 0.2 129452 2616 ? Ssl 20:10 0:21 redis-server *:7001 [cluster]
      root 893 0.8 0.2 128356 2612 ? Ssl 20:10 0:21 redis-server *:7002 [cluster]

    netstat -tnlp | grep redis 可以看到redis监听端口

      tcp 0 0 0.0.0.0:7000 0.0.0.0:* LISTEN 885/redis-server *
      tcp 0 0 0.0.0.0:7001 0.0.0.0:* LISTEN 887/redis-server *
      tcp 0 0 0.0.0.0:7002 0.0.0.0:* LISTEN 893/redis-server *
      tcp 0 0 0.0.0.0:17000 0.0.0.0:* LISTEN 885/redis-server *
      tcp 0 0 0.0.0.0:17001 0.0.0.0:* LISTEN 887/redis-server *
      tcp 0 0 0.0.0.0:17002 0.0.0.0:* LISTEN 893/redis-server *

    我们除了看到 配置文件中设置的端口700*    还有700*+10000  (1700*), 前者是客户端访问的, 后者是集群内部节点之间访问的.

    注意,在多台Server间搭建集群,如果开了防火墙的,需要设置iptables开放上面所有端口.

 

  2) Server2

    步骤和Server1一样, 设置端口  7003  7004  7005

 

 4. 创建集群

  前面已经准备好了搭建集群的redis节点,接下来我们要把这些节点都串连起来搭建集群。官方提供了一个工具:redis-trib.rb  (/usr/local/redis/src/redis-trib.rb) 看后缀就知道这鸟东西不能直接执行,它是用ruby写的一个程序,所以我们还得安装ruby.

  yum -y install ruby ruby-devel rubygems rpm-build    //网上不明觉厉,都是这么安装的,就跟着这样玩吧

  再用 gem 这个命令来安装 redis接口    gem貌似是ruby的一个工具包  反正没错就是了。

  gem install redis    //等一会儿就好了

  当然,方便操作,两台Server都要安装。

 

  上面的步骤完事了,接下来运行一下redis-trib.rb

    /usr/local/redis/src/redis-trib.rb

 

Usage: redis-trib

  reshard        host:port
                  --to
                  --yes
                  --slots
                  --from
  check          host:port
  call            host:port command arg arg .. arg
  set-timeout    host:port milliseconds
  add-node        new_host:new_port existing_host:existing_port
                  --master-id
                  --slave
  del-node        host:port node_id
  fix            host:port
  import          host:port
                  --from
  help            (show this help)
  create          host1:port1 ... hostN:portN
                  --replicas

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

 

    看到这,应该明白了吧, 就是靠上面这些操作 完成redis集群搭建的.

    确认所有的节点都启动,接下来使用参数create 创建    (在Server1中来创建)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Implementing Redis cluster using ThinkPHP6 Implementing Redis cluster using ThinkPHP6 Jun 20, 2023 am 08:36 AM

With the rapid development of the Internet, the problem of high concurrency has become more and more prominent. In response to this problem, the emergence of Redis has become an important solution. It solves the problem of excessive reading and writing pressure in traditional relational databases through memory reading and writing. However, single-node Redis still has performance bottlenecks under high concurrency conditions, so Redis clusters need to be used. This article will describe how to use ThinkPHP6 to implement a Redis cluster. 1. Introduction to Redis Cluster Redis Cluster is an official cluster provided by Redis.

Redis and Node.js cluster solution: how to achieve high availability Redis and Node.js cluster solution: how to achieve high availability Jul 29, 2023 pm 05:42 PM

Cluster solution for Redis and Node.js: How to achieve high availability Introduction: With the rapid development of the Internet, data processing has become increasingly large and complex. In order to ensure high availability and scalability of the system, we need to use a distributed cluster architecture to handle the needs of storing and processing large amounts of data. Redis, as a high-performance in-memory database, combined with Node.js as the back-end programming language, can build a highly available distributed cluster solution. This article will introduce how to use Redis and Node.js to implement

Redis cluster in Redis and how to use PHP Redis cluster in Redis and how to use PHP May 15, 2023 pm 03:22 PM

Redis is a powerful in-memory key-value pair storage database. It has higher performance and better scalability than regular RDBMS (relational database management system). One of the advantages of Redis is that it can be used as the core technology of distributed systems. In this article, we will explore the concept of Redis Cluster and how to use Redis Cluster in PHP. What is Redis cluster? Simply put, a Redis cluster is an aggregation of multiple Redis instances. Redis cluster allows us

Learn database functions in Go language and implement read and write operations in Redis cluster Learn database functions in Go language and implement read and write operations in Redis cluster Jul 29, 2023 pm 12:21 PM

Learn the database functions in Go language and implement read and write operations in Redis cluster Introduction: Database is an indispensable part of today's Internet applications, and Go language, as a simple and efficient programming language, also has good database operation capabilities. This article will introduce how to use database functions in Go language and implement read and write operations in Redis cluster. 1. Database functions in Go language Database operations in Go language are mainly implemented through the database/sql package. This package provides basic data

How to implement cluster deployment of PHP data cache through Redis? How to implement cluster deployment of PHP data cache through Redis? Aug 10, 2023 am 08:13 AM

How to implement cluster deployment of PHP data cache through Redis? Introduction: When PHP applications face high concurrency and large traffic, they often encounter database performance bottlenecks. At this time, using caching technology can greatly improve the performance and concurrency of the system. As a high-performance in-memory key-value database, Redis is widely used in the implementation of caching solutions. This article will introduce how to implement cluster deployment of PHP data cache through Redis to further improve performance and scalability. 1. Overview of Redis Cluster Redis

Redis and PHP cluster solution: how to achieve high availability and scalability Redis and PHP cluster solution: how to achieve high availability and scalability Jul 30, 2023 pm 08:51 PM

Redis and PHP cluster solution: How to achieve high availability and scalability Introduction: Redis is an open source, high-performance in-memory database that is often used to build fast and scalable applications. As a popular server-side scripting language, PHP can be used with Redis to achieve high availability and scalability cluster solutions. This article will introduce how to use Redis and PHP to build a high-availability and scalable cluster, and explain in detail through code examples. 1. Construction, installation and configuration of Redis cluster Re

How to use Redis and Julia languages ​​to implement high-availability cluster functions How to use Redis and Julia languages ​​to implement high-availability cluster functions Sep 20, 2023 am 10:58 AM

How to use Redis and Julia languages ​​to implement high-availability cluster functions Introduction: With the development of Internet business, the requirements for system availability are getting higher and higher. To ensure that systems can continue to provide services in the event of a failure, high availability has become one of the key requirements in various industries. This article will introduce how to use Redis and Julia languages ​​to implement high-availability cluster functions, and provide specific code examples. 1. What is a high-availability cluster? A high-availability cluster organizes multiple nodes together to form an overall system.

Redis cluster expansion plan and implementation details Redis cluster expansion plan and implementation details Jun 21, 2023 am 10:58 AM

Redis is a high-performance open source memory data storage service. It is increasingly favored by developers because of its fast read and write speed, persistent storage and support for multiple data structures. As the business continues to grow, the storage capacity of Redis can no longer meet the demand, and it needs to be expanded. This article will introduce the Redis cluster expansion plan and its implementation details. The concept of Redis cluster Redis cluster refers to connecting multiple Redis instances together to form a large set of Redis instances, which can improve Redis

See all articles