CentOS6.4 install Redis2.6.13 and phpRedis extensions

Source: Internet
Author: User
Tags allkeys install redis
Step 1: Export github.com

Step 1: Download The http://redis.io/download wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz http://www.tcl.tk/software/tcltk/download.html wget http://prdownloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz https://github.com/

Step 1: download and install the required files
Http://redis.io/download
Wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz
Http://www.tcl.tk/software/tcltk/download.html
Wget http://prdownloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz
Https://github.com/nicolasff/phpredis
Wget https://github.com/nicolasff/phpredis/archive/master.zip
Because the final downloaded file for URL redirection is a master file without a suffix, it is actually a zip file. The folder decompressed by the unzip master is phpredis-master.

Step 2: Install the compilation software
2.1 install tcl
Tar xzvf tcl8.6.0-src.tar.gz
Cd tcl8.6.0/unix
./Configure
Make & make install

If you run make test without installing tcl to compile redis, the following error will be reported. This step can also be omitted, directly executing make install without executing make test has no effect on redis startup or shutdown.
[Root @ localhost redis] # make test
Cd src & make test
Make [1]: Entering directory '/usr/local/webserver/redis/src'
You need tcl 8.5 or newer in order to run the Redis test
Make [1]: *** [test] Error 1
Make [1]: Leaving directory '/usr/local/webserver/redis/src'
Make: *** [test] Error 2

2.2 install redis
Tar xzvf redis-2.6.13.tar.gz
Music redis-2.6.13/usr/local/webserver/redis
Cd/usr/local/webserver/redis
Make
Make test # can be omitted
Make install

2.3 Configuration
The source code package contains a default configuration file named redis. conf. You can modify relevant parameters as needed,
Daemonize: The default value is no. this parameter is used to determine whether the redis service runs in daemonize mode.
Pidfile: Default Value:/var/run/redis. pid. It specifies the path of the redis service process number file. This parameter must be configured when running in daemon mode;
Port: The default value is 6379. Specify the port of the redis service;
Bind: bind an ip address. The default value is all network devices on the local machine;
Timeout: disconnect after the client is idle for n seconds;
Loglevel: Set the Log Level of the server. The following options are available:
Debug: records detailed information for development or debugging;
Verbose: provides a lot of useful information, but it is not as detailed as debug. This option is used by default;
Notice: Moderate reminder, mostly used in the product environment;
Warning: displays only important warning information;
Logfile: Specifies the log output path. The default value is stdout, which indicates that the log is output to the screen. In the daemon mode, the log is output to/dev/null;
If you want to output logs to syslog, you can start syslog-enabled yes. The default value of this option is no.
Databases: specifies the number of databases. The default value is 16. The default value is DB 0.
The following are snapshot-related settings:
Save : Specifies the time to refresh the snapshot to the disk. This option has two attribute values, which are triggered only when both of them are met. You can set multiple levels, for example, the default parameter file is set as follows:
Save 900 1: triggered when the key value changes at least once every 900 seconds (15 minutes;
Save 300 10: triggered when the key value changes at least 10 times every 300 seconds (5 minutes;
Save 60 10000: triggered when the key value is changed at least 10000 times every 60 seconds;
Rdbcompression: The default value is yes. When the dump database is used, LZF is used to compress string objects. If the CPU resources are insufficient, set it to no and choose not to compress;
Dbfilename: The default value is dump. rdb. The name of the file that is dumped to the file system;
Dir: the default value./, that is, the storage path of the dump data file in the current directory;
The following are settings related to replication. replication is disabled by default. Therefore, the LIST Parameters in the default parameter file are commented out.
# Slaveof : Specifies the master ip address and port used to create an image service;
# Masterauth : If a password is configured for the master node, you need to set the password here;
Slave-serve-stale-data: The default value is yes. When slave loses the connection to the master, or the replication is still being processed, slave may have the following two manifestations:
When the value of this parameter is yes, slave continues to respond to client requests, although the data is not synchronized or even has no data (in the case of initial synchronization );
When the value of this parameter is no, slave will return the error message "SYNC with master in progreee;
# Repl-ping-slave-period: the default value is 10. This parameter specifies the period in which the Server Load balancer will periodically ping the master;
# Repl-timeout: The default value is 60, indicating the timeout time. Note that this parameter includes the time for batch data transmission and ping response.
The following are security-related settings:
# Requirepass: specify a password. You must use a password to connect to the client;
# Rename-command: redefinition command. For example, rename the CONFIG command to a complicated name:
Rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52;
Rename-command CONFIG "": cancel this command;
The following are settings for resource restrictions:
# Maxclients: specifies the maximum number of concurrent connections on the client. There is no limit by default until redis cannot create a new process. setting this parameter to 0 also means no restriction, if a value is specified for this parameter, when the concurrent connection reaches the specified value, redis closes all new connections and returns the 'max number of clients reached' error message;
# Maxmemory: sets the maximum memory available for redis. When the maximum memory size is reached, redis tries to delete the key value according to the configured recycle policy. If the key value cannot be deleted, or the retention policy is set to not cleared, redis will return an error message to the memory sending request. This parameter is useful when redis is used as the cache for a level-1 LRU.
# Maxmemory-policy: The default value is volatile-lru. You can specify a clearing policy using the following methods:
Volatile-lru-> remove the key with an expire set using an LRU algorithm
Allkeys-lru-> remove any key accordingly to the LRU algorithm
Volatile-random-> remove a random key with an expire set
Allkeys-> random-> remove a random key, any key
Volatile-ttl-> remove the key with the nearest expire time (minor TTL)
Noeviction-> don't expire at all, just return an error on write operations
# Maxmemory-samples: The default value is 3. The LRU and minimum TTL policies are not rigorous but approximate estimation methods. Therefore, you can select a sampling value for check.
The following are the append only Mode settings. By default, redis uses the asynchronous mode to dump data to the disk. In extreme cases, this may lead to the loss of some data (such as sudden server downtime ), if the data is important and you do not want to lose it, You can enable the direct write mode. In this mode, redis will synchronize all received write operations to appendonly. in the aof file, this file will rebuild all data in the memory when the redis service is started. Note that this mode has a significant impact on performance.
Appendonly: The default value is no, indicating whether the direct write mode is enabled;
# Appendfilename: default file name in direct write mode: appendonly. aof;
Appendfsync: Call the fsync () method to allow the operating system to write data to the disk. The data synchronization mode is as follows:
Always: calls every time, such as security, but the slowest speed;
Everysec: synchronization per second, which is also the default method;
No: fsync is not called. The operating system determines when to synchronize data, such as the quick mode;
No-appendfsync-on-rewrite: The default value is no. When the AOF fsync policy is set to always or everysec, the background save process performs a large number of I/O operations. In some linux configurations, redis may block excessive fsync () calls.
Auto-aof-rewrite-percentage: 100 by default
Auto-aof-rewrite-min-size: Default Value: 64 mb
The following are settings related to slow logs used to record queries whose execution time exceeds the threshold value. The execution time does not include the time used for I/O operations or sending data to the client, but the time spent for executing commands (that is, the time when the thread is blocked and cannot accept other requests ):
Slowlog-log-slower-than: Default Value: 10000. Unit: microseconds. It is defined as the threshold value for slow execution;
Slowlog-max-len: The default value is 1024, which is the maximum data of slow logs. Note that this will occupy content resources. If you want to clear it, You can execute the slowlog reset command;
The following settings are related to the virtual memory. The virtual memory version 2.4 is discarded.
Vm-enabled no
Vm-swap-file/tmp/redis. swap
Vm-max-memory 0
Vm-page-size 32
Vm-pages 134217728
Vm-max-threads 4
The settings related to advanced configuration are as follows:
Hash-max-zipmap-entries: The default value is 512. When the number of elements in a map reaches the maximum value but the length of the maximum element does not reach the set threshold value, its HASH encoding adopts a special method (more effective use of memory ). This parameter is used in combination with the following parameters to set these two thresholds. Set the number of elements;
Hash-max-zipmap-value: the default value is 64. It sets the maximum length of the element value in map.
List-max-ziplist-entries: The default value is 512. Similar to hash, a list array that meets the condition also uses a special method to save space.
List-max-ziplist-value: the default value is 64.
Set-max-intset-entries: The default value is 512. When the data in the set type is numeric and the number of integer elements in the set cannot exceed the specified value, a special encoding method is used.
Zset-max-ziplist-entries: The default value is 128, which is similar to hash and list.
Zset-max-ziplist-value: the default value is 64.
Activerehashing: The default value is yes, which is used to control whether to automatically recreate the hash. Active rehashing uses 1 microsecond cpu time sorting every 100 microseconds to reorganize the Redis hash table. Rebuild is implemented through a lazy method. The more operations are performed to write data to the hash table, the more rehashing steps are required. If the server is currently idle, The rehashing operation will be executed all the time. If you have high real-time requirements and it is difficult to accept the latency of 2 microseconds from time to time in redis, you can set activerehashing to no. Otherwise, we recommend setting it to yes to save memory space.
The following settings are available:
Include: used to specify other parameter files.

2.4 start redis
/Usr/local/webserver/redis/src/redis-server/usr/local/webserver/redis/6380. conf
/Usr/local/webserver/redis/src/redis-server/usr/local/webserver/redis/6379. conf
/Usr/local/webserver/redis/src/redis-server/usr/local/webserver/redis/6381. conf

You can use netstat-ntl to check whether the startup is successful.
[Root @ localhost redis] # netstat-ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN
Tcp 0 0 192.168.1.21: 6379 0.0.0.0: * LISTEN
Tcp 0 0 0.0.0.0: 20587 0.0.0.0: * LISTEN
Tcp 0 0 0.0.0.0: 875 0.0.0.0: * LISTEN
Tcp 0 0 192.168.1.21: 6380 0.0.0.0: * LISTEN
Tcp 0 0 192.168.1.21: 6381 0.0.0.0: * LISTEN

2.5 disable redis
/Usr/local/webserver/redis/src/redis-cli-h 192.168.1.21-p 6380 shutdown
/Usr/local/webserver/redis/src/redis-cli-h 192.168.1.21-p 6379 shutdown
/Usr/local/webserver/redis/src/redis-cli-h 192.168.1.21-p 6381 shutdown

Step 3: Install phpredis (PHP extension of REDIS)
Unzip master
Cd phpredis-master/
/Usr/local/webserver/php5/bin/phpize
./Configure -- with-php-config =/usr/local/webserver/php5/bin/php-config
Make & make install
Vi/usr/local/webserver/php5/etc/php. ini
Added: extension = "redis. so"
Run/usr/local/webserver/php5/bin/php-m to check whether there are any redis extensions, or browse a phpinfo file to check whether there are redis extensions.


In addition, redis has a web management tool phpRedisAdmin. After trying it out, you can try it out if you are interested.


Tags-centos, redis, phpredis

Original article address: Install Redis 2.6.13 and phpRedis extensions in CentOS 6.4. Thank you for sharing 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.