Install redis in linuxcentos5.8

Source: Internet
Author: User
Tags redis version keep alive install redis
Redis is a high-performance key-value database. The emergence of redis largely compensates for the shortage of keyvalue storage such as memcached, and can play a good complementary role in relational databases in some cases. It provides Python, Ruby, Erlang, and PHP clients for ease of use. 1. Install tcl; otherwise, an error is reported during redismaketest.

Redis is a high-performance key-value database. The emergence of redis largely compensates for the shortage of key/value storage such as memcached, and can play a good complementary role in relational databases in some cases. It provides Python, Ruby, Erlang, and PHP clients for ease of use. 1. Install tcl or report it when redis make test

Redis is a high-performance key-value database. The emergence of redis largely compensates for the shortage of key/value storage such as memcached, and can play a good complementary role in relational databases in some cases. It provides Python, Ruby, Erlang, and PHP clients for ease of use.
1. Install tcl
Otherwise, an error is reported during redis make test.

You need tcl 8.5 or newer in order to run the Redis testmake[1]: *** [test] Error 1
wget http://downloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gztar zxvf tcl8.6.0-src.tar.gzcd tcl8.6.0-srccd unix &&./configure --prefix=/usr \            --mandir=/usr/share/man \            $([ $(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.shmake test
Tests ended at Tue Apr 16 12:02:27 CST 2013all.tcl:        Total   116     Passed  116     Skipped 0       Failed  0
make install &&make install-private-headers &&ln -v -sf tclsh8.6 /usr/bin/tclsh &&chmod -v 755 /usr/lib/libtcl8.6.so

Ii. redis
1. Install redis

wget http://redis.googlecode.com/files/redis-2.6.12.tar.gztar xzf redis-2.6.12.tar.gzcd redis-2.6.12makemake test

The following errors can be ignored:

Https://github.com/antirez/redis/issues/1034

[exception]: Executing test client: assertion:Server started even if RDB was unreadable!.assertion:Server started even if RDB was unreadable!    while executing"error "assertion:$msg""    (procedure "fail" line 2)    invoked from within"fail "Server started even if RDB was unreadable!""    ("uplevel" body line 2)    invoked from within"uplevel 1 $elsescript"    (procedure "wait_for_condition" line 7)    invoked from within"wait_for_condition 50 100 {        [string match {*Fatal error loading*}  [exec tail -n1 < [dict get $srv stdout]]]    } else {        fail "Server..."    ("uplevel" body line 2)    invoked from within"uplevel 1 $code"    (procedure "start_server_and_kill_it" line 5)    invoked from within"start_server_and_kill_it [list "dir" $server_path] {    wait_for_condition 50 100 {        [string match {*Fatal error loading*} \            [exec..."    (file "tests/integration/rdb.tcl" line 57)    invoked from within"source $path"    (procedure "execute_tests" line 4)    invoked from within"execute_tests $data"    (procedure "test_client_main" line 9)    invoked from within"test_client_main $::test_server_port "make[1]: *** [test] Error 1

After the make command is executed, four executable files are generated in the current directory, including redis-server, redis-cli, redis-benchmark, and redis-stat, their functions are as follows:
Redis-server: daemon Startup Program of the Redis server
Redis-cli: Redis command line operation tool. Of course, you can also use telnet to operate based on its plain text protocol.
Redis-benchmark: Redis performance testing tool to test the read/write performance of Redis in your system and your configuration
Redis-stat: Redis status detection tool that can detect Redis's current status parameters and latency

2. Create a Redis directory

mkdir -p /opt/redis/binmkdir -p /opt/redis/etcmkdir -p /opt/redis/varcp redis.conf /opt/redis/etc/cd srccp redis-server redis-cli redis-benchmark redis-check-aof redis-check-dump /opt/redis/bin/useradd redischown -R redis.redis /opt/redis

Create a Redis directory to better manage Redis-related resources in a unified manner. You can also use
Make install
Installed in the default system directory

3. Copy the Startup File

cp ../utils/redis_init_script /etc/init.d/redis

4. Start redis

cd /opt/redis/bin./redis-server /opt/redis/etc/redis.conf
_._                                                             _.-``__ ''-._                                                   _.-``    `.  `_.  ''-._           Redis 2.6.12 (00000000/0) 64 bit  .-`` .-".  "\/    _.,_ ''-._                                    (    '      ,       .-`  | `,    )     Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379 |    `-._   `._    /     _.-'    |     PID: 24454  `-._    `-._  `-./  _.-'    _.-'                                    |`-._`-._    `-.__.-'    _.-'_.-'|                                   |    `-._`-._        _.-'_.-'    |           http://redis.io          `-._    `-._`-.__.-'_.-'    _.-'                                    |`-._`-._    `-.__.-'    _.-'_.-'|                                   |    `-._`-._        _.-'_.-'    |                                    `-._    `-._`-.__.-'_.-'    _.-'                                         `-._    `-.__.-'    _.-'                                                 `-._        _.-'                                                         `-.__.-'                                               [24454] 12 Apr 10:34:19.519 # Server started, Redis version 2.6.12[24454] 12 Apr 10:34:19.519 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.[24454] 12 Apr 10:34:19.519 * The server is now ready to accept connections on port 6379

After Redis is successfully installed, run the redis-server command to run Redis. In this case, it runs according to the default configuration (the default configuration is not the background operation ). If we want Redis to run as required, we need to modify the configuration file,

5. Set itpables to allow access from the 192.168.0 Intranet segment.

iptables -A INPUT -s 192.168.0.0/24 -p tcp -m tcp --dport 6379 -j ACCEPT/etc/init.d/iptables save

6. Configure redis
Vi/opt/redis/etc/redis. conf

Daemonize yes # whether to run as a daemon. The default value is 0 pidfile/var/run/redis. pid # specify a pid. The default value is/var/run/redis. pidport 6379 # Redis default listening port bind 192.168.0.41 # bind host IP address, default value: 127.0.0.1timeout 300 # How many seconds after the client is idle, disconnect, default value: 300 (seconds) tcp-keepalive 0 # tcp persistence connection loglevel notice # log record level, which has four optional values: debug, verbose (default), notice, warninglogfile/opt/redis/var/redis. log # specify the log output file name. The default value is stdout. You can also set it to/dev/null to shield the log databases 16 # number of available databases, the default value is 16 save 900 1 # policy for saving data to disk # When a Keys data is changed, refresh to disk in 900 seconds save 300 10 # When 10 Keys data are changed, refresh to disk in 300 seconds save 60 10000 # When 1 million keys data is changed, refresh to disk once every 60 seconds # When dump. whether to compress the Data Object rdbcompression yes # Name of the local database file. The default value is dump. rdbdbfilename dump. rdb # local database storage path. The default value is. /dir/opt/redis/var/# Memory limit maxmemory 2G # refresh policy maxmemory-policy allkeys-lru

7. Adjust System Kernel Parameters
If the memory is insufficient, you need to set the kernel parameters:

echo 1 > /proc/sys/vm/overcommit_memory

Here we will talk about the meaning of this configuration:/proc/sys/vm/overcommit_memory
This file specifies the kernel memory allocation policy. The value can be 0, 1, or 2.
0 indicates that the kernel will check whether there is enough available memory for use by the process. If there is enough available memory, the memory application will be allowed; otherwise, the memory application will fail, and return the error to the application process.
1 indicates that the kernel allows all physical memory allocation regardless of the current memory status.
2. indicates that the kernel is allowed to allocate more memory than the total physical memory and swap space.
Redis generates a sub-process when dumping data. In theory, the memory occupied by the child process is the same as that of the parent. For example, the parent occupies 8 GB of memory, at this time, 8 GB of memory should also be allocated to the child. If the memory is not enough, it will often cause the redis server to go down or the IO load is too high, and the efficiency is reduced. Therefore, the optimized memory allocation policy should be set to 1 (indicating that the kernel allows allocation of all physical memory, regardless of the current memory status)

Vi/etc/sysctl. conf

vm.overcommit_memory = 1

Then the application takes effect:

sysctl –p

8. Modify the redis service script
Vi/etc/init. d/redis

REDISPORT=6379EXEC=/opt/redis/bin/redis-serverCLIEXEC=/opt/redis/bin/redis-cliPIDFILE=/var/run/redis.pidCONF="/opt/redis/etc/redis.conf"

Modify the script when listening for non-local IP addresses. Otherwise, the script cannot be shut down.

# Add the listener address variable REDIHOST = 192.168.0.41 # Add-h $ REDIHOSTecho "Stopping..." $ CLIEXEC-h $ REDIHOST-p $ REDISPORT shutdown

9. Test

/etc/init.d/redis start

Starting Redis server...

/opt/redis/bin/redis-cli -h 192.168.0.41

Redis 127.0.0.1: 6379> ping
PONG
Redis 127.0.0.1: 6379> set mykey c1gstduio
OK
Redis 127.0.0.1: 6379> get mykey
"C1gstduio"
Redis 127.0.0.1: 6379> exit

Benchmark
/Opt/redis/bin/redis-benchmark-h 192.168.0.41

====== PING_INLINE ======  10000 requests completed in 0.17 seconds  50 parallel clients  3 bytes payload  keep alive: 199.51% <= 1 milliseconds100.00% <= 1 milliseconds60240.96 requests per second====== PING_BULK ======  10000 requests completed in 0.17 seconds  50 parallel clients  3 bytes payload  keep alive: 1100.00% <= 0 milliseconds60240.96 requests per second====== SET ======  10000 requests completed in 0.16 seconds  50 parallel clients  3 bytes payload  keep alive: 1100.00% <= 0 milliseconds61728.39 requests per second====== GET ======  10000 requests completed in 0.17 seconds  50 parallel clients  3 bytes payload  keep alive: 199.49% <= 1 milliseconds100.00% <= 1 milliseconds60606.06 requests per second====== INCR ======  10000 requests completed in 0.16 seconds  50 parallel clients  3 bytes payload  keep alive: 196.26% <= 1 milliseconds100.00% <= 1 milliseconds64516.13 requests per second====== LPUSH ======  10000 requests completed in 0.15 seconds  50 parallel clients  3 bytes payload  keep alive: 193.60% <= 1 milliseconds100.00% <= 1 milliseconds65789.48 requests per second====== LPOP ======  10000 requests completed in 0.15 seconds  50 parallel clients  3 bytes payload  keep alive: 193.50% <= 1 milliseconds100.00% <= 1 milliseconds66666.66 requests per second====== SADD ======  10000 requests completed in 0.16 seconds  50 parallel clients  3 bytes payload  keep alive: 196.52% <= 1 milliseconds100.00% <= 1 milliseconds61728.39 requests per second====== SPOP ======  10000 requests completed in 0.17 seconds  50 parallel clients  3 bytes payload  keep alive: 1100.00% <= 0 milliseconds57471.27 requests per second====== LPUSH (needed to benchmark LRANGE) ======  10000 requests completed in 0.17 seconds  50 parallel clients  3 bytes payload  keep alive: 1100.00% <= 0 milliseconds58139.53 requests per second====== LRANGE_100 (first 100 elements) ======  10000 requests completed in 0.25 seconds  50 parallel clients  3 bytes payload  keep alive: 199.67% <= 1 milliseconds100.00% <= 1 milliseconds40322.58 requests per second====== LRANGE_300 (first 300 elements) ======  10000 requests completed in 0.56 seconds  50 parallel clients  3 bytes payload  keep alive: 10.22% <= 1 milliseconds98.62% <= 2 milliseconds99.01% <= 3 milliseconds99.49% <= 4 milliseconds100.00% <= 4 milliseconds17921.15 requests per second====== LRANGE_500 (first 450 elements) ======  10000 requests completed in 0.96 seconds  50 parallel clients  3 bytes payload  keep alive: 10.07% <= 1 milliseconds40.25% <= 2 milliseconds73.76% <= 3 milliseconds99.51% <= 4 milliseconds100.00% <= 5 milliseconds10362.69 requests per second====== LRANGE_600 (first 600 elements) ======  10000 requests completed in 1.00 seconds  50 parallel clients  3 bytes payload  keep alive: 10.07% <= 1 milliseconds0.35% <= 2 milliseconds98.18% <= 3 milliseconds99.12% <= 4 milliseconds99.48% <= 5 milliseconds99.60% <= 6 milliseconds99.85% <= 7 milliseconds100.00% <= 8 milliseconds10010.01 requests per second====== MSET (10 keys) ======  10000 requests completed in 0.26 seconds  50 parallel clients  3 bytes payload  keep alive: 10.34% <= 1 milliseconds100.00% <= 2 milliseconds38167.94 requests per second

10. Close the service
/Opt/redis/bin/redis-cli shutdown
If the port changes, you can specify the Port:
/Opt/redis/bin/redis-cli-h 192.168.0.41-p 6379 shutdown

11. Save/backup
Data backup can be achieved through regular backup of this file.
Because redis writes data to the disk asynchronously, if you want to write data in the memory to the hard disk immediately, run the following command:
Redis-cli save or redis-cli-p 6379 save (specified port)
Note that the preceding deployment operations require certain permissions, such as copying and setting kernel parameters.
When executing the redis-benchmark command, the memory data is also written to the hard disk.

/Opt/redis/bin/redis-cli save
OK

View results
Ll-h var/

total 48K-rw-r--r-- 1 root root  40K Apr 12 11:49 dump.rdb-rw-r--r-- 1 root root 5.3K Apr 12 11:49 redis.log

12. Start running
Vi/etc/rc. local

/etc/init.d/redis start

Iii. php Extension

There are a lot of redis extensions, and there are several php alone. Here we use phpredis, Predis requires PHP> = 5.3
Predis?★RepositoryJoL1hAHN Mature and supported
Phpredis?★Repositoryyowgi This is a client written in C as a PHP module.
Rediska? Repository Homepageshumkov
RedisServerRepositoryOZ Standalone and full-featured class for Redis in PHP
Redisent? Repositoryjustinpoliey
CredisRepositorycolinmollenhour Lightweight, standalone, unit-tested fork of Redisent which wraps phpredis for best performance if available.

1. install php extension phpredis

wget https://nodeload.github.com/nicolasff/phpredis/zip/master --no-check-certificatecd phpredis-masterunzip mastercd phpredis-master//opt/php/bin/phpize./configure --with-php-config=/opt/php/bin/php-configmakemake install

Next, add extension = redis. so in php. ini.
Vi/opt/php/etc/php. ini

extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20060613/"extension=redis.so

Vi test. php

 connect("127.0.0.1",6379);$redis->set("test","Hello World");echo $redis->get("test");?>

Redis
Redis Supportenabled
Redis Version 2.2.2

4. php-based web management tools

PhpRedisAdmin

Https://github.com/ErikDubbelboer/phpRedisAdmin

Demo: http://dubbelboer.com/phpRedisAdmin? Overview
There are a lot of people using this, but I cannot display it after installation.

Readmin

Http://readmin.org/

Demo: http://demo.readmin.org/
Need to be installed in the root directory

Phpredmin

Https://github.com/sasanrose/phpredmin#readme

Can be displayed, with a float chart
Use pseudo rewrite,/index. php/welcome/stats

Wget https://nodeload.github.com/sasanrose/phpredmin/zip/master
Unzip phpredmin-master.zip

Ln-s phpredmin/public predmin

Edit nginx and support rewrite
Nginx. conf

location ~* ^/predmin/index.php/             {  rewrite ^/predmin/index.php/(.*) /predmin/index.php?$1 break;  fastcgi_pass  127.0.0.1:9000;                  fastcgi_index index.php;                  include fcgi.conf;             }

Crontab-e

* * * * * root cd /var/www/phpredmin/public && php index.php cron/index

Configure redis
Vi phpreadmin/config

'redis' => Array(            'host'     => '192.168.0.30',            'port'     => '6379',            'password' => Null,            'database' => 0

Access admin.xxx.com/predmin/to display the interface

5. actual usage
After redis is installed, make the discuzx2.5 cache
Bandwidth consumption is astonishing, about 10 times that of memcached
Memory usage is also about 1/4 more
Discuz occasionally times out and fails to connect to redis.
Finally, we switched back to memcached.

Refer:

Http://redis.io/topics/quickstart

Http://hi.baidu.com/mucunzhishu/item/ead872ba3cec36db84dd798c

Http://www.linuxfromscratch.org/blfs/view/svn/general/tcl.html

Original article address: Install redis in centos5.8 linux. Thank you for sharing it with me.

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.