CentOS installation Redis and Php-redis tutorial

Source: Internet
Author: User
Tags hash install php memory usage redis centos install redis redis tutorial

CentOS Install Redis shell script
#!/bin/sh
#http://zggsdy.blog.163.com/blog/static/28782049201331825523781/
cd/web/soft/php
If [-D "redis-2.8.13"];then
RM-RF redis-2.8.13
Fi
Tar xzvf redis-2.8.13.tar.gz
CD redis-2.8.13
Make
Make install
Sed-n '/daemonize no/p ' redis.conf | Sed-i ' s/daemonize no/daemonize yes/g ' redis.conf
If [F "/etc/redis.conf"]; then
Rm-f/etc/redis.conf
Fi
CP redis.conf/etc/
Cd.. /
RM-RF redis-2.8.13
#cp/web/conf/redis/redis.conf/etc/
#启动
Redis-server/etc/redis.conf
#查看进程有没有成功启动
Ps-ef | grep Redis
#测试输入一个键值
REDIS-CLI set Test "123456"
#获取键值
REDIS-CLI Get Test
#关闭redis
#redis-cli shutdown//Close all
#redis-cli-p 6379 shutdown//Turn off the Redis on port 6397
#关闭以后缓存的数据会自动dump到硬盘上
Redis configuration file Chinese description, this configuration is for 2.4, I now installed on the server is 2.8, can not be copied configuration
############################## Chinese Description: ################################
#1, if the next process runs, the default is no
#daemonize No
#2, such as after the process of running, you need to specify a PID, default to/var/run/redis.pid
#pidfile/var/run/redis.pid
#3, listening port, defaults to 6379
#port 6379
#4, binding host IP, default value is 127.0.0.1 (note)
#bind 127.0.0.1
#5, timeout time, defaults to 300 (sec)
#timeout 300
#6, logging level, with 4 optional values, Debug,verbose (default), notice,warning
#loglevel verbose
#7, logging mode, default value is stdout
#logfile stdout
#8, the number of available databases, the default value is 16, and the default database is 0
#databases 16
#9 to indicate how many updates have been done in a long period of time to synchronize the data to the data file. This can be a combination of conditions, such as the default configuration file settings, set three conditions.
At least 1 keys have been changed in #900秒 (15 minutes)
#save 900 1
At least 10 keys have been changed in #300秒 (5 minutes)
#save 300 10
#10, whether to compress data when it is stored to the local database, by default Yes
#rdbcompression Yes
#11, local database filename, default value is Dump.rdb
#dbfilename/root/redis_db/dump.rdb
#12, the local database holds the path, and the default value is./
#dir/root/redis_db/
#13, set the IP and port of the primary service when this machine is from service (note)
#slaveof
#14, set the connection password for the primary service when this computer is from service (note)
#masterauth
#15, Connection password (note)
#requirepass foobared
#16, maximum number of client connections, default unrestricted (note)
#maxclients 128
#17, set the maximum memory, the maximum memory settings, Redis will first attempt to clear the expired or expiring key, when this method is processed, the maximum memory settings, will no longer write operations. Comments
#maxmemory
#18 whether logging after each update operation, if not turned on, may result in loss of data over time during a power outage. Because the Redis itself synchronizes data files according to the above save condition, some data will only exist in memory for a period of time. The default value is no
#appendonly Yes
#19, update the log file name, the default value is appendonly.aof (note)
#appendfilename/root/redis_db/appendonly.aof
#20, there are 3 optional values for updating the log criteria. No means that the operating system synchronizes the data cache to disk, and always indicates that Fsync () is manually invoked after each update operation to write the data to disk, Everysec is synchronized every second (the default).
#appendfsync everysec
#21, whether virtual memory is used, and the default value is no
#vm-enabled Yes
#22, virtual memory file path, default value is/tmp/redis.swap, not multiple Redis instance sharing
#vm-swap-file/tmp/redis.swap
#23, save all data larger than vm-max-memory into virtual memory, regardless of how small the vm-max-memory is set, all index data is stored in memory (Redis index data is the keys), that is to say, when the vm-max-memory is set to 0 , in fact, all of the value exists on the disk. The default value is 0.
#vm-max-memory 0
#24, virtual memory files are stored in blocks, 32bytes per block
#vm-page-size 32
#25, the maximum number of virtual internal files
#vm-pages 134217728
#26, you can set the number of threads to access the swap file, set the best not to exceed the machine's core, if set to 0, then all operations on the swap file is serial. It may cause a long delay, but there is a good guarantee of data integrity.
#vm-max-threads 4
#27, the small output cache is put together so that multiple responses can be sent to the client in a TCP packet, and I am not very clear about the exact principle and the real effect. So according to the notes, you're not sure when you set it to Yes.
#glueoutputbuf Yes
#28, the hash data structure was introduced in Redis 2.0. When the hash contains more than the specified number of elements and the largest element does not exceed the critical value, the hash will be stored in a special encoding (greatly reducing memory usage), where the two thresholds can be set
#hash-max-zipmap-entries 64
#29, the maximum value of an element in a hash
#hash-max-zipmap-value 512
#30, Redis will use 1 milliseconds of CPU time per 100 milliseconds to hash the Redis hash table to reduce memory usage. When you have a very stringent real-time requirement in your usage scenario, you cannot accept Redis's 2 millisecond delay to the request, and configure this to No. If you do not have such stringent real-time requirements, you can set to Yes so that you can free up memory as quickly as possible
#activerehashing Yes
Install PHP extensions Redis
#!/bin/sh
#https://github.com/nicolasff/phpredis/zipball/master
cd/web/soft/php
If [-D "nicolasff-phpredis-94e0649"];then
RM-RF nicolasff-phpredis-94e0649
Fi
Unzip Phpredis-2.2.5.zip
CD nicolasff-phpredis-94e0649
/web/server/php/bin/phpize
./configure--with-php-config=/web/server/php/bin/php-config
Make && make install
Phpini= "/web/server/php/etc/php.ini"
Sed-i ' 908a extension = "redis.so" ' $PHPINI
Cd.. /
RM-RF nicolasff-phpredis-94e0649
Echo '
$redis = new Redis ();
$redis->connect ("127.0.0.1", 6379);
$redis->set ("test", "Hello world!");
echo $redis->get ("test");
?> ' >/root/redis.php
/web/server/php/bin/php/root/redis.php

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.