Redis installation Deployment on CENTOS7

Source: Internet
Author: User
Tags benchmark redis version signal handler pkill install redis redis server

Introduction :

Redis is an advanced Key-value database. It's similar to memcached, but data can be persisted and supported with rich data types. There are strings, lists, sets, and ordered collections. Support for computing collections on the server side, difference, and so on, also supports a variety of sorting functions. So Redis can also be viewed as a data structure server.

All the data in Redis is stored in memory (high efficiency), it is then periodically saved to disk asynchronously (this is called a "semi-persistent mode"), or it can be written to a append only file (AOF) (this is called "Total persistence mode") for each data change.

For more information on Redis please refer to the Redis official website in Chinese, where I only give the Redis on CENTOS7 installation deployment.

Step One: Download the Redis installation package

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

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

Step Two: Compiling the source program

Decompression and compilation

TAR-ZXVF redis-2.8.19.tar.gz
CD redis-2.8.19/src
//compile
make

... here is a large number of compilation procedures, omitted. There may be some warning, do not go to the official they ...
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 for installation:

CD src make
Install

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 point, we can look at the files under src:

You can see that at this point, some green files appear under the SRC folder, which is the command file we need to use later.

Step Three: Move the file

Move files for ease of administration: (all source code installed software is installed under/usr/local, such as Apache, etc.)

Create two folders, the bin is used to store commands, etc has a storage configuration file.

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

-P is recursive creation.

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

and move the 7 command files (green) under the SRC directory to/usr/local/redis/bin/

[Lsgozi@localhost src]$ cd ...
[Lsgozi@localhost redis-2.8.19]$ ls
00-releasenotes  copying  Makefile   redis.conf        sentinel.conf  utils
BUGS             deps     manifesto  runtest           src     contributing  README     Runtest-sentinel  tests
[lsgozi@localhost redis-2.8.19]$ mv./redis.conf/usr/local/ redis/etc/
[lsgozi@localhost redis-2.8.19]$ cd src
[lsgozi@localhost src]$  MV mkreleasehdr.sh Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server/usr/local/redis/bin/

Step four: Start the Redis service:

First go to the directory where you just installed Redis:

[Lsgozi@localhost src]$ cd/usr/local/redis/bin
[lsgozi@localhost bin]$ ls
mkreleasehdr.sh  Redis-check-aof   redis-cli       redis-server
redis-benchmark  redis-check-dump  Redis-sentinel

Then we start the Redis service. Command required to start Redis service Redis-server

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

Results:

However, to do so, we do not use the "etc" configuration file to start (the Red line part of the figure).

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

Here we first use CTRL + C to terminate the service, and then see if the Redis service is terminated cleanly, and then start the service by setting up a profile:

Press CTRL + C (^C):

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

Run: pstree-p | grep Redis found Redis service has been terminated cleanly

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

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

But now Redis is still running in the foreground.

What if you want to start the background?

Here we use--throw commands directly into the background of "execute" &. May I.

The answer is no, Redis's background startup and running needs to be set through the parameters in the configuration file. 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 exit

We then use the configuration file to start Redis-server again.

As you can see, the Redis is started in the background, and the PS command lets you see that Redis is running.

[Lsgozi@localhost bin]\$./redis-server/usr/local/redis/etc/redis.conf
[lsgozi@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
[lsgozi@localhost bin]$ pstree-p | grep redis
           |-redis-server (13154)-+-{redis-server} (13156)
           |                     '-{redis-server} (13157)

The Redis server-side default connection port is 6379.

Like the MySQL or mariadb server, the default connection port is 3306.

In peacetime, we often need to see if 6379 ports are occupied. You can use the following command:

NETSTAT-TUNPL | grep 6379

Note that the Redis service requires root permission to view, or you can only check that 6379 is consumed by a process, but the process name is not visible.

At this point, the Redis service has been successfully started according to the configuration file.

Step five: Client login

If prompted after carriage return:

[Lsgozi@localhost bin]$/usr/local/redis/bin/redis-cli
127.0.0.1:6379>//hint

Indicates that the client is logged on successfully

Step Six: Turn off the Redis service

Stop Redis Instance

We can use Pkill redis-server

[Lsgozi@localhost bin]$ pkill redis-server
[lsgozi@localhost bin]$ netstat-tunpl | grep 6379
[lsgozi@localhost bin]$ 
[lsgozi@localhost bin]$ pstree-p | grep redis
[lsgozi@localhost bin]$ 
[lsgozi@localhost bin]$ 
[ Lsgozi@localhost bin]$/usr/local/redis/bin/redis-cli 
could not connect to Redis at 127.0.0.1:6379:connection Refused not
connected> not 
connected> exit

After the shutdown, the discovery of 6379 was no longer occupied, and the Redis process was gone.

Client landing is not successful.

You can also use the/USR/LOCAL/REDIS/BIN/REDIS-CLI shutdown, which uses the client command REDIS-CLI to stop the Redis service

[Lsgozi@localhost bin]] $./redis-server/usr/local/redis/etc/redis.conf
[lsgozi@localhost bin]$ pstree-p | grep redis
           |-redis-server (13509)-+-{redis-server} (13511)
           |                     '-{redis-server} (13512)
[lsgozi@localhost bin]$/usr/local/redis/bin/redis-cli shutdown
[lsgozi@localhost bin]$ Pstree-p | grep redis
[lsgozi@localhost bin]$ 
[lsgozi@localhost bin]$ sudo netstat-tunpl | grep 6379

Of course, closing a service can also use Killall and kill-9.

Appendix: More about/usr/local/redis/etc/redis.conf configuration information

1, daemonize if need to run in the background, change the item to Yes

2, pidfile configuration of multiple PID address default in/var/run/redis.pid

3, bind binding IP, set up to accept only requests from the IP

4, port listening ports, the default is 6379

5, LogLevel divided into 4 levels: Debug verbose notice warning

6, logfile used to configure log file address

7, databases set the number of databases, the default use of the database is 0

8, save set Redis the frequency of database mirroring.

9, rdbcompression in the mirror backup, whether to compress

10. Dbfilename the filename of the mirrored backup file

11. Dir Database Mirrored backup file placement path

12, Slaveof set database for other databases from the database

13, Masterauth The main database connection needs password Authentication

14, Requriepass set login need to use the password

15, MaxClients limit the number of customers to use at the same time

16, MaxMemory set Redis can use the maximum memory

17, AppendOnly open Append only mode

18, Appendfsync Set the frequency of appendonly.aof file synchronization (the second way to back up the data)

19. Vm-enabled Open Virtual memory support (the parameters at the beginning of the VM are configured with virtual memory)

20, Vm-swap-file set the virtual memory of the swap file path

21. Vm-max-memory set the maximum physical memory size used by Redis

22, Vm-page-size set the virtual memory page size

23, Vm-pages set the total page number of the swap file

24, Vm-max-threads set VM IO Simultaneous use of the number of threads

25, Glueoutputbuf to store small output cache together

26, Hash-max-zipmap-entries set the critical value of the hash

27, Activerehashing again hash

This blog mainly refers to the installation and deployment of Redis and maintenance detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.