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
If prompted whether to install, choose: y
2.2 Redis installation
(1) Use SecureFXPortable to upload the Redis installation file to the Linux directory
(2) Upload the Redis installation file, here I upload the self-built folder: /home/yhp/local
(3) Unzip the redis file
[root@localhost local]# tar -zxvf redis-5.0.5.tar.gz
(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
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
(6) bin directory after installation
Commands under the bin folder:
(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)
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
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
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
(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)
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