Home Database Mysql Tutorial Redis系列-安装部署维护篇

Redis系列-安装部署维护篇

Jun 07, 2016 pm 05:23 PM
redis

redis高性能很大程度上源于它是个内存型数据库,它的高性能表现在:set操作11w/s,get操作8.1w/s,为了进一步加深对redis的理解总

Redis是个高性能的key-value数据库,它的key具有丰富的数据结构:string,hash,list set和sorted set。作为NOSQL,比起memcache之类,不仅仅key数据结构丰富,而且具有持久化的功能,并且能够支持主从复制,,很方便构建集群。

redis高性能很大程度上源于它是个内存型数据库,它的高性能表现在:set操作11w/s,get操作8.1w/s,为了进一步加深对redis的理解总结,我打算写个redis系列的文章。这里主要谈谈redis安装部署及运维维护。

1、下载安装

[root@ ]# wget -c     #下载 
[root@ ]# tar -zxvf redis-2.4.17.tar.gz  #解压 
[root@ ]# cd redis-2.4.17 
[root@ redis-2.4.17]# make  #编译 
[root@ redis-2.4.17]# make install #安装 

安装完毕,常用工具会自动拷贝到/user/loca/bin目录下。做为服务器,我们常常还需要把redis设置成开机自启动,源码包中有个很好用的脚本,执行脚步根据提示输入即可。

[root@ redis-2.4.17]# cd utils/ 
[root@ utils]# ./install_server.sh 
Welcome to the redis service installer 
This script will help you easily set up a running redis server 
 
 
Please select the redis port for this instance: [6379] 
Selecting default: 6379 
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf 
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log 
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379 
Please select the redis executable path [/usr/local/bin/redis-server] 
Copied /tmp/6379.conf => /etc/init.d/redis_6379 
Installing service... 
Successfully added to chkconfig! 
Successfully added to runlevels 345! 
Starting Redis server... 
Installation successful! 

注意执行install_server.sh,需要先进入utils目录,不然脚本会报错,提示找不到相应文件。安装完服务,redis自动启动,可以用ps命令查看到相关信息:

[root@ utils]# ps -ef | grep redis 
root      4554    1  0 10:55 ?        00:00:02 /usr/local/bin/redis-server /etc/redis/6379.conf 
root      4564  2808  0 10:59 pts/0    00:00:00 grep redis 

2、手动启动关闭服务

[root@ utils]# /etc/init.d/redis_6379 stop  #关闭 
[root@ utils]# /etc/init.d/redis_6379 start  #启动 

3、通过客户端命令行工具连接redis服务查看redis相关信息

a)连接

[root@ utils]# redis-cli 

redis 127.0.0.1:6379> 

b)其他指令

redis 127.0.0.1:6379> info  #查看server版本内存使用连接等信息 
 
redis 127.0.0.1:6379> client list  #获取客户连接列表 
 
redis 127.0.0.1:6379> client kill 127.0.0.1:33441 #终止某个客户端连接 
 
redis 127.0.0.1:6379> dbsize #当前保存key的数量 
 
redis 127.0.0.1:6379> save #立即保存数据到硬盘 
 
redis 127.0.0.1:6379> bgsave #异步保存数据到硬盘 
 
redis 127.0.0.1:6379> flushdb #当前库中移除所有key 
 
redis 127.0.0.1:6379> flushall #移除所有key从所有库中 
 
redis 127.0.0.1:6379> lastsave #获取上次成功保存到硬盘的unix时间戳 
 
redis 127.0.0.1:6379> monitor #实时监测服务器接收到的请求 
 
redis 127.0.0.1:6379> slowlog len #查询慢查询日志条数 
(integer) 3 
 
redis 127.0.0.1:6379> slowlog get #返回所有的慢查询日志,最大值取决于slowlog-max-len配置 
 
redis 127.0.0.1:6379> slowlog get 2 #打印两条慢查询日志 
 
redis 127.0.0.1:6379> slowlog reset #清空慢查询日志信息 

通过以上操作,单台服务器基本跑起来了,不过后面的路还很长很长。

linux

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)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How to build the redis cluster mode How to build the redis cluster mode Apr 10, 2025 pm 10:15 PM

Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make

How to clear redis data How to clear redis data Apr 10, 2025 pm 10:06 PM

How to clear Redis data: Use the FLUSHALL command to clear all key values. Use the FLUSHDB command to clear the key value of the currently selected database. Use SELECT to switch databases, and then use FLUSHDB to clear multiple databases. Use the DEL command to delete a specific key. Use the redis-cli tool to clear the data.

How to read redis queue How to read redis queue Apr 10, 2025 pm 10:12 PM

To read a queue from Redis, you need to get the queue name, read the elements using the LPOP command, and process the empty queue. The specific steps are as follows: Get the queue name: name it with the prefix of "queue:" such as "queue:my-queue". Use the LPOP command: Eject the element from the head of the queue and return its value, such as LPOP queue:my-queue. Processing empty queues: If the queue is empty, LPOP returns nil, and you can check whether the queue exists before reading the element.

How to configure Lua script execution time in centos redis How to configure Lua script execution time in centos redis Apr 14, 2025 pm 02:12 PM

On CentOS systems, you can limit the execution time of Lua scripts by modifying Redis configuration files or using Redis commands to prevent malicious scripts from consuming too much resources. Method 1: Modify the Redis configuration file and locate the Redis configuration file: The Redis configuration file is usually located in /etc/redis/redis.conf. Edit configuration file: Open the configuration file using a text editor (such as vi or nano): sudovi/etc/redis/redis.conf Set the Lua script execution time limit: Add or modify the following lines in the configuration file to set the maximum execution time of the Lua script (unit: milliseconds)

How to use the redis command line How to use the redis command line Apr 10, 2025 pm 10:18 PM

Use the Redis command line tool (redis-cli) to manage and operate Redis through the following steps: Connect to the server, specify the address and port. Send commands to the server using the command name and parameters. Use the HELP command to view help information for a specific command. Use the QUIT command to exit the command line tool.

How to implement redis counter How to implement redis counter Apr 10, 2025 pm 10:21 PM

Redis counter is a mechanism that uses Redis key-value pair storage to implement counting operations, including the following steps: creating counter keys, increasing counts, decreasing counts, resetting counts, and obtaining counts. The advantages of Redis counters include fast speed, high concurrency, durability and simplicity and ease of use. It can be used in scenarios such as user access counting, real-time metric tracking, game scores and rankings, and order processing counting.

How to set the redis expiration policy How to set the redis expiration policy Apr 10, 2025 pm 10:03 PM

There are two types of Redis data expiration strategies: periodic deletion: periodic scan to delete the expired key, which can be set through expired-time-cap-remove-count and expired-time-cap-remove-delay parameters. Lazy Deletion: Check for deletion expired keys only when keys are read or written. They can be set through lazyfree-lazy-eviction, lazyfree-lazy-expire, lazyfree-lazy-user-del parameters.

How to optimize the performance of debian readdir How to optimize the performance of debian readdir Apr 13, 2025 am 08:48 AM

In Debian systems, readdir system calls are used to read directory contents. If its performance is not good, try the following optimization strategy: Simplify the number of directory files: Split large directories into multiple small directories as much as possible, reducing the number of items processed per readdir call. Enable directory content caching: build a cache mechanism, update the cache regularly or when directory content changes, and reduce frequent calls to readdir. Memory caches (such as Memcached or Redis) or local caches (such as files or databases) can be considered. Adopt efficient data structure: If you implement directory traversal by yourself, select more efficient data structures (such as hash tables instead of linear search) to store and access directory information

See all articles