How to use Redis under Linux for installation

Source: Internet
Author: User

1, download the source package redis-2.8.21.tar.gz, and upload it to the specified directory /urs/src, and then unzip it:

[Email protected] src]# TAR-XVF redis-2.8.21.tar.gz

Enter the extracted directory and execute the following command to specify the installation directory as /urs/local/redis:

[Email protected] src]# CD redis-2.8.21

[[email protected] redis-2.8.21]# make Prefix=/usr/local/redis Install

After you have successfully installed Redis, you can See a bin directory in/usr/local/redis that includes the following files:

[Email protected] ~]# cd/usr/local/redis/bin/

[[email protected] bin]# ls

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

2. Add a program to the service:

Copy the script redis_init_script to the/ETC/RC.D/INIT.D directory and rename it to Redis(Note: /etc/rc.d/init.d/ The script in the directory will be executed when the system starts.

[Email protected] ~]# cd/usr/src/redis-2.8.21/utils/

[email protected] utils]# CP Redis_init_script/etc/rc.d/init.d/redis

to add Redis to the Enrollment service:

[Email protected] ~]# chkconfig--add Redis

Error:service Redis does not support Chkconfig

You need to modify the script RedisWhen you encounter this situation:

[Email protected] ~]# Vim/etc/init.d/redis

#chkconfig: 2345 // Newly added content

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

CLIEXEC=/USR/LOCAL/REDIS/BIN/REDIS-CLI // modified content

$EXEC $CONF &//redis commands to run in the background, the "&", which is the service

go to the back run meaning, otherwise when the service is started, theredis Service will occupy the foreground, occupying the main user interface, resulting in other // commands not being executed

After the modification, execute the following command:

[Email protected] ~]# chkconfig--add Redis

[Email protected] ~]# chkconfig--list Redis

Redis 0:off 1:off 2:on 3:on 4:on 5:on 6:off

To restart Redis, the following error occurred:

[[Email protected] ~]# service Redis start

Starting Redis Server ...

[6384] Jul 21:43:19.992 # Fatal error, can ' t open config file '/etc/redis/6379.conf '

Workaround:

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

[Email protected] ~]# Mkdir/etc/redis

[Email protected] ~]# cp/usr/src/redis-2.8.21/redis.conf/etc/redis/6379.conf

In this way, the conf specified by the Redis service script exists and, by default,Redis is not enabled for authentication by turning on the the requirepass of 6379.conf specifies a verification password;

Modify /etc/redis/6379.conf, set up the redis process as the daemon, and specify a password :

[Email protected] ~]# vim/etc/redis/6379.conf

Daemonize Yes//daemonize: Whether to run in the next station daemon mode

Requirepass 20082009// Set Password to 20082009

After Setup is complete, you can add a registration service:

[Email protected] ~]# chkconfig--add Redis

[[Email protected] ~]# service Redis start

Starting Redis Server ...

To see if the startup was successful:

[Email protected] ~]# Ps-ef | grep Redis

Root 2099 1 0 22:17? 00:00:00/usr/local/redis/bin/redis-server *:6379

Root 2475 2270 0 22:19 pts/1 00:00:00 grep redis

3, call redis-cli command for simple operation (note whether to start password Authentication):

[Email protected] ~]# REDIS-CLI

127.0.0.1:6379> Ping

(Error) Noauth Authentication required.

127.0.0.1:6379> auth 20082009 // need to enter a password

Ok

127.0.0.1:6379> Ping

PONG

127.0.0.1:6379> Set name LeBron James

(Error) ERR syntax error

127.0.0.1:6379> set name "LeBron James" /// string with spaces need to be added ""

Ok

127.0.0.1:6379> Get Name

"LeBron James"

127.0.0.1:6379> Set name Lebronjames

Ok

127.0.0.1:6379> Get Name

"Lebronjames"

127.0.0.1:6379>


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to use Redis under Linux for installation

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.