Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis series-1, environment installation, connection

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Yum installs radis

1. Add Epel source for yum: yum install epel-release

2 、 yum install redis

3. Find /-name "redis*"

Install the latest version of Redis

To download http://redis.io/download

Tar-zxvf redis-3.2.1.tar.gzmake & & make install

This will install Redis on your computer.

Start Redis

$redis-server

Check if Redis is working?

$redis-cli

This opens a Redis prompt, as shown in the following figure:

Redis 127.0.0.1 purl 6379 >

The above prompt 127.0.0.1 is the local IP address, and 6379 is the port on which the Redis server is running. Now enter the PING command, as shown in the following figure.

Redis 127.0.0.1 6379 > ping

This indicates that you have successfully installed Redis on your machine.

Install Redis Desktop Manager on Ubuntu

To install Redis Desktop Management on Ubuntu, simply download the package from http://redisdesktop.com/download and install it.

The Redis Desktop Manager provides a user interface to manage Redis keys and data.

Run commands on a remote server

To run commands on a Redis remote server, you need to connect to the server through the same client redis-cli

Syntax $redis-cli-h host-p port-a password for example

The following example shows how to connect to a remote server on Redis host: 127.0.0.1, port: 6379, plus the authentication password: mypass.

$redis-cli-h 127.0.0.1-p 6379-a "mypass" III. Redis connection command

S.N. Command and description 1AUTH password

The server validates the given password 2ECHO message

Print the given string 3PING

Check if the server is running 4QUIT

Close the current connection 5SELECT index

Change the selected database for the current connection

4. Install radis under linux

Part one: install redis

Want to install redis to this directory

one

/ usr/local/redis

Want to download the installation package to this directory

one

/ usr/local/src

Then the installation process instructions are as follows:

one

two

three

four

five

six

seven

$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 # make a link

$cd redis

$make PREFIX=/usr/local/redis install # installed in the specified directory

Notice that in the last line above, we specified the installation directory through PREFIX. If make fails, generally speaking, gcc is not installed on your system, then you can install it through yum:

one

Yum install gcc

After the installation is complete, continue to execute make.

After installing redis successfully, you will see a bin directory in / usr/local/redis that contains the following files:

one

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

Part two: make redis into a service

1. Copy the script to the / etc/rc.d/init.d directory

The script in the ps: / etc/rc.d/init.d/ directory is similar to the registry in windows, and some specified scripts will be executed when the system starts.

When you install Redis by following the steps above, its service script is located at:

one

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

It must be copied to the directory of / etc/rc.d/init.d:

one

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

Copy redis_init_script to / etc/rc.d/init.d/, and rename it to redis.

If you add a registration service at this time:

one

Chkconfig-add redis

The following error will be reported:

one

Redis service does not support chkconfig

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

two。 Change the redis script

Open the script using vi to view the script information:

one

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

What you see is as follows (the following is the changed information):

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

thirty

thirty-one

thirty-two

thirty-three

thirty-four

thirty-five

thirty-six

thirty-seven

thirty-eight

thirty-nine

forty

forty-one

forty-two

#! / 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 "$1" 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..."

$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 profile:

1. The original file does not contain the following line 2

one

# chkconfig: 2345 80 90

two。 The parameters of the original file EXEC and CLIEXEC have also been changed.

one

two

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

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

The command opened by 3.redis is executed in the background.

one

$EXEC $CONF &

Ps: pay attention to the following "&", which means to transfer the service to run later, otherwise, when the service is started, the Redis service will

Occupy the foreground, occupy the main user interface, so that other commands can not be executed.

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

one

two

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 enable authentication, and you can specify an authentication password through the requirepass that turns on 6379.conf.

After the above operations are completed, you can register the yedis service:

one

Chkconfig-add redis

3. Start the redis service

one

Service redis start

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

Modify the profile file:

one

Vi / etc/profile

Append to the last line:

one

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

Then apply this file immediately:

one

. / etc/profile

This allows you to invoke the redis-cli command directly, as shown below:

one

two

three

four

five

six

$redis-cli

Redis 127.0.0.1 6379 > auth superman

OK

Redis 127.0.0.1 6379 > ping

PONG

Redis 127.0.0.1 purl 6379 >

At this point, redis is successfully installed.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report