The installation of redis on read hat6.0 and the use of the client command line

Construction and configuration of redis-3.0.6 in redhat-6.0 environment

 

Installation of redis:

Step 1: Download wget http://download.redis.io/releases/redis-3.0.6.tar.gz

Step 2: Unzip the tar xzf redis-3.0.6.tar.gz

Step 3: Enter the installation directory cd redis-3.0.6

Step 4: Compile make

 

Configure the redis service:

cp /usr/local/redis-2.8.9/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

then vi /etc/rc.d/init.d/redis

Add on the second line of the document

# chkconfig: 2345 80 90

then notice

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

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

Because our installation directory is /usr/local/redis-2.8.9, the above two lines are changed to

EXEC=/usr/local/redis-2.8.9/src/redis-server 

CLIEXEC=/usr/local/redis-2.8.9/src/redis-cli

Also pay attention to the redis file

$EXEC $CONF

Here, add & after CONF

$EXEC $CONF &

"&" means that the service is transferred to the back to run, otherwise, when the service is started, the Redis service will occupy the foreground, occupying the main user interface, and causing other commands to fail to execute.

 

4. You can see that in the /etc/init.d/redis file, there is such a line:

CONF="/etc/redis/${REDISPORT}.conf"

So copy the redis configuration file to /etc/redis/

mkdir /etc/redis  

cp /usr/local/redis-2.8.9/redis.conf /etc/redis/6379.conf

 

5. Configure the access password in 6379.conf

Find the line #requirepass and rewrite it to requirepass with the new password (eg 123)

 

6. By default, redis only allows local access. Commenting out bind 127.0.0.1 means that all ips are accessible

 

7. After completing the above operations, you can register the service:

chkconfig --add redis

Set up to start automatically

chkconfig redis on

Then start the redis service

service redis start

Redis can run as a service.

 

 

After configuring redis, to be able to access from the outside, you need to close the firewall and configure the client password or bind an accessible user ip

Turn off the firewall:

1.chkconfig /etc/init.d/iptables stop then restart linux

2. Set the access password of redis:

    Method 1: Open the redis client in linux to set the password (if there is no access password configured in the configuration file, set the password when starting the client)

   Start the server: redis installation directory/src/redis-cli

   Set the server password: config set requirepass 123

    Method 2: Configure the password in the redis configuration file (/etc/redis/6379.conf) such as; auth 123 (the password set in the configuration file)

 

 

Use of the redis client command line:

Step 1: Open the client and execute the command redis installation directory /src/redis-cli --raw (redis may have access to Chinese, in order not to display hexadecimal garbled characters when acquiring data, add this parameter)

Step 2 (may be required): If a password has been configured in the redis configuration file, execute the authorization authentication command to connect to redis. The command is as follows: auth 123 (password set in my machine)

Step 3 (if authorization authentication is required): Execute the command for authorization authentication, auth 123 (the password you set)

Step 4: Query, an example is as follows:

1. Query to get all storage keys: keys *

2. Get the data structure stored by a key: type person -- if it is a set data structure, the return value of this command is set

3. Assuming the person storage structure type, use the following command to get all the values: SMEMBERS person

 

Stop redi service method:

Step 1: Find the process of redis ps -ef | grep redis to get the process id suppose to be 3038

Step 2: Kill the process kill -9 3038

 

Please correct me if I am wrong!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326188878&siteId=291194637