Redis installation, configuration, use, and Redis PHP Extensions installation Tutorial _ database Other

Source: Internet
Author: User
Tags benchmark chmod redis redis server

Redis is a memory database that supports richer value types than memcache, and Sina Weibo uses Redis for caching.

Redis's Source code installation

Copy Code code as follows:

wget http://download.redis.io/redis-stable.tar.gz
TAR-ZXVF redis-stable.tar.gz
CD redis-stable
Make
Make Test
Make install

The following error may be reported at 1.make:
Copy Code code as follows:

zmalloc.o:in function ' zmalloc_used_memory ':
/root/redis-stable/src/zmalloc.c:223:undefined reference to ' __sync_add_and_fetch_4 '
Collect2:ld returned 1 exit status
MAKE[1]: * * * [redis-server] Error 1
MAKE[1]: Leaving directory '/ROOT/REDIS-STABLE/SRC '
Make: * * * [ALL] Error 2

Solution:
Edit src/.make-settings in the OPT, change to opt=-o2-march=i686.

2.make Test Error:

Copy Code code as follows:

You are need TCL 8.5 or newer in order to run the Redis test
Make: * * * [Test] Error 1

Solution Installation Tcl
Copy Code code as follows:

wget http://downloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz

CD tcl8.6.0/

CD UNIX &&
./configure--prefix=/usr \
--mandir=/usr/share/man \
--without-tzdata \
$ ([$ (uname-m) = x86_64] && echo--enable-64bit) &&
Make &&

Sed-e "s@^\ (tcl_src_dir= '). *@\1/usr/include ' @" \
-E "/tcl_b/s@= '" (-l\) \?. *unix@= ' \1/usr/lib@ '
-I. tclconfig.sh

Make install &&
Make Install-private-headers &&
Ln-v-SF Tclsh8.6/usr/bin/tclsh &&
Chmod-v 755/usr/lib/libtcl8.6.so



Introduction to the Redis command

Redis consists of four executables: Redis-benchmark, Redis-cli, Redis-server, redis-stat four files, plus a redis.conf form the final available package for the entire redis. Their role is as follows:

Daemon startup program for Redis-server:redis server
Redis-cli:redis Command line Operation tool. Of course, you can also use Telnet to operate on its plain text protocol.
Redis-benchmark:redis Performance Testing tool to test Redis performance in your system and your configuration
Redis-stat:redis State Detection Tool, can detect Redis current state parameters and delay status
Now you can start Redis, Redis has only one startup parameter, and that's his profile path.

Start Redis

Redis.conf to/etc in the copy source package

Copy Code code as follows:
# CD Redis-stable
# CP Redis.conf/etc/redis.conf

Edit/etc/redis.conf, modify Daemaon No to Daemaon Yes, and start the process in a daemon way.

Copy Code code as follows:

# redis-server/etc/redis.conf

Close Redis

Copy Code code as follows:

# REDIS-CLI Shutdown//Close all
To close a redis on a port
# redis-cli-p 6397 shutdown//Close 6397-Port Redis

Note: After the shutdown, the cached data will automatically dump to the hard disk, the hard disk address see redis.conf in the Dbfilename Dump.rdb

Redis Configuration

Note that the default copy of the past redis.conf file daemonize parameter is no, so Redis does not run in the background, then to test, we need to reopen a terminal. Modify to Yes to run Redis for the background. In addition, the configuration file specified the PID file, log files and data file address, if necessary to modify first, the default log information directed to stdout.

The following are the meaning of the main configuration parameters of redis.conf:

Copy Code code as follows:

Daemonize: Whether to run after the daemon mode
Pidfile:pid File Location
Port: The port number listening
Timeout: Request Timeout time
Loglevel:log Information level
Logfile:log File Location
Databases: number of databases Open
Save * *: How often the snapshot is saved, how long the first * represents, and the third * indicates how many writes have been performed. Automatically saves snapshots when a certain number of writes are performed within a certain amount of time. Multiple conditions can be set.
Rdbcompression: Whether to use compression
Dbfilename: Data Snapshot file name (just filename, excluding directory)
Dir: Save directory for Data snapshots (this is a directory)
AppendOnly: Whether to turn on the Appendonlylog, open the word every write will remember a log, which will improve the risk-resistant ability of data, but affect efficiency.
Appendfsync:appendonlylog How to sync to disk (three options, each write is forced to call Fsync, enable once per second Fsync, do not call Fsync wait for the system to sync itself)
At this point you can open a terminal for testing, the default listening port in the configuration file is 6379

Redis Boot automatically

Before you can use this script to manage, you need to configure the following kernel parameters, otherwise the Redis script will error when you restart or stop Redis, and you cannot automatically synchronize data to disk before stopping the service:

Copy Code code as follows:

# vi/etc/sysctl.conf

Vm.overcommit_memory = 1

Then the application takes effect:

Copy Code code as follows:

# sysctl–p

To create a Redis startup script:

Copy Code code as follows:

# Vim/etc/init.d/redis

#!/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 "$" in
Start
Start

Stop
Stop

Restart)
Restart

Condrestart)
[-e/var/lock/subsys/$prog] && restart
Retval=$?

Status
Status $prog
Retval=$?

*)
echo $ "Usage: $ {Start|stop|restart|condrestart|status}"
Retval=1
Esac
Exit $RETVAL


Then add the service and boot from:
Copy Code code as follows:

# chmod 755/etc/init.d/redis
# chkconfig--add Redis
# chkconfig--level 345 Redis on
# chkconfig--list Redis

Redis PHP Extended Installation

Copy Code code as follows:

wget Https://github.com/nicolasff/phpredis/zipball/master-O Php-redis.zip
Unzip Php-redis.zip
CD nicolasff-phpredis-2d0f29b/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make && make install

When finished redis.so is installed to

Copy Code code as follows:
/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

Vi/usr/local/php/lib/php.ini

Add to

Copy Code code as follows:
Extension=redis.so

Restart the PHP-FPM.

Configure may be encountered, add--with-php-config parameters can be resolved.

Copy Code code as follows:

Configure:error:Cannot find Php-config. Please use--with-php-config=path

./configure--with-php-config=/usr/local/php/bin/php-config

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.