In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "redis installation, configuration, use and redis php extension installation steps", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the steps of redis installation, configuration, use and redis php extension installation.
Redis is an in-memory database that supports richer value types than memcache. Sina Weibo uses redis for caching.
Source code installation of redis
The copy code is 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 when 1.make:
The copy code is 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 OPT in src/.make-settings and change it to OPT=-O2-march=i686.
2.make test error:
The copy code is as follows:
You need tcl 8.5 or newer in order to run the Redis test
Make: * * [test] Error 1
Workaround install tcl
The copy code is 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 uname 64] & & echo-- enable-64bit) & &
Make & &
Sed-e "s @ ^\ (TCL_SRC_DIR='\). * @\ 1Universe usrUniverse @"\ "
-e "/ TCL_B/s@='\ (- L\)\?. * unix@='\ 1Universe usrUniverse 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 redis command
Redis consists of four executable files: redis-benchmark, redis-cli, redis-server, and redis-stat, plus a redis.conf to form the final available package for the entire redis. Their functions are as follows:
Daemon launcher for redis-server:Redis server
Redis-cli:Redis command line operation tool. Of course, you can also use telnet according to its plain text protocol.
Redis-benchmark:Redis performance testing tool to test the read and write performance of Redis on your system and your configuration
Redis-stat:Redis status detection tool, which can detect the current state parameters and delay status of Redis
Now you can start redis. Redis has only one startup parameter, which is its configuration file path.
Start redis
Copy the redis.conf in the source package to / etc
The copy code is as follows:
# cd redis-stable
# cp redis.conf / etc/redis.conf
Edit / etc/redis.conf, change daemaon no to daemaon yes, and start the process as a daemon.
The copy code is as follows:
# redis-server / etc/redis.conf
Close redis
The copy code is as follows:
# redis-cli shutdown / / close all
Turn off redis on a port
# redis-cli-p 6397 shutdown / / disable redis on port 6397
Note: after closing, the cached data will be automatically dump to the hard disk. The address of the hard disk can be found in dbfilename dump.rdb in redis.conf.
Redis configuration
Note that the daemonize parameter of the copied redis.conf file is no by default, so redis will not run in the background, so to test, we need to open a new terminal. Change to yes to run redis in the background. In addition, the configuration file specifies the address of the pid file, log file and data file. If you need to modify it first, the default log information is directed to stdout.
The following is the meaning of the main configuration parameters of redis.conf:
The copy code is as follows:
Daemonize: whether to run in background daemon mode
Pidfile:pid file location
Port: the port number on which to listen
Timeout: request timeout
Loglevel:log information level
Logfile:log file location
Databases: number of databases opened
Save * *: how often the snapshot is saved. The first * indicates how long it takes, and the third * indicates how many writes are performed. The snapshot is automatically saved when a certain number of writes are performed within a certain period of time. Multiple conditions can be set.
Rdbcompression: whether to use compression
Dbfilename: data snapshot file name (file name only, not directory)
Dir: the directory where the data snapshot is saved (this is the directory)
Appendonly: whether or not to enable appendonlylog, each write operation will record a log, which will improve the anti-risk ability of the data, but affect the efficiency.
How to synchronize appendfsync:appendonlylog to disk (three options: forcing fsync to be called every time you write, enabling fsync once per second, and not calling fsync to wait for the system to synchronize itself)
At this point, you can open a terminal for testing. The default listening port in the configuration file is 6379.
Redis booting starts automatically
Before using this script to manage, you need to configure the following kernel parameters, otherwise the Redis script will report an error when restarting or stopping redis, and cannot automatically synchronize data to disk before stopping the service:
The copy code is as follows:
# vi / etc/sysctl.conf
Vm.overcommit_memory = 1
Then the application takes effect:
The copy code is as follows:
# sysctl-p
Create a redis startup script:
The copy code is 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 "$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
Then add services and boot up:
The copy code is as follows:
# chmod 755 / etc/init.d/redis
# chkconfig-add redis
# chkconfig-- level 345 redis on
# chkconfig-list redis
Redis php extension installation
The copy code is 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
After completion, redis.so is installed into the
The copy code is as follows:
/ usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
Vi / usr/local/php/lib/php.ini
Add
The copy code is as follows:
Extension=redis.so
Just restart php-fpm.
You may encounter it during configure, which can be solved by adding the-- with-php-config parameter.
The copy code is as follows:
Configure: error: Cannot find php-config. Please use-with-php-config=PATH
. / configure-- with-php-config=/usr/local/php/bin/php-config
At this point, I believe you have a deeper understanding of the "redis installation, configuration, use and redis php extension installation steps". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.