Compile and install Redis in RedHat5.8 environment and register it as a system service

Source: Internet
Author: User
Tags redis download redis cluster
System Environment: $ cat/etc/issueRedHatEnterpriseLinuxServerrelease5.8 (Tikanga) Kernel \ ronan \ m1. download and install. 1.1 download official: Workshop. 1.2 install and place the downloaded installation package in

System Environment:
$ Cat/etc/issue
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
Kernel \ r on an \ m

1. Download and install 1.1

Http://redis.io/download
Download the latest stable redis-3.0.4.tar.gz, which is only 1.3 MB in size.

1.2 Installation

Put the downloaded installation package in the user directory, as shown in figure/Home/webapp, Intends to install it/Opt/redis:
$ Sudo mkdir/opt/redis
$ Cd/home/webapp
$ Tar xzf redis-3.0.4.tar.gz
$ Redis-3.0.4 cd
$ Sudo make PREFIX =/opt/redis install

View later/Opt/redisOnly one directory is generated below. There are only six files in this directory:
Redis-benchmark redis-check-dump redis-sentinel
Redis-check-aof redis-cli redis-server
Installation is complete.

2. Register as System Service 2.1 edit service script

View the service script that comes with the installation package:
$ Cat/home/webapps/redis-3.0.4/utils/redis_init_script
#! /Bin/sh
#
# Simple Redis init. d script conceived to work on Linux systems
# As it does use of the/proc filesystem.

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 "$1" in
Start)
If [-f $ PIDFILE]
Then
Echo "$ PIDFILE exists, process is already running or crashed"
Else
Echo "Starting Redis server ..."
$ EXEC $ CONF
Fi
;;
Stop)
If [! -F $ PIDFILE]
Then
Echo "$ PIDFILE does not exist, process is not running"
Else
PID = $ (cat $ PIDFILE)
Echo "Stopping ..."
$ CLIEXEC-p $ REDISPORT shutdown
While [-x/proc/$ {PID}]
Do
Echo "Waiting for Redis to shutdown ..."
Sleep 1
Done
Echo "Redis stopped"
Fi
;;
*)
Echo "Please use start or stop as first argument"
;;
Esac
Copy it/Etc/rc. d/init. dDirectory and rename itRedis:
$ Sudo cp/home/webapps/redis-3.0.4/utils/redis_init_script/etc/rc. d/init. d/redis
Then, based onRedisInstallation path modification/Etc/rc. d/init. d/redisIs:
#! /Bin/sh
# Chkconfig: 2345 90 10
# Description: Redis is a persistent key-value database
# Simple Redis init. d script conceived to work on Linux systems
# As it does use of the/proc filesystem.

REDISPORT = 6379
EXEC =/opt/redis/bin/redis-server
CLIEXEC =/opt/redis/bin/redis-cli

PIDFILE =/var/run/redis _ $ {REDISPORT}. pid
CONF = "/opt/redis/$ {REDISPORT}. conf"

Case "$1" in
Start)
If [-f $ PIDFILE]
Then
Echo "$ PIDFILE exists, process is already running or crashed"
Else
Echo "Starting Redis server ..."
$ EXEC $ CONF &
Fi
;;
Stop)
If [! -F $ PIDFILE]
Then
Echo "$ PIDFILE does not exist, process is not running"
Else
PID = $ (cat $ PIDFILE)
Echo "Stopping ..."
$ CLIEXEC-p $ REDISPORT shutdown
While [-x/proc/$ {PID}]
Do
Echo "Waiting for Redis to shutdown ..."
Sleep 1
Done
Echo "Redis stopped"
Fi
;;
*)
Echo "Please use start or stop as first argument"
;;
Esac
Note:

  • Chkconfig,DescriptionThe two lines of comment are required. Either line is required. Otherwise, service redis does not support chkconfig;
  • $ EXEC $ CONF &, Followed&To forward the service to the backend;
  • EXEC,CLIEXEC,CONFAnd so on.
2.2 copy the configuration file

Set/Home/webapp/redis-3.0.4ProvidedRedis. confCopy the configuration fileRedisInstall the root directory and rename it6379. conf:
$ Cp/home/webapp/redis-3.0.4/redis. conf/opt/redis/6379. conf

2.3 set Environment Variables

Append the following content/Etc/profileFile:
/Opt/redis/bin:/sbin: $ PATH
Run./Etc/profileTo make the configuration take effect immediately and useEcho $ PATHVerify.

2.4 Service Registration

$ Chkconfig -- add redis
No news is good news. No output proves that the service is successfully registered.
If chkconfig command not found is prompted, firstRpm-q chkconfigCheck whether the installation is complete.Chkconfig, If installed, checkPATHIs there/Sbin.

3. Start and verify the service

$ Sudo service redis start
Start and execute the service
$ Redis-cli ping
PONG
Indicates that the service has been started.

References
  • Redis Download
  • Redis Quick Start

You may also like the following articles about Redis. For details, refer:

Install and test Redis in Ubuntu 14.04Http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis master-slave replication basic configuration http://www.linuxidc.com/Linux/2015-03/115610.htm

Redis cluster details document http://www.linuxidc.com/Linux/2013-09/90118.htm

Ubuntu 12.10 install Redis (graphic details) + Jedis connection Redis http://www.linuxidc.com/Linux/2013-06/85816.htm

Redis series-installation, deployment, maintenance http://www.linuxidc.com/Linux/2012-12/75627.htm

CentOS 6.3 install Redis http://www.linuxidc.com/Linux/2012-12/75314.htm

Redis installation deployment learning notes http://www.linuxidc.com/Linux/2014-07/104306.htm

Redis configuration file redis. conf detailed description http://www.linuxidc.com/Linux/2013-11/92524.htm

Redis details: Click here
Redis: Click here

For more information about RedHat, see RedHat topic page http://www.linuxidc.com/topicnews.aspx? Tid = 10

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-09/123288.htm

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.