Linux under Redis installation and self-boot configuration __linux

Source: Internet
Author: User
Tags file copy redis

Redis is a C-implemented, data-based, persistent key-value pair database that is often used as a caching service in distributed services. This article describes how to install from scratch to the configuration start service under CentOS. I. Installation of Redis

Redis installation is actually quite simple, the recommended way is to download the Redis source code, and after the installation of the machine compiled.

First access to the home folder download directory, the implementation of wget download source code

[zhxilin@localhost ~]$ cd download
[zhxilin@localhost download]$ wget http://download.redis.io/redis-stable.tar.gz

Next unpack, move to the/usr/redis directory

[ZHXILIN@LOCALHOST download]$ tar-zxvf redis-stable.tar.gz 
[zhxilin@localhost download]$ su mv Redis-stable/usr/redis

Then enter the Redis directory, execute make command, compile Redis source

[ROOT@LOCALHOST download]# cd/usr/redis/
[root@localhost redis]# make

After compiling, there are 2 important programs generated in the SRC directory, one is Redis-server, the other is REDIS-CLI, then enters the SRC directory, executes make install, then copies the executable to the/usr/local/bin directory, Because the/usr/local/bin is defined under the system's environment variable $path, the terminal can perform redis-server and redis-cli at any location.

[root@localhost redis]# cd src/
[root@localhost src]# make install

The work on installing Redis is complete.

Let's take a look at some of the compiled programs:

Redis-server: As the name suggests, Redis service

Redis-cli:redis client, providing a REDIS clients to connect to Redis services, and perform additional checks and deletions

Redis-sentinel:redis Instance monitoring management, notification and instance failure provisioning services

Performance testing tools for Redis-benchmark:redis

Redis-check-aof: To be used for quick fixes when an accident occurs, if it is persisted in a aof manner

Redis-check-rdb: To be used for quick fixes when an accident occurs, if it is persisted in a rdb manner

After the installation is complete, start Redis-server and run Redis-cli for testing

[Zhxilin@localhost ~]$ Redis-server
[Zhxilin@localhost ~]$ redis-cli 
127.0.0.1:6379> PING
PONG

This means that the Redis service is working properly and if the Redis service is not started, the error could the not connect to Redis at 127.0.0.1:6379:connection refused is reported when running REDIS-CLI.

two. Configure Self-startup

In order for Redis-server to run automatically when the system starts, we need to run the Redis service as a daemon (daemon) and we'll go back to/usr/redis/ Directory to find a redis.conf file, this file is the Redis service runtime load configuration, we first look at the contents of the

The contents of this file are very long, but most of them are annotations, and we focus on several of these settings daemonize and Pidfile:

Where the daemonize default is the False,pidfile default value is Pidfile/var/run/redis_6379.pid

The first one says whether it is daemon, obviously we should change it to daemonize yes;

The second means that when the service is running as a daemon, Redis writes the PID to the/var/run/redis_6379.pid file, the file exists in the service run, and the service is automatically deleted when the file is stopped, so it can be used to determine if the Redis is running.

Exit after saving.

With the basic configuration, Redis also needs to have a script that manages startup, shutdown, and restart. Redis source code In fact has provided an initialization script, located in/usr/redis/utils/redis_init_script.

Let's take a look at what this script does:

#!/bin/sh# redisport=6379 exec=/usr/local/bin/redis-server cliexec=/usr/local/bin/redis-cli PIDFILE=/var/run/redis
                _${redisport}.pid conf= "/etc/redis/${redisport}.conf" case "" in Start "if [-f $PIDFILE] Then echo "$PIDFILE exists, process is already running or crashed" else echo "starting Red
    Is server ... "$EXEC $CONF fi;;
        STOP) if [! f $PIDFILE] then echo "$PIDFILE does not exist, process isn't running" Else pid=$ (cat $PIDFILE) echo "Stopping ..." $CLIEXEC-P $REDISPORT s Hutdown while [-x/proc/${pid}] doing echo waiting for Redis to Shutdo
    WN ... "Sleep 1 Redis stopped" FI;
*) echo "Please use start or stop as the" "argument";; Esac

The script specifies the port, the server path, the CLI path, the Pidfile path, and the Conf path, all of which need to be configured correctly, and if make install is executed at installation time, the script here does not require much change because make Install both the server and the CLI under the/usr/local/bin.

See also here the path of Conf, we need to Redis directory of redis.conf file copy to/etc/redis/6379.conf

[Root@localhost utils]# cd/etc
[root@localhost etc]# mkdir

Then copy the Redis_init_script script to the/ETC/INIT.D/REDISD

The scripts under/ETC/INIT.D are services that can be started automatically at system startup, and there is now a system startup configuration:

[Root@localhost zhxilin]# chkconfig REDISD on

Then you'll find an error: The service REDISD does not support chkconfig.

Referring to this article, this is because we need to add a small change to the beginning of the Redis_init_script:

#!/bin/sh

# Description:redis is a persistent key-value database

As for what the 2345 90 10 represent, please refer to the article link above.

After you save the copy to the/ETC/INIT.D/REDISD, run the chkconfig and complete it.

When you are ready, you can perform the following command to verify that the service is set up successfully:

[root@localhost zhxilin]# service REDISD start 
[root@localhost zhxilin]# service REDISD stop

Equivalent to

[Root@localhost zhxilin]#/ETC/INIT.D/REDISD start 
[root@localhost zhxilin]#/ETC/INIT.D/REDISD Stop

Finally restart the system, after entering the system directly run REDIS-CLI Test Redis service has been automatically run.

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.