Background:
Redis started with merzia, an Italian startup, founder Salvatore sanfilippo, and Pieter noordhuis, another major code contributor, who is currently working on redis in VMware. The redis code is hosted on GitHub.
Redis is a single-thread model in terms of performance, while memcached supports multiple threads. Therefore, the latter has higher performance on multi-core servers. However, redis has excellent performance, in most cases, its performance will not become a bottleneck. Therefore, you should be more concerned about the differences between the two functions. If you need advanced data types or persistence functions, redis will be a good substitute for memcached.
If redis is used with the Lua script, it is the perfect cache. Lua can solve the single-thread redis mode and read and write redis at a high speed.
Environment:
Single Machine, virtual machine, IP Address: 192.168.0.222
System: centos 6.3 64bit mini-install
Preparations:
Tcl8.6.1-src.tar.gz redis-2.6.14.tar.gz phpredis-master.tar.gz
Go to the corresponding official website and download the three open-source packages. If you don't understand them, Baidu will not. If you don't want to find a few packages, it will be broken!
Installation steps:
1. Compile the environment first and give both GCC and make to Yum.
|
Yum-y install GCC make
Tar xzvf tcl8.6.1-src.tar.gz
CD tcl8.6.1/ |
2. Start to install TCL. TCL is the main dependency tool of redis, so it needs to be compiled.
|
Cd unix &&
./Configure -- prefix =/usr \
-- Without-tzdata \
-- Mandir =/usr/share/man \
$ ([$ (Uname-m) = x86_64] & Echo -- enable-64bit )&&
Make &&
Sed-e "[email protected] ^ \ (tcl_src_dir = '\). * @ \ 1/usr/include '@"\
-E "/tcl_ B/[email protected] = '\ (-L \)\?. * [Email protected] = '\ 1/usr/[email protected] "\
-I tclconfig. Sh |
The official website says that after this step is completed, you can make test. Do not make test. Once you make test, you can have a few coffee drinks to rest, it takes at least half an hour to complete.
3. Start to install tcl and configure the library file Environment
|
Make install &&
Make install-private-headers &&
Ln-v-SF tclsh8.6/usr/bin/tclsh &&
Chmod-V 755/usr/lib/libtcl8.6.so |
4. After packaging the dependencies, you can install redis now. However, you need to compile the server environment before installing redis.
|
Echo 1>/proc/sys/Vm/overcommit_memory
Echo VM. overcommit_memory = 1>/etc/sysctl. conf
Sysctl VM. overcommit_memory = 1 |
If you do not configure the following kernel parameters first, an error will be reported when the redis script restarts or stops redis, and data cannot be automatically synchronized to the disk before the service is stopped.
5. Install redis
|
Tar xzvf redis-2.6.14.tar.gz
CD redis-2.6.14
Make
Make Test
Make install
CP redis. CONF/etc/ |
6. edit/etc/redis. conf, change daemaon no to daemaon yes, and start the process as a daemon process.
7. Create the/etc/init. d/redis STARTUP script and enter the following content to fill
|
VI/etc/init. d/redis
---------------------------------- Copy from below, and then post it
#! /Bin/bash
#
# Init file for redis
#
# Chkconfig:-80 12
# Description: redis daemon
#
# Processname: redis
# Config:/etc/redis. conf
# Pidfile:/var/run/redis. PID
Source/etc/init. d/functions
# Bin = "/usr/local/bin"
Bin = "/usr/local/bin"
Config = "/etc/redis. conf"
Pidfile = "/var/run/redis. PID"
### Read Configuration
[-R "$ sysconfig"] & source "$ sysconfig"
Retval = 0
Prog = "redis-server"
Desc = "redis server"
Start (){
If [-e $ pidfile]; then
Echo "$ DESC already running ...."
Exit 1
Fi
Echo-N $ "Starting $ Desc :"
Daemon $ bin/$ prog $ config
Retval =$?
Echo
[$ Retval-EQ 0] & Touch/var/lock/subsys/$ prog
Return $ retval
}
Stop (){
Echo-N $ "Stop $ Desc :"
Killproc $ prog
Retval =$?
Echo
[$ Retval-EQ 0] & Rm-F/var/lock/subsys/$ prog $ pidfile
Return $ retval
}
Restart (){
Stop
Start
}
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Restart
;;
Condrestart)
[-E/var/lock/subsys/$ prog] & restart
Retval =$?
;;
Status)
Status $ prog
Retval =$?
;;
*)
Echo $ "Usage: $0 {START | stop | restart | condrestart | status }"
Retval = 1
Esac
Exit $ retval
|
8. Set the redis startup permission and enable the Automatic startup mode.
|
Chmod 755/etc/init. d/redis
Chkconfig -- add redis
Chkconfig -- level 345 redis on
Chkconfig -- list redis |
9. Start redis
|
Redis-server/etc/redis. conf
Alternatively, you can use the following
Service redis stat |
If the process is found to be online, it indicates that redis is successfully installed.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/47/E0/wKiom1QCmKmQ-jBYAACxOQIpAJY743.jpg "Title =" Unnamed QQ screenshot20140831113620.png "alt =" wKiom1QCmKmQ-jBYAACxOQIpAJY743.jpg "/>
10. Test redis for normal operation and write and read operations.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/47/E2/wKioL1QCmf7z8rvTAAB33Lcsdcc789.jpg "Title =" QQ photo20140831113736.jpg "alt =" wkiol1qcmf7z8rvtaab33lcsdcc789.jpg "/>
Obviously, it can be set, that is, it can be written. The value of Zhou is 1234.
Then, we get again, that is, get the Zhou key, and the corresponding value is 1234.
It doesn't matter if you don't understand these commands. In subsequent articles, I will explain the common redis operations "CLI"
11. Now that the installation is complete, the next step is to put it into operation. These are all single commands and are not suitable for operation. Therefore, we need to create an API, the common Web language is Php. Therefore, we need to support PHP. Therefore, we need to install a PHP plug-in.
12. Before installing the PHP plug-in, you need to install the PHP environment first. If you are not familiar with installing PHP, please read this article.
Centos nginx + PhP install is the most perfect
13. start installing the PHP plug-in.
|
Tar xvf phpredis-master.tar.gz
CD phpredis-Master
Phpize --- Note: Remember the path output by the system,
./Configure -- enable-redis
Make & make install |
14. edit/etc/PHP. ini and add the following two sentences:
|
Extension_dir = "/usr/lib64/PHP/modules/", which is the output value
Extension = redis. So |
15. Restart PHP to complete the process.
16. For details about how PHP calls redis, refer to subsequent articles.
This article is from the "Zhou's family" blog and will not be reposted!
Redis installation tutorial-Single Machine