Linux test Environment Deployment Redis (iv)

Source: Internet
Author: User
Tags install redis redis server

Installing the configuration Redis

Part I: Installing Redis
Want to install Redis to this directory

1

/usr/local/redis

You want to download the installation package to this directory

1

/usr/local/src

Then the installation process instructions are as follows:

1

2

3

4

5

6

7

$ 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, so you can install it via yum:

1

Yum Install GCC

After the installation is complete, continue with make.

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

1

Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server

Part II: Making Redis a service

1. Copy the script to the/ETC/RC.D/INIT.D directory
PS: The script in the /etc/rc.d/init.d/ directory is similar to the registry in Windows, and some of the specified scripts will be executed when the system is started
When you install Redis as per the above steps, its service script is located at:

1

/usr/local/src/redis/utils/redis_init_script

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

1

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

Copy the Redis_init_script to/etc/rc.d/init.d/and easily name Redis.

If you add a registration service at this point:

1

Chkconfig--add Redis

The following error will be reported:

1

Redis service does not support Chkconfig

To do this, we need to change the Redis script.

2. Change the Redis script
Open the script using VI to view the script information:

1

Vim/etc/rc.d/init.d/redis

What you see is as follows (the following is a change of good information):

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

#!/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=6379

Exec=/usr/local/redis/bin/redis-server

Cliexec=/usr/local/redis/bin/redis-cli

Pidfile=/var/run/redis_${redisport}.pid

conf= "/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 was 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

Compared to the original configuration file:

1. The original document does not have the contents of line 2nd below,

1

#chkconfig: 2345 80 90

2. The original file exec, cliexec parameters, is also changed.

1

2

Exec=/usr/local/redis/bin/redis-server

Cliexec=/usr/local/redis/bin/redis-cli

3.redis commands that are enabled to run in the background.

1

$EXEC $CONF &

PS: Note that the "&" in the back, that is, to move the service back to the meaning of running, otherwise 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

1

2

Mkdir/etc/redis

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 Yedis service:

1

Chkconfig--add Redis

3. Start the Redis service

1

Service Redis Start

Third, add the directory where the Redis command resides to the system parameter path

To modify a profile:

1

Vi/etc/profile

Append in last line:

1

Export path= "$PATH:/usr/local/redis/bin"

Then apply this file immediately:

1

. /etc/profile

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

1

2

3

4

5

6

$ redis-cli

Redis 127.0.0.1:6379> Auth Superman

Ok

Redis 127.0.0.1:6379> Ping

PONG

Redis 127.0.0.1:6379>

At this point, Redis is installed successfully.

Summary: Installing Redis in a Linux system can be more or less problematic. In this installation, 3 of the most
1. Download, install, use here to the wget command, make command, I do not understand the use of make command, and always worry about how the make command installed in the specified directory, this time finally understand.
2. How to add a program to the service, of course, also have a knowledge of/etc/rc.d/init.d this file.
3. How to add some commands of a program to the system parameters, enter the command directly to achieve the operation of a program.
is to specify a good environment variable.

(GO) Linux test Environment Deployment Redis (iv)

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.