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

Source: Internet
Author: User
Tags install redis

Compile and install Redis in Redhat5.8 environment and register it as a system service
System Environment:
$ Cat/etc/issue
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
Kernel \ r on an \ m
1. Download installation 1.1 download official: http://redis.io/download
Download the latest stable redis-3.0.4.tar.gz, which is only 1.3 MB in size.
1.2 install and 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 and edit the service script to view the built-in service script of the installation package:

$ cat /home/webapp/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=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/etc/redis/${REDISPORT}.conf"case "$1" instart)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed"elseecho "Starting Redis server..."$EXEC $CONFfi;;stop)if [ ! -f $PIDFILE ]thenecho "$PIDFILE does not exist, process is not running"elsePID=$(cat $PIDFILE)echo "Stopping ..."$CLIEXEC -p $REDISPORT shutdownwhile [ -x /proc/${PID} ]doecho "Waiting for Redis to shutdown ..."sleep 1doneecho "Redis stopped"fi;;*)echo "Please use start or stop as first argument";;esac

Copy it /Etc/rc. d/init. dDirectory and rename it Redis:
$ Sudo cp/home/webapps/redis-3.0.4/utils/redis_init_script/etc/rc. d/init. d/redis
Then, based on RedisInstallation 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=6379EXEC=/opt/redis/bin/redis-serverCLIEXEC=/opt/redis/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/opt/redis/${REDISPORT}.conf"case "$1" instart)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed"elseecho "Starting Redis server..."$EXEC $CONF &fi;;stop)if [ ! -f $PIDFILE ]thenecho "$PIDFILE does not exist, process is not running"elsePID=$(cat $PIDFILE)echo "Stopping ..."$CLIEXEC -p $REDISPORT shutdownwhile [ -x /proc/${PID} ]doecho "Waiting for Redis to shutdown ..."sleep 1doneecho "Redis stopped"fi;;*)echo "Please use start or stop as first argument";;esac

Note:
Chkconfig, DescriptionThe two lines must be annotated; 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 /Home/webapp/redis-3.0.4Provided Redis. confCopy the configuration file RedisInstall the root directory and rename it 6379. conf:
$ Cp/home/webapp/redis-3.0.4/redis. conf/opt/redis/6379. conf
2.3 Add the following content to the environment variable settings /Etc/profileFile:
/Opt/redis/bin:/sbin: $ PATH
Run ./Etc/profileTo make the configuration take effect immediately and use Echo $ 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, first Rpm-q chkconfigCheck whether the installation is complete. Chkconfig, If installed, check PATHIs 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.

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.