Redis installation under Linux

Source: Internet
Author: User
Tags redis version root access install redis

Installation Environment:

linux:centos6.9 64-bit

Redis version: redis-4.0.2.tar.gz


Redis Installation

Redis website Address: http://www.redis.io/

Currently the latest version is 4.0.2

1. Download the source code and compile the source code after decompression

[Email protected] ~]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz

[Email protected] ~]# tar-xfredis-4.0.2.tar.gz

[Email protected] ~]# CD redis-4.0.2

[[email protected] redis-4.0.2]# make

2, make compile completed, we see the following interface, indicating that we have successfully installed.

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/05/b6be09f15c2cee40e84fc6dcd9ced161.jpg-wh_500x0-wm_3 -wmp_4-s_1726444301.jpg "title=" 1.jpg "alt=" B6be09f15c2cee40e84fc6dcd9ced161.jpg-wh_ "/>

We will see a few more executables in the REDIS-4.0.2/SRC directory, where Redis-server is used to start the service, REDIS-CLI is used to start the client, the other is not clear, we can check.

After the default make, we start the Redis service, we have to go to the installation directory each time, so it is very cumbersome, so we can do after the make install, will put the generated binary files into the/usr/local/bin directory

Make install

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/05/a772cec0f12ce3458ca81f28a8e54af3.jpg-wh_500x0-wm_3 -wmp_4-s_1074480221.jpg "title=" 3.jpg "alt=" A772cec0f12ce3458ca81f28a8e54af3.jpg-wh_ "/>

Note: If a normal user is required to perform the make install and requires root access, use sudo to install the


3. Set up service

First copy the Redis-4.0.2/utils/redis_init_script file to/etc/init.d, and also to the name Redis. Execute command

CP Redis-4.0.2/utils/redis_init_script/etc/init.d/redis

Vi/etc/rc.d/init.d/redis

Add in the second line of the document

# chkconfig:234580 90.

Make sure that there are redis-server and redis-cli files in the/usr/local/redis/bin (if some people install it without the make install command, it is necessary to copy redis-server and REDIS-CLI to/from the installation directory) Usr/local/redis/bin directory, otherwise the service cannot be found at startup Redis-server) The second red box is shown.

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/05/dd568b37e637ada8859873bacd8cb70c.jpg-wh_500x0-wm_3 -wmp_4-s_450360013.jpg "title=" 4.jpg "alt=" Dd568b37e637ada8859873bacd8cb70c.jpg-wh_ "/>

You can see this line in the/etc/init.d/redis file: conf= "/etc/redis/${redisport}.conf". The Redis configuration file is then copied to/etc/redis/and is easily named 7200.conf.

MKDIR/ETC/REDISCP redis-4.0.2/redis.conf/etc/redis/7200.conf


4. Modify the 7200.conf configuration file

#  Specifies the port that Redis runs on, by default 6379port 7200#daemonize no  Redis is not running in the background by default, and if it needs to run in the background, Change the value of the item to yesdaemonize yes #  when Redis is running in the background, Redis defaults to placing the PID file in/var/run/redis.pid, which you can configure to a different address. #  when running multiple Redis services, you need to specify a different PID file and port #pidfile /var/run/redis_6379.pid pidfile /var/run/redis_ 7200.pid  #  Specifies that Redis receives only requests from that IP address, and if not set, all requests are processed,#  it is best to set the item in the production environment # bind  127.0.0.1#  the time-out period, in seconds, when a client connection is set. When the client has not issued any instructions during this time, close the connection # 0 This setting timeout 0 #  specify the logging level # redis a total of four levels are supported: Debug, verbose, Notice, warning, the default is verbose# debug         record a lot of information for development and testing #  varbose       useful information, unlike debug will record so many # notice   common verbose, often used in production environment #  warning       only very important or critical information is logged to the log loglevel debug #  configuration log file address #   Default value is stdout, standard output, if background mode is output to/dev/null#logfile stdoutlogfile /var/log/redis/redis.log


5, the background start two ways

The default Redis boot service will monopolize the input screen and there are two ways to start in the background:

A, found in the/etc/init.d/redis $exec $CONF behind add a &, which means to have Redis as a background service start B, modify the Redis configuration file?. Conf (/etc/redis/7200.conf) will #daemonize no some options to configure the foreground or background boot, if background startup is set to Yes)


6. Join Service Management

After you complete the above actions, you can register the service:

Chkconfig--add Redis

Then start the Redis service

Service Redis Start

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/05/a3fc040cfa8d2bdef2f96a01e92fe0ff.jpg-wh_500x0-wm_3 -wmp_4-s_3105356594.jpg "title=" 7.jpg "alt=" A3fc040cfa8d2bdef2f96a01e92fe0ff.jpg-wh_ "/>

This allows us to register the Redis service.


If service Redis stop, there is a hint/var/run/redis_7200.pid does not exist, process is not running

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/05/423d823244dcb04fe6ab0debd39dde9a.jpg-wh_500x0-wm_3 -wmp_4-s_3393285007.jpg "title=" 5.jpg "alt=" 423d823244dcb04fe6ab0debd39dde9a.jpg-wh_ "/>

This shows that there is no this file under Run, we entered into the/var/run issued first really did not have this file, but there are redis.pid files.

Workaround:

A, modify the redis_${redisport}.pid in the/etc/rc.d/init.d/redis file to Redis.pidb, modify the pidfile/var/run/in the 7200.conf configuration file Redis.pid is Pidfile/var/run/redis_7200.pid, the PID is generated before the deletion, and the Redis_7200.pid file is generated when the reboot occurs.

So after we restart the service, we can close it with this command. Here our Redis service is installed, and a service is done.

The above is the entire process of installing Redis under Linux, and I hope to help you install Redis.


With Redis startup script:

#!/bin/sh# chkconfig: 2345 80 90## simple redis init.d script  conceived to work on linux systems# as it does use of  The /proc filesystem. redisport=7200exec=/usr/local/bin/redis-servercliexec=/usr/local/bin/redis-clipidfile=/var/run/redis_${ redisport}.pidconf= "/etc/redis/${redisport}.conf" case  "$"  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 &NBSP: "                $ 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


This article is from "Operation and maintenance record Mei Ling" blog, please be sure to keep this source http://meiling.blog.51cto.com/6220221/1979156

Redis installation under Linux

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.