How to install Redis under Linux?

Install Redis under Linux

1 Environmental preparation

(1) Virtual machine version: VMware® Workstation 12 Pro

(2) Linux system: Centos Release 6.5

(3) Remote command terminal: xshell

(4) File transfer tool: SecureFXPortable

2 Redis installation

2.1 Redis compilation environment

Redis is developed in C language. To install redis, you need to go to the official website to download the source code for compilation. The compilation depends on the GCC compilation environment. If the gcc compilation environment is not installed on CentOS, you need to install it in advance. The installation command is as follows: (Here we use root user processing These operations)

[root@localhost ~]# yum install gcc-c++

If prompted whether to download, select: y
Insert picture description here

If prompted whether to install, choose: y
Insert picture description here

2.2 Redis installation

(1) Use SecureFXPortable to upload the Redis installation file to the Linux directory

Insert picture description here

(2) Upload the Redis installation file, here I upload the self-built folder: /home/yhp/local

Insert picture description here

(3) Unzip the redis file

[root@localhost local]# tar -zxvf redis-5.0.5.tar.gz

Insert picture description here

(4) Compile Redis (compile, compile .c files into .o files)

Enter the unzipped folder and execute make

[root@localhost local]# cd redis-5.0.5
[root@localhost redis-5.0.5]# make

Insert picture description here

Compilation is successful! If an error occurs during compilation, first delete the installation file directory, and then unzip and recompile.

(5) Installation

[root@localhost redis-5.0.5]# make PREFIX=/home/admin/myapps/redis install

Note: /home/myapps/redis here is the custom redis installation path
Insert picture description here

(6) bin directory after installation
Insert picture description here

Commands under the bin folder:

Insert picture description here

Insert picture description here

(7) Copy file

Redis requires a configuration file to start, and you can modify the port number information. Copy the redis.conf file in the folder where redis is decompressed to the installation directory

[root@localhost redis-5.0.5]# cp redis.conf /home/admin/myapps/redi

3 Start of Redis

3.1 Redis's front-end mode startup

Running bin/redis-server directly will start the permanent front-end mode. The disadvantage of the front-end mode startup is that after the startup is completed, no other operations can be performed. If you want to operate, you must use ctrl+c, and the redis-server program ends. This method is not recommended

[root@localhost bin]# ./redis-server

The following is the startup interface (this interface can only be started, no other operations can be performed after startup)
Insert picture description here

Use ctrl+c to exit the front-end startup.

3.2 Redis backend startup

Modify the redis.conf configuration file, set: daemonize yes, and then you can use the back-end mode to start.

[root@localhost redis]# vi redis.conf

Insert picture description here

When starting, specify the configuration file (here the folder is redis)

[root@localhost redis]# ./bin/redis-server ./redis.conf

Redis default port: 6379, view through the current service

[root@localhost redis]# ps -ef | grep -i redis

Insert picture description here

3.3 Client access redis

If you want to operate redis through instructions, you can use the redis client to operate, and run redis-cli in the bin folder.

The default connection is 127.0.0.1, the port number is 6379

[root@localhost bin]# ./redis-cli
127.0.0.1:6379>

If you want to connect to the specified ip address and port number, you need to follow

redis-cli -h ip地址 -p 端口号

Grammatical structure connection.

3.4 Send commands to Redis server

Ping, test whether the connection between the client and Redis is normal, if the connection is normal, return to pong

127.0.0.1:6379> ping
PONG

3.5 Exit the client

127.0.0.1:6379> quit

3.6 Stop of Redis

(1) The program is forced to end. Forcibly terminating the Redis process may result in the loss of redis persistent data. Syntax: kill -9 pid

Insert picture description here

(2) The correct way to stop Redis should be to send a SHUTDOWN command to Redis by (close the default port)

[root@localhost redis]# ./bin/redis-cli shutdown

3.7 Operate redis with third-party tools (redis-desktop-manager)
Insert picture description here

Note: You need to turn off the linux firewall and modify the bind parameter in the redis.conf file

bind linux的ip地址

At this time, when accessing through the redis client, the code is as follows:

./redis-cli -h 192.168.197.132 -p 6379

Guess you like

Origin blog.csdn.net/weixin_43515837/article/details/113094692
Recommended