Compile and install redis in Linux. For details, refer to linuxredis.
Let's not talk much about it. Start work directly.
Preparations:
Test environment: Win10
Virtual Machine: VM
Linux: CentOS5.5 (LNMP environment has been set up)
Software Package: redis-2.6.14.tar.gz (redis installation package under Linux): http://pan.baidu.com/s/1oX8dN
Start installation below:
Step 1: Upload the source code package of redis-2.6.14.tar.gz to Linux,
Create a soft directory under the/usr/local/directory and upload the software package to the soft directory.
(I won't talk much about the upload process)
Step 2: Decompress the source package:
# Tar-zxvf redis-2.6.14.tar.gz
Step 3: Go to the decompressed source code package and execute the compilation
# Cd redis-2.6.14
# Make CFLAGS = "-march = i686 ";
######################################## #############################
Note: The code behind make is CFLAGS = "-march = i686" to prevent the software version from being incompatible with the Linux hardware.
Linux has the difference between i386 and i686. If the redis software and hardware are not compatible, you can directly use the make command to compile the Code. This error will be reported:
However, if CFLAGS = "-march = i686" is added after make, the problem can be solved and compiled successfully.
If you make the Code directly and do not report an error, you do not need to add the CFLAGS code.
######################################## ##############################
Step 4: Enter the redis-2.6.14/src directory after successful compilation
# Cd/usr/local/soft/redis-2.6.14/src
# Ll
Several executable files are displayed:
Here we only need to use two files: redis-server and redis-cli.
Step 5: Create a working directory and copy the preceding two files to the working directory.
I created a redis directory under the/usr/local/directory.
# Cd/usr/local/
# Mkdir redis
Copy the redis-server and server-cli in the src directory to the redis directory.
[Root @ localhost src] # cp redis-cli redis-server/usr/local/redis/
Then return to the redis-2.6.14 source code directory to copy the redis. conf file to the redis directory
[Root @ localhost redis-2.6.14] # cp redis. conf/usr/local/redis/
The final result is that the redis directory contains three files, for example:
Here, even if it is done,
Next, run the redis service:
[Root @ localhost redis] #./redis-server
When the following interface appears, your redis instance can be used normally.
Now there is another question: redis is running at the front end. What should I do if I cannot do anything else? How can I run redis in the background?
Method: Modify the redis. conf file and change "daemonize no" to "daemonize yes ".
[Root @ localhost redis] # vi redis. conf
Change no to yes. Save and exit
Kill the rdis process and start the redis service again.
[Root @ localhost redis] # killall redis-server
[Root @ localhost redis] #./redis-server redis. conf
The following interface indicates that redis is successfully run in the background.
To check whether there is any redis service in the process, run the pstree command to view the process:
[Root @ localhost redis] # pstree
After the background runs successfully, use the redis-cli client to connect to redis:
[Root @ localhost redis] #./redis-cli 192.168.0.101 6379
In the above Code, the IP address and port number can be left blank. If this parameter is left blank, the local redis instance is connected by default.
Check whether there is data in redis.
Command: keys *
No data yet
To add a piece of data!
Command: get mykey "tom"
Read a piece of data:
Command: get mykey
Here, redis is installed. Here we will share the usage of redis:
Redis command reference: http://redisdoc.com/
For more information about how php operates redis, please pay attention to it next time. Please refer to the error.