-
- $ wget http://download.redis.io/releases/redis-2.6.16.tar.gz
- $ tar xzf redis-2.6.16.tar.gz
- $ cd redis-2.6.16
- $ make install
-
Copy code
2. Configuration
-
- $ mkdir /etc/redis
- $ cp redis.conf /etc/redis/redis.conf
- $ gedit /etc/sysctl.conf$ sysctl -p
-
Copy code
Note: Add vm.overcommit_memory=1 to the end of the sysctl.conf file
3. Start testing
-
- $ /usr/local/bin/redis-server /etc/redis/redis.conf
- $ /usr/local/bin/redis-cli
- $ set test xjx
- $ get test
-
Copy the code
4. Turn on the computer
-
-
$ gedit /etc/redis/redis.conf
- Set daemonize yes
$ gedit /var/run/redis.pid
- Save directly, mainly Create this file
gedit /etc/init.d/redis
- Edit the script, you can also download it yourself or enter the following content
- #!/bin/bash
- #
- # redis - this script starts and stops the redis-server daemon
- #
- # chkconfig: - 80 12
- # description: Redis is a persistent key-value database
- # processname: redis-server
- # config: /etc/redis/redis.conf
- # pidfile : /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/bin"
- CONFIG=" /etc/redis/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
- }< /p>
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
-
Copy code
Change file permissions:
-
- $ chmod 755 /etc/init.d/redis
Copy code
Add startup:
-
- $ chkconfig --add redis
- $ chkconfig --level 345 redis on
- $ chkconfig --list redis
Copy the code
and then restart the server, $ service redis status to check whether it is configured correctly
Next, we will introduce the installation and configuration methods of phpredis.
2. phpredis
1. Download and decompress by yourself
https://github.com/nicolasff/phpredis/archive/master.zip
2. Installation
-
- $ cd /root/phpredis-master
- $ /usr/local/php/bin/phpize
- $ ./configure --with-php-config=/usr/local/php/bin/php- config
- $ make && make install
-
Copy code
Note: The path is modified according to the actual situation
3.php extension
$ gedit /usr/local/php/etc/php.ini
Add extension=redis.so, and then restart php-fpm (non-nginx)
4.Test
-
- $redis = new Redis();
- $redis->connect('127.0.0.1',6379);
- $redis->set('test','hello world!');
- echo $redis->get('test');
-
Copy code
3. phpredisadmin
http://down.admin5.com/php/75024.html
Just download and unzip it to the www directory. It is provided here for everyone. It is best not to use the latest official version. You will understand the reason after using it.
|