Installing the Redis complete process

Source: Internet
Author: User
Tags install redis

Overview
First report the version of my system:

Java code
    1. [Root@firefish init.d]# cat/etc/issue


The system version information is as follows:

Reference
CentOS Release 6.4 (Final)
Kernel \ r on an \m



Installing Redis

You want to install Redis under this directory:

Reference/usr/local/redis


Refer to the Http://redis.io/download installation instructions to make adjustments:

Reference
$ mkdir/usr/local/redis
$ cd/usr/local/src
$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
$ tar xzf redis-2.6.14.tar.gz
$ ln-s redis-2.6.14 Redis #建立一个链接
$ CD Redis
$ make Prefix=/usr/local/redis Install #安装到指定目录中


Note the last line above, we specified the installed directory through prefix. If make fails, it is common that GCC is not installed in your system and can be installed by Yum:

Java code
    1. Yum Install GCC


After the installation is complete, make is executed.

After you have successfully installed Redis, you will be able to see a bin directory in/usr/local/redis that includes the following files:

Java code
    1. Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server



Make Redis a service

1. Copy the script to the/ETC/RC.D/INIT.D directory

When you install Redis as per the above steps, its service script is located at:

Java code
    1. /usr/local/src/redis/utils/redis_init_script


It must be copied to the/ETC/RC.D/INIT.D directory:

Java code
    1. Cp/usr/local/src/redis/utils/redis_init_script/etc/rc.d/init.d/redis


The following copies the Redis_init_script to/etc/rc.d/init.d/and is easily named Redis.

If this is the case, we directly register the service:

Java code
    1. Chkconfig--add Redis


The following error will be reported:

Reference Redis service does not support Chkconfig


For some, we need to change the Redis script, see the next section for instructions.

2. Change the service script for Redis

Java code
    1. Vim/etc/rc.d/init.d/redis



See the following file contents:

Java code
  1. #!/bin/bash
  2. #chkconfig: 2345
  3. # simple Redis INIT.D script conceived to work on Linux systems
  4. # as it does use of the/proc filesystem.
  5. redisport=6379
  6. Exec=/usr/local/redis/bin/redis-server
  7. Cliexec=/usr/local/redis/bin/redis-cli
  8. Pidfile=/var/run/redis_${redisport}.pid
  9. conf="/etc/redis/${redisport}.conf"
  10. Case "$" in
  11. Start
  12. if [-F $PIDFILE]
  13. Then
  14. Echo "$PIDFILE exists, process is already running or crashed"
  15. Else
  16. echo "Starting Redis server ..."
  17. $EXEC $CONF &
  18. Fi
  19. ;;
  20. Stop
  21. if [!-F $PIDFILE]
  22. Then
  23. echo "$PIDFILE does not exist, process was not running"
  24. Else
  25. pid=$ (Cat $PIDFILE)
  26. echo "Stopping ..."
  27. $CLIEXEC-P $REDISPORT shutdown
  28. While [-x/proc/${pid}]
  29. Do
  30. echo "Waiting for Redis to shutdown ..."
  31. Sleep 1
  32. Done
  33. echo "Redis stopped"
  34. Fi
  35. ;;
  36. *)
  37. echo "Please use Start or stop as first argument"
  38. ;;
  39. Esac



1) Troubleshoot issues that cannot be registered:

The original file does not have the contents of line 2nd below,

Reference #chkconfig:2345 80 90


If the registration will be an error, to add re-registration is OK.

2) Change the exec, cliexec parameter, set the corresponding value, as shown above is consistent with our previous installation.

3) Change the Redis Open command to run in the background:

Java code
    1. $EXEC $CONF &


Notice that the "&" in the back is the meaning of moving the service to the back, or when the service is started, the Redis service will
Occupy the front desk, occupying the main user interface, resulting in other commands not being executed.

4) Copy the Redis configuration file to/etc/redis/${redisport}.conf

Java code
    1. Mkdir/etc/redis
    2. cp/usr/local/src/redis/redis.conf/etc/redis/6379.conf


In this way, the conf specified by the Redis service script exists. By default, Redis does not have authentication enabled, and you can specify a verification password by turning on the requirepass of 6379.conf.


Once the above operation is complete, you can register the service:

Java code
    1. Chkconfig--add Redis



3. Start the Redis service

Java code
    1. $ service Redis Start



Add the directory of the Redis command to the system parameter path

To modify a profile:
#vi/etc/profile
In the last line add:

Java code
    1. Export path="$PATH:/usr/local/redis/bin"


Then apply this file immediately:

Java code
    1. . /etc/profile



This makes it possible to invoke the REDIS-CLI command directly, as follows:

Java code
    1. $ redis-cli
    2. Redis 127.0. 0.1:6379> auth Superman
    3. Ok
    4. Redis 127.0. 0.1:6379> ping
    5. PONG
    6. Redis 127.0. 0.1:6379>


Because I turned on the security authentication feature above, the password is Superman, so I need to auth to interact with the server.

< finish >

Installing the Redis complete process

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.