Table of Contents
1. Linux下Redis的安装使用
2. Redis主从复制
3. Redis 持久化
1. 测试结果
Home Database Mysql Tutorial Linux下Redis的安装使用

Linux下Redis的安装使用

Jun 07, 2016 pm 04:13 PM
linux redis use Install

1. Linux下Redis的安装使用 官方下载:http://redis.io/download 可以根据需要下载不同版本 下载,解压和安装: $ wgethttp://download.redis.io/releases/redis-2.6.17.tar.gz $ tar xzf redis-2.6.17.tar.gz $ cd redis-2.6.17 $ make 编译后的可执行文件

1. Linux下Redis的安装使用

官方下载:http://redis.io/download 可以根据需要下载不同版本

下载,解压和安装:

$ wgethttp://download.redis.io/releases/redis-2.6.17.tar.gz

$ tar xzf redis-2.6.17.tar.gz

$ cd redis-2.6.17

$ make

编译后的可执行文件在src目录中,可以使用下面的命令运行Redis:

$ src/redis-server

你可以使用内置的客户端连接Redis:

$ src/redis-cli

redis> set foo bar

OK

redis> get foo

"bar"

 

安装时遇到的问题:

1. 如果出现“Youneed 'tclsh8.5' in order to run the Redis test”。则可运行 sudo apt-get install tcl8.5 来安装tcl。
然后再make test测试一下注意是在redis的目录里面
最后出现\o/ All tests passed without errors!

centos 可以是yum install tcl 这么安装。

也可以从官网上http://sourceforge.net/projects/tcl/files/Tcl/下载tcl,然后按照以下步骤安装:

1. wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz

2. sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/

3. cd /usr/local/tcl8.6.1/unix/

4. sudo ./configure

5. sudo make

6. sudo make install

2. gcc:命令未找到
sudo yum install gcc。

从安装光盘里装rpm包或是从官网下载压缩包安装(前提是已安装低版本gcc)。

3. jemalloc/jemalloc.h: 没有那个文件或目录
make的时候加上MALLOC=libc 参数。

 

2. Redis主从复制

配置

配置复制是很简单的,仅仅在slave的配置文件中增加类似下面这行的内容:

slaveof 192.168.1.1 6379
Copy after login

你可以更换master的ip地址或地址,或者,你可以使用slaveof命令,master就会启动和slave的同步。

设置slave到master的认证

如果master需要通过密码登陆,那就需要配置slave在进行所有同步操作也要使用到密码。

在一个运行的实例上尝试,使用 redis-cli :

config set masterauth <password>
Copy after login

Toset it permanently, add this to your config file:

masterauth <password>
Copy after login

3. Redis 持久化

快照

在默认情况下,Redis 将数据库快照保存在名字为 dump.rdb的二进制文件中。你可以对 Redis 进行设置,让它在“ N 秒内数据集至少有 M 个改动”这一条件被满足时,自动保存一次数据集。你也可以通过调用 SAVE或者 BGSAVE ,手动让 Redis 进行数据集保存操作。

比如说,以下设置会让 Redis 在满足“ 60 秒内有至少有 1000 个键被改动【本文来自鸿网互联 (http://www.68idc.cn)】”这一条件时,自动保存一次数据集:

save 60 1000
Copy after login

这种持久化方式被称为快照 snapshotting.

只追加操作的文件(Append-only file,AOF)

快照功能并不是非常耐久(durable):如果 Redis 因为某些原因而造成故障停机,那么服务器将丢失最近写入、且仍未保存到快照中的那些数据。

从 1.1 版本开始, Redis 增加了一种完全耐久的持久化方式:AOF 持久化。

你可以在配置文件中打开AOF方式:

appendonly yes
Copy after login

从现在开始,每当 Redis 执行一个改变数据集的命令时(比如SET),这个命令就会被追加到 AOF 文件的末尾。这样的话,当 Redis 重新启时,程序就可以通过重新执行 AOF 文件中的命令来达到重建数据集的目的。

AOF有多耐用?

你可以配置Redis 多久才将数据 fsync 到磁盘一次。有三种方式:

· 每次有新命令追加到 AOF 文件时就执行一次 fsync :非常慢,也非常安全

· 每秒 fsync 一次:足够快(和使用 RDB 持久化差不多),并且在故障时只会丢失 1 秒钟的数据。

· 从不 fsync :将数据交给操作系统来处理。更快,也更不安全的选择。

推荐(并且也是默认)的措施为每秒fsync 一次,这种 fsync 策略可以兼顾速度和安全性。

1. 测试结果

测试主从复制:

在主机上通过info命令查看机器状态,通过keys*命令查看数据库里数据为空,用set命令设置键k1,值v1,用get命令得到k1值为v1:

在从机上通过info命令查看机器状态,通过keys*命令查看数据库里数据为空,用get命令得到k1值为v1实现主从复制:

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

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to switch Chinese mode with vscode How to switch Chinese mode with vscode Apr 15, 2025 pm 11:39 PM

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

How to back up vscode settings and extensions How to back up vscode settings and extensions Apr 15, 2025 pm 05:18 PM

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

See all articles