Centos7 install redis

Introduction :

Redis is an advanced key-value database. It is similar to memcached, but the data can be persisted and the supported data types are very rich. There are strings, linked lists, sets and sorted sets. It supports computing the union, intersection and complement of sets on the server side, and also supports various sorting functions. So Redis can also be regarded as a data structure server.

All data of Redis is stored in memory (high efficiency), and then saved to disk in an asynchronous manner from time to time (this is called "semi-persistent mode"); it is also possible to write each data change to a append only file(aof) inside (this is called "full persistence mode").

Here I only give  the installation and deployment of Redis on CentOS 7.

Step 1: Download the Redis installation package

First, download the compressed package redis-2.8.19.tar.gz in the official version of redis from the official website:

cd /home/downloads

wget http://download.redis.io/releases/redis-2.8.19.tar.gz

Step 2: Compile the source program

Unzip and compile

tar -zxvf redis-2.8.19.tar.gz

cd redis-2.8.19/src

// compile

make

……. Here is a large number of compilation processes, omitted. There may be some warnings, don't go to them....... 
CC setproctitle.o 
CC hyperloglog.o 
CC latency.o 
CC sparkline.o 
LINK redis-server 
INSTALL redis-sentinel 
CC redis-cli.o 
LINK redis-cli 
CC redis -benchmark.o 
LINK redis-benchmark 
CC redis-check-dump.o 
LINK redis-check-dump 
CC redis-check-aof.o 
LINK redis-check-aof

Hint: It’s a good idea to run ‘make test’ ;)

Enter src to install:

cd src

make install

//The installation process prompts 
Hint: It's a good idea to run 'make test' ;)

INSTALL install

INSTALL install

INSTALL install

INSTALL install

INSTALL install

At this time, we can look at the files under src:

 

You can see that at this time, there are some green files in the src folder. These files are the command files we need to use in the future.

Step 3: Move the file

Move files for easy management: (all source code installed software is installed under /usr/local, such as apache, etc.)

Create two folders, bin is used to store commands, etc. have configuration files.

mkdir -p /usr/local/redis/etcmkdir -p /usr/local/redis/etc

-p is to create recursively.

Next, copy the redis.conf under the redis-2.8.19 folder to /usr/local/redis/etc/

And move the 7 command files (green) in the src directory to /usr/local/redis/bin/

[linuxidc@localhost src]$ cd ..

[linuxidc@localhost redis-2.8.19]$ ls00-RELEASENOTES  COPYING  Makefile   redis.conf        sentinel.conf  utilsBUGS             deps     MANIFESTO  runtest           srcCONTRIBUTING     INSTALL  README     runtest-sentinel  tests

[linuxidc@localhost redis-2.8.19]$ mv ./redis.conf /usr/local/redis/etc/

[linuxidc@localhost redis-2.8.19]$ cd src

[linuxidc@localhost src]$  mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server /usr/local/redis/bin/

Step 4: Start the Redis service:

First enter the directory where redis was just installed:

[linuxidc@localhost src]$ cd /usr/local/redis/bin

[linuxidc@localhost bin]$ ls

mkreleasehdr.sh  redis-check-aof   redis-cli       redis-server

redis-benchmark  redis-check-dump  redis-sentinel

After that we start the redis service. To start the redis service, you need to use the command redis-server

[linuxidc@localhost bin]$ ./redis-server

result:

 

However, in doing so, we did not use the configuration file under etc for startup (the red line in the figure).

If you want to start through the specified configuration file, you need to specify the configuration file at startup:

Here we first use ctrl+C to terminate the service, then check whether the redis service is terminated cleanly, and then start the service by setting the configuration file:

After pressing ctrl+c (^C):

^C[32138 | signal handler] (1463921540) Received SIGINT scheduling shutdown...[32138] 22 May 20:52:20.380 # User requested shutdown...[32138] 22 May 20:52:20.380 * Saving the final RDB snapshot before exiting.[32138] 22 May 20:52:20.393 * DB saved on disk[32138] 22 May 20:52:20.393 # Redis is now ready to exit, bye bye...

Run: pstree -p | grep redis and find that the redis service has been terminated cleanly

Now we run redis with the configuration file /usr/local/etc/redis.conf

[linuxidc@localhost bin]$ ./redis-server /usr/local/redis/etc/redis.conf

 

However, now redis is still running in the foreground.

What if I want to start it in the background?

Here we use -- & ? May I?

The answer is no, Redis needs to be set by parameters in the configuration file to start and run in the background. If you need to run in the background, change the daemonize configuration item to yes

vim /usr/local/redis/etc/redis.conf

Search : '\daemonize'  Change
the daemonize configuration item to yes, 
save and exit

After that we start redis-server again using the configuration file .

As you can see, redis is started in the background, and you can see that redis is running through the ps command.

[linuxidc@localhost bin]\$ ./redis-server /usr/local/redis/etc/redis.conf

[linuxidc @ localhost bin] \ $ ps -ef | grep redis

root     13154     1  0 22:53 ?        00:00:00 ./redis-server *:6379

neil 13162 8143 0 22:54 pts / 0 00:00:00 grep --color = auto redis

[linuxidc @ localhost bin] $ pstree -p | grep redis

           |-redis-server(13154)-+-{redis-server}(13156)

           |                     `-{redis-server}(13157)

The default connection port of the Redis server is 6379.

It 's like the default connection port of MySQL or mariadb server is 3306

In normal times, we often need to check whether port 6379 is occupied. You can use the following commands:

netstat -tunpl | grep 6379

Note that the redis service requires root privileges to view, otherwise, you can check that 6379 is occupied by a process, but you cannot see the process name.

So far, the redis service has been successfully started according to the configuration file! !

Step 5: Client login

[linuxidc@localhost bin]$ /usr/local/redis/bin/redis-cli

If prompted after carriage return:

[linuxidc@localhost bin]$ /usr/local/redis/bin/redis-cli127.0.0.1:6379>//Prompt

Indicates that the client has successfully logged in

Step 6: Shut down the Redis service

Stop the Redis instance

We can use pkill redis-server

[linuxidc@localhost bin]$ pkill redis-server

[linuxidc @ localhost bin] $ netstat -tunpl | grep 6379

[linuxidc@localhost bin]$

[linuxidc @ localhost bin] $ pstree -p | grep redis

[linuxidc@localhost bin]$

[linuxidc@localhost bin]$

[linuxidc@localhost bin]$ /usr/local/redis/bin/redis-cli Could not connect to Redis at 127.0.0.1:6379: Connection refusednot connected> not connected> exit

After closing, it was found that 6379 was no longer occupied, and the redis process was gone.

Customer login also failed.

You can also use /usr/local/redis/bin/redis-cli shutdown, this method uses the client command redis-cli to stop the Redis service

[linuxidc@localhost bin]]$ ./redis-server /usr/local/redis/etc/redis.conf

[linuxidc @ localhost bin] $ pstree -p | grep redis

           |-redis-server(13509)-+-{redis-server}(13511)

           |                     `-{redis-server}(13512)

[linuxidc@localhost bin]$ /usr/local/redis/bin/redis-cli shutdown

[linuxidc @ localhost bin] $ pstree -p | grep redis

[linuxidc@localhost bin]$

[linuxidc @ localhost bin] $ sudo netstat -tunpl | grep 6379

[linuxidc@localhost bin]$

Of course, you can also use killall and kill -9 to close a service.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325195790&siteId=291194637