Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install stand-alone Redis for Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to install a stand-alone version of Redis in Linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Preface

Redis is one of the most popular NOSQL systems, and it is a key-value storage system. Similar to Memcached, but largely compensating for the shortcomings of memcached, it supports relatively more value types of storage, including string, list, set, zset, and hash. These data types support push/pop, add/remove, and take intersection union and difference sets and richer operations. On this basis, redis supports a variety of different sorting methods. Redis data is cached in computer memory, and will periodically write updated data to disk or modify operations to additional record files.

Recently, in migrating the test environment, it is useful to Redis to record the process of installing a stand-alone version of Redis in linux. Let's take a look at the detailed introduction.

Verify the gcc-c++ environment

Redis is developed in C language, so to run on linux, you need the environment of gcc-c++.

Check if there is a gcc-c++ environment:

Rpm-qa | grep gcc-c++

If there is no installation:

Yum install gcc-c++yum-y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make gcc-c++ libstdc++-devel tcl

Install Redis

First download the installation package:

Wget http://download.redis.io/releases/redis-4.0.10.tar.gz

Then extract it to the specified directory:

Tar-zxvf redis-4.0.10.tar.gz-C / usr/local/

Go to the extracted directory and compile:

Cd / usr/local/redis-4.0.10make

Install after successful compilation, and set the installation path:

Make install PREFIX=/usr/local/redis

After the installation is completed, you can start it in the corresponding directory:

Cd / usr/local/redis/bin./redis-server

If all goes well, redis has started normally, but the startup content will be displayed on the terminal. If you do not want to display it, you can modify the configuration.

First, go to redis.conf in the copy installation package.

Cp / root/redis-4.0.10/redis.conf / usr/local/redis

Then open the configuration file and set the daemonize in the file to yes.

Edit after vi redis.conf, as shown in the screenshot below:

Then start it with the configuration item:

. / redis-server redis.conf

Verification and operation

After the redis is installed, we check to see if it is normal.

First, let's start the test side:. / redis-cli, and then do some simple operations, as shown in the screenshot below:

Configuration description

# # basic configuration daemonize no / / the number of databases 16 / / database created by background process (database 0 is selected by default) save 900 1 # refresh the snapshot to the hard disk must meet the requirements of both before it will be triggered, that is, at least 1 keyword will change after 900 seconds. Save 30010 # must be at least 10 keywords changed after 300 seconds. Save 60 10000 # must be at least 10000 keywords changed after 60 seconds. Stop-writes-on-bgsave-error yes # background storage error stops writing. Rdbcompression yes # uses LZF to compress rdb files. Rdbchecksum yes # verifies when storing and loading rdb files. Dbfilename dump.rdb # sets the rdb file name. Dir. / # sets the working directory to which the rdb file is written. / / Master / Slave configuration slaveof / / set to a machine's slave server masterauth / / the password to connect to the master server slave-serve-stale-data yes # when the master server is disconnected or is in the process of replication, whether the slave server answers slave-read-only yes # slave server read-only repl-ping-slave-period 10 # slave master interval in seconds repl-timeout 60 # master-slave timeout (timeout is considered disconnected) Slave-priority is bigger than period # if master can no longer work properly Then among multiple slave, the slave with the lowest priority value is selected to be promoted to master, and a priority value of 0 means that it cannot be promoted to master. Whether the master end of repl-disable-tcp-nodelay no # merges data or not. Send large chunks to slaveslave-priority 100 / / the priority of the slave server. When the master server dies, it will automatically pick the smallest slave priority as the master server # secure requirepass foobared # requires password rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 # if public environment Some sensitive commands can be renamed, such as config # limit maxclients 10000 # maximum number of connections maxmemory # maximum use memory maxmemory-policy volatile-lru # memory limit processing volatile-lru-> # LRU algorithm Delete expired keyallkeys-lru-> # LRU algorithm Delete key-> # Random Delete expired keyallkeys-random-> # Random Delete key (do not distinguish overdue) volatile-ttl- > # Delete keynoeviction that is about to expire-> # do not delete Return error message # explain that LRU ttl is an approximate algorithm, you can choose N, and then compare whether the most suitable data maxmemory-samples log mode appendonly no # is only log appendfsync no # system buffering, unified writing, fast appendfsync always # system does not buffer, direct write, slow, less lost data appendfsync everysec # compromise, write no-appendfsync-on-rewrite no # once per second to yes, then the data of other threads will be put in memory Merge writes (fast Easy to lose) auto-AOF-rewrite-percentage 100 # the current aof file is the minimum size to rewrite auto-AOF-rewrite-min-size 64mb # aof when the last rewrite is large N% # slow query slowlog-log-slower-than 10000 # record slow query slowlog-max-len with a response time greater than 10000 microseconds # A maximum of 128 records # server command time # returns timestamp + microsecond dbsize # the number of key returned Quantity bgrewriteaof # rewrite aofbgsave # background start child process dump data save # blocking process dump data slaveof host port # do host port slave server (data emptying Copy the new main content) slaveof no one # becomes the master server (the original data is not lost, usually used after the failure of the master server) flushdb # clear all data in the current database flushall # clear all data in all databases (what if misused?) shutdown [save/nosave] # shut down the server and save the data Modify AOF (if set) slowlog get # get slow log slowlog len # get slow log entries slowlog reset # clear slow query config get # option (support * wildcard) config set # option value config rewrite # write value to configuration file config restart # update info command debug object key # debug option, look at a key situation debug segfault # simulation segment error, make the server crash object key (refcount | encoding | idletime) monitor # open the console Watch the command (debug) client list # list all connections client kill # Kill a connection CLIENT KILL 127.0.0.1:43501client getname # get the name of the connection default nilclient setname "name" # set the connection name, easy to debug # connection command auth password login (if there is a password) ping # test whether the server is available with echo "some content" # test whether the server interacts properly with select 0Tax 1ax 2. # Select database quit # to exit the connection

Summary

It is relatively easy to build redis. Interested partners can try it themselves and try to build a redis cluster next time.

Supplementary information

Installation:

1. Get redis resources

Wget http://download.redis.io/releases/redis-4.0.8.tar.gz

two。 Decompression

Tar xzvf redis-4.0.8.tar.gz

3. Installation

Cd redis-4.0.8

Make

Cd src

Make install PREFIX=/usr/local/redis

4. Move the configuration file to the installation directory

Cd.. /

Mkdir / usr/local/redis/etc

Mv redis.conf / usr/local/redis/etc

5. Configure redis to start in the background

Vi / usr/local/redis/etc/redis.conf / / change daemonize no to daemonize yes

6. Add redis to boot

Vi / etc/rc.local / / add something to it: / usr/local/redis/bin/redis-server / usr/local/redis/etc/redis.conf (meaning to start up and call the command to open redis)

7. Turn on redis

/ usr/local/redis/bin/redis-server / usr/local/redis/etc/redis.conf

Common command

Redis-server / usr/local/redis/etc/redis.conf / / start redis

Pkill redis / / stop redis

Uninstall redis:

Rm-rf / usr/local/redis / / Delete the installation directory

Rm-rf / usr/bin/redis-* / / remove all redis-related command scripts

Rm-rf / root/download/redis-4.0.4 / / Delete the redis decompression folder

This is the end of the article on "how to install stand-alone Redis for Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report