CentOS 6.9 Redis Installation and basic configuration (i)

Source: Internet
Author: User
Tags redis redis version

Use the following command to update the Yum source and install the Redis service:

RPM-UVH http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

Yuminstall-y Redis

Serviceredis start

Chkconfigredis on

After the installation, we found a strange problem (not sure if it is related to the Redis version, CentOS 7.4 did not encounter a similar problem):

We view the Redis service status:


But we're looking at the Redis service port listening Condition:


You can see that the Redis service is listening normally and can be connected locally using REDIS-CLI:


Understanding that Serviceredis status is actually going to invoke the status method of/etc/init.d/redis This script file, let's take a look at/etc/init.d/redis this file content (irrelevant part we use ...). Omitted):

#!/bin/sh

......

Name= "Redis-server"

exec= "/usr/bin/$name"

shut= "/usr/libexec/redis-shutdown"

Pidfile= "/var/run/redis_6379.pid"

Redis_config= "/etc/redis.conf"

......

Start () {

[f $REDIS _config] | | Exit 6

[x $exec] | | Exit 5

Echo-n $ "Starting $name:"

Daemon--user ${redis_user-redis} "$exec $REDIS _config--daemonize yes--pidfile $pidfile"

Retval=$?

Echo

[$retval-eq 0] && Touch $lockfile

Return $retval

}

......

Rh_status () {

Status-p $pidfile $name

}

Rh_status_q () {

Rh_status >/dev/null 2>&1

}

Case "$" in

Start

Rh_status_q && Exit 0

$

;;

Stop

Rh_status_q | | Exit 0

$

;;

Restart)

$

;;

Reload

Rh_status_q | | Exit 7

$

;;

Force-reload)

Force_reload

;;

Status

Rh_status

;;

Condrestart|try-restart)

Rh_status_q | | Exit 0

Restart

;;

*)

echo $ "Usage: $ {Start|stop|status|restart|condrestart|try-restart}"

Exit 2

Esac

Exit $?

We see that the Rh_status method is invoked when the Redisstatus parameter is invoked, which actually checks the PID file. Let's take a look at the start method, you will call/usr/bin/redis-server this execution file, corresponding to generate a PID file, see a daemonize parameter, to Redis configuration file to view this parameter and the PID file path:




You can see that the default Redis is run in daemon, but the path to the PID file in the configuration file is inconsistent with the path in the/etc/init.d/redis script file, so we try to modify the PID file path in the script: pidfile= "/var/run/ Redis.pid "

Try restarting the service again discovery still does not work, see/var/run There is no redis PID file generated below:


It's strange that Redis does not have permission to create a directory. Let's create a/var/run/redis directory by hand and assign a permission to the Redis User:


Try restarting the service again, this is normal:

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.