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
你可以更换master的ip地址或地址,或者,你可以使用slaveof命令,master就会启动和slave的同步。
设置slave到master的认证
如果master需要通过密码登陆,那就需要配置slave在进行所有同步操作也要使用到密码。
在一个运行的实例上尝试,使用 redis-cli :
config set masterauth <password>
Toset it permanently, add this to your config file:
masterauth <password>
3. Redis 持久化
快照
在默认情况下,Redis 将数据库快照保存在名字为 dump.rdb的二进制文件中。你可以对 Redis 进行设置,让它在“ N 秒内数据集至少有 M 个改动”这一条件被满足时,自动保存一次数据集。你也可以通过调用 SAVE或者 BGSAVE ,手动让 Redis 进行数据集保存操作。
比如说,以下设置会让 Redis 在满足“ 60 秒内有至少有 1000 个键被改动【本文来自鸿网互联 (http://www.68idc.cn)】”这一条件时,自动保存一次数据集:
save 60 1000
这种持久化方式被称为快照 snapshotting.
只追加操作的文件(Append-only file,AOF)
快照功能并不是非常耐久(durable):如果 Redis 因为某些原因而造成故障停机,那么服务器将丢失最近写入、且仍未保存到快照中的那些数据。
从 1.1 版本开始, Redis 增加了一种完全耐久的持久化方式:AOF 持久化。
你可以在配置文件中打开AOF方式:
appendonly yes
从现在开始,每当 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实现主从复制:

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.