Home Database Mysql Tutorial Redis+Keepalived内存数据库集群配置

Redis+Keepalived内存数据库集群配置

Jun 07, 2016 pm 03:10 PM
redis cluster

Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

前言:Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

Redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。

Redis是一种高级key-value数据库。它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富。有字符串,链表,集合和有序集合。支持在服务器端计算集合的并,交和补集(difference)等,还支持多种排序功能。所以Redis也可以被看成是一个数据结构服务 器。

Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这称为“半持久化模式”);也可以把每一次数据变化都写入到一个usr/localend only file(aof)里面(这称为“全持久化模式”)。

为了提升redis高可用性,我们除了备份redis dump数据之外,还需要创建redis主从架构,可以利用从将数据库持久化(数据持久化通俗讲就是把数据保存到磁盘上,保证不会因为断电等因素丢失数据。

redis需要经常将内存中的数据同步到磁盘来保证持久化。redis支持两种持久化方式,一种是 Snapshotting(快照)也是默认方式,另一种是Append-only file(缩写aof)的方式。)

什么是redis的主从复制呢?

Redis主从复制,当用户往Master端写入数据时,通过Redis Sync机制将数据文件发送至Slave,Slave也会执行相同的操作确保数据一致;且实现Redis的主从复制非常简单。同时slave上还可以开启二级slave,三级slave从库,跟MySQL的主从类似。

安装redis可以参考上一次课程哦,这里直接安装slave,只需要在slave redis.conf配置文件中加入如下语句即可:

slaveof 192.168.33.10 6379  # slaveofmaster的ip master的端口。

一、安装Keepalived:

tar zxf keepalived-1.2.1.tar.gz

cd keepalived-1.2.1&&./configure --with-kernel-dir=/usr/src/kernels/2.6.18* &&make&& make install

DIR=/usr/local/ ;cp $DIR/etc/rc.d/init.d/keepalived  /etc/rc.d/init.d/

cp $DIR/etc/sysconfig/keepalived /etc/sysconfig/ &&mkdir -p /etc/keepalived

cp $DIR/sbin/keepalived /usr/sbin/

二、配置Keepalived:

vi /etc/keepalived/keepalied.conf

! Configuration File for keepalived

global_defs {

  notification_email{

      wgkgood@139.com

  }

  notification_email_fromwgkgood@139.com

  smtp_server127.0.0.1

  smtp_connect_timeout30

  router_idLVS_DEVEL

}

# VIP1

vrrp_instance VI_1 {

    state BACKUP 

    interface eth0

  lvs_sync_daemon_inteface eth0

    virtual_router_id151

    priority 100

    advert_int 5

    nopreempt

    authentication {

        auth_typePASS

        auth_pass2222

    }

    virtual_ipaddress{

        192.168.33.100

    }

}

virtual_server 192.168.33.100 6379 {

    delay_loop 6   

    lb_algo wrr   

    lb_kind DR 

    persistence_timeout60   

    protocol TCP       

    real_server 192.168.33.10 6379 {

        weight 100       

        notify_down/data/sh/redis.sh

        TCP_CHECK {

        connect_timeout10

        nb_get_retry3

        delay_before_retry3

        connect_port6379

        }

    }

}

三、从Keepalived配置:

Redis从服务器配置keepalived.conf跟master一样,只需要把Realserver IP修改成:

real_server 192.168.33.11 ;优先级从100改成90即可。

vi /etc/keepalived/keepalied.conf

! Configuration File for keepalived

global_defs {

  notification_email{

      wgkgood@139.com

  }

  notification_email_fromwgkgood@139.com

  smtp_server127.0.0.1

  smtp_connect_timeout30

  router_idLVS_DEVEL

}

# VIP1

vrrp_instance VI_1 {

    state BACKUP 

    interface eth0

  lvs_sync_daemon_inteface eth0

    virtual_router_id151

    priority 90

    advert_int 5

    nopreempt

    authentication {

        auth_typePASS

        auth_pass2222

    }

    virtual_ipaddress{

        192.168.33.100

    }

}

virtual_server 192.168.33.100 6379 {

    delay_loop 6   

    lb_algo wrr   

    lb_kind DR 

    persistence_timeout60   

    protocol TCP       

    real_server 192.168.33.11 6379 {

        weight 100       

        notify_down/data/sh/redis.sh

        TCP_CHECK {

        connect_timeout10

        nb_get_retry3

        delay_before_retry3

        connect_port6379

        }

    }

}

四、创建切换脚本:

在master、slave数据库上创建/data/sh/redis.sh脚本,内容为:

/etc/init.d/keepalived stop

然后分别重启两台Redis数据库上keepalived服务即可。

最后测试停止master Mysql服务,,是否会自动切换到Backup上即可。

下面关于Redis的文章您也可能喜欢,不妨参考下:

Ubuntu 14.04下Redis安装及简单测试

Redis主从复制基本配置

Redis集群明细文档

Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis

Redis系列-安装部署维护篇

CentOS 6.3安装Redis

Redis安装部署学习笔记

Redis配置文件redis.conf 详解

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

本文永久更新链接地址

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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.

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 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

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