Home Database Mysql Tutorial Redis安装及主从配置

Redis安装及主从配置

Jun 07, 2016 pm 05:17 PM
oracle redis database

Redis是一种面向ldquo;键/值rdquo;对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景。它起步

Redis是一种面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景。它起步较晚,发展迅速,目前已被许多大型机构采用,如google、taobao、sina微博等。本文不对其数据结构做深入的讲解,只是介绍其安装及主从结构的配置过程。如需要更详细的了解请参考其官方网站。 Redis的安装

Redis目前只支持Linux及BSD等系统,不支持Window下的安装。在Linux下安装的过程如下所示:

$ wget

$ tar xzf redis-2.2.12.tar.gz

$ cd redis-2.2.12

$ make

安装成功后的提示为:

Hint: To run 'make test' is a good idea ;)

make[1]: Leaving directory `/usr/alibaba/install/redis-2.2.12/src'

在安装完成后,即可进入至该工程的src下启动服务:

$ src/redis-server

通过内置的build-cli工具进行相应的测试,其测试过程如下:

$ src/redis-cli

redis> set foo bar

OK

redis> get foo

"bar"

redis > getset foo 123

“bar”

redis >get foo

123

Redis的主从配置 机器的分配

主从结构的配置所涉及到的机器及各机器所完成的功能如下所示:

IP地址                                      

角色

10.20.150.205

主结点

10.20.150.208

从结点1

10.20.150.209

从结点2

主从结构的配置

在进行主从结构配置之前,请确保已经在上述三台机器上已经安装了Redis服务。对于Redis的主从结构的配置相对比较简单,只需修改redis.conf文件,配置上主结点对应的IP及端口。具体如下所示:

Port 6380

bind 10.20.150.205

slaveof 10.20.150.205 6379

l  port 6380表示当前该Redis服务对应的端口号;

l  bind 10.20.150.205 表示当前Redis绑定的主结点的IP地址;

l  slaveof 10.20.150.205 6379 表示当前Redis是哪个主结点的从结点,其中包括IP及端口号。

当主结点在启动时                       

当只有一台主结点在启动时,会显示如下的信息:

[29028] 26 Sep 18:39:12 * Server started, Redis version 2.2.12

[29028] 26 Sep 18:39:12 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

[29028] 26 Sep 18:39:12 * DB loaded from disk: 0 seconds

[29028] 26 Sep 18:39:12 * The server is now ready to accept connections on port 6379

[29028] 26 Sep 18:39:12 - 0 clients connected (0 slaves), 790584 bytes in use

当有一台从结点10.20.150.208启动时

其中主结点会自动检测到有新的从结点启动并加入进来,其显示的信息如下:

[29028] 26 Sep 18:40:31 - Accepted 10.20.150.208:44779

[29028] 26 Sep 18:40:31 * Slave ask for synchronization

[29028] 26 Sep 18:40:31 * Starting BGSAVE for SYNC

[29028] 26 Sep 18:40:31 * Background saving started by pid 29091

[29091] 26 Sep 18:40:31 * DB saved on disk

[29028] 26 Sep 18:40:31 * Background saving terminated with success

[29028] 26 Sep 18:40:31 * Synchronization with slave succeeded

[29028] 26 Sep 18:40:32 - 0 clients connected (1 slaves), 798752 bytes in use

[29028] 26 Sep 18:40:37 - 0 clients connected (1 slaves), 798752 bytes in use

[29028] 26 Sep 18:40:42 - 0 clients connected (1 slaves), 798752 bytes in use

[29028] 26 Sep 18:40:47 - 0 clients connected (1 slaves), 798752 bytes in use

对于从结点显示的信息如下:

#[597] 26 Sep 18:40:29 * Server started, Redis version 2.2.12

[597] 26 Sep 18:40:29 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

[597] 26 Sep 18:40:29 * The server is now ready to accept connections on port 6379

[597] 26 Sep 18:40:29 - 0 clients connected (0 slaves), 790616 bytes in use

[597] 26 Sep 18:40:29 * Connecting to MASTER...

[597] 26 Sep 18:40:29 * MASTER SLAVE sync started: SYNC sent

[597] 26 Sep 18:40:29 * MASTER SLAVE sync: receiving 10 bytes from master

[597] 26 Sep 18:40:29 * MASTER SLAVE sync: Loading DB in memory

[597] 26 Sep 18:40:29 * MASTER SLAVE sync: Finished with success

[597] 26 Sep 18:40:34 - 1 clients connected (0 slaves), 798744 bytes in use

当有另外一台从机10.20.150.209挂载时

当有另一台从机挂载至主机时,主机显示的信息如下:

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
1 months 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)

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

Redstone/RED currency listing price forecast and detailed explanation of token economics Redstone/RED currency listing price forecast and detailed explanation of token economics Mar 03, 2025 pm 10:42 PM

This time, the Redstone token $RED will be launched on Binance Launchpool on Binance TGE! This is also the first time Binance has launched a pre-market trading limit mechanism! The first day limit is 200%, and the ban will be lifted after 3 days to avoid "the peak will be achieved when the market opens"! Launchpool mechanism introduces the BinanceLaunchpool participating in Redstone that needs to pledge designated tokens (BNB, USDC, FDUSD) activity period is 48 hours: 08:00 UTC on February 26, 2025 to 08:00 UTC on February 28, 2025 ending this pre-market daily limit rule: 18:00 on February 28, 2025

Practical case: Connecting to heterogeneous database systems using PHP Practical case: Connecting to heterogeneous database systems using PHP Jun 02, 2024 pm 08:46 PM

PHP connecting to heterogeneous databases provides the ability to interact across different database systems by installing specific extensions (such as PDO_SQLSRV, PDO_OCI, PDO_MYSQL) and using PDO classes to connect to the database. In the actual case, PHP queries SQL Server and Oracle database and merges the results. Through these steps, users can integrate heterogeneous databases to build powerful applications that span multiple data sources.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

See all articles