Redis is an open source API that is written in ANSI C, supports the web, can be persisted in memory, key-value databases, and provides multiple languages. From March 15, 2010 onwards, the development work of Redis is hosted by VMware.
1. Environment
# Lsb_release
LSB Version:: core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32: Printing-4.0-noarch
Distributor Id:centos
Description:centos Release 5.8 (Final)
release:5.8
Codename:final
# getconf Long_bit
32
2. Download Redis
# CD/USR/LOCAL/SRC
# wget http://download.redis.io/releases/redis-2.8.9.tar.gz
3. Installing Redis
# tar Xzf redis-2.8.9.tar.gz
# CD redis-2.8.9
# makes or make cflags= "-march=i686" (Linux 32-bit will error, need to increase the execution parameters)
4. Configure Redis
# mkdir/usr/local/redis/{conf,run,db}-PV
# cd/usr/local/src/redis-2.8.9/
# CP Redis.conf/usr/local/redis/conf
# CD src/
# CP Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server mkreleasehdr.sh/usr/local/redis/
# cd/usr/local/redis/conf
# sed-i ' s/daemonize no/daemonize yes/' redis.conf
# ln-s/USR/LOCAL/REDIS/REDIS-CLI/USR/SBIN/REDIS-CLI
5. Start Redis
#/usr/local/redis/redis-server/usr/local/redis/conf/redis.conf
6. Check
# NETSTAT-TUNLP | grep Redis
# Ps-ef | grep Redis
[Email protected] ~]# REDIS-CLI
127.0.0.1:6379> Set Redis test
Ok
127.0.0.1:6379> Get Redis
"Test"
127.0.0.1:6379>
Configuration file Description (redis.conf):
Daemonize Yes #---The default value of No, which is used to customize whether the Redis service is running in daemon mode. ---
Pidfile/usr/local/webserver/redis/run/redis.pid #默认值/var/run/redis.pid, specify the process number file path for the Redis service, which you need to configure when running in daemon mode;
Port 6379 #默认值6379, specifying the ports for the Redis service
# bind 127.0.0.1 #绑定ip, default is all the network device of the machine;
Timeout 0 #客户端空闲n秒后断开连接; The default is 0 to keep it open.
LogLevel Notice # # #设置服务端的日志级别, there are several options:
Debug: Record detailed information for development or commissioning;
VERBOSE: Provide a lot of useful information, but not as detailed as debug, the default is this option;
Notice: Moderate reminders, more for the product environment;
Warning: Only important warning messages are displayed;
LogFile stdout # #指定日志的输出路径, the default value stdout, indicating output to the screen, the Guardian mode is output to/dev/null;
If you want to output the log to Syslog, you can start syslog-enabled Yes, which defaults to No.
# syslog-enabled No
Databases # # # #指定数据库的数量, default is 16, the default database used is DB 0.
----The following snapshot-related settings:------
# Save <seconds> <changes> # #指定多长时间刷新快照至磁盘, this option has two attribute values and only fires when two attribute values are met; You can set multiple levels, such as the default parameter file:
Save 900 1: Every 900 seconds (15 minutes) at least once the key value change is triggered;
Save 300 10: Every 300 seconds (5 minutes) at least 10 times the key value change is triggered;
Save 60 10000: Every 60 seconds at least 10,000 times the key value change is triggered;
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression Yes # #默认值yes, when the dump database using LZF compressed string object, if the CPU resource is more tense, can be set to No, choose not to compress;
Rdbchecksum Yes
# The filename where to dump the DB database file name
Dbfilename Dump.rdb # #默认值dump. rdb,dump to file names in the filesystem
DIR/USR/LOCAL/WEBSERVER/REDIS/DB # #默认值./, the current directory, dump out the storage path of the data file;
----The following replication-related settings, replication is not enabled by default, so the following table parameters are commented on in the default parameter file----
# slaveof <masterip> <masterport> # #指定主端ip和端口 for creating a mirror service
# Masterauth <master-password> # #如果master配置了密码的话, here also need to do settings;
Slave-serve-stale-data Yes # #默认值yes. When slave loses a connection to the master side, or the copy is still being processed, the slave will have the following two performances:
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 (appearing in the case of initial synchronization);
When the value of this parameter is no, slave returns the error message "SYNC with Master in Progreee";
Slave-read-only Yes # #默认从Redis是只读模式
# repl-ping-slave-period # # # #默认值10, specifying the period of slave to ping Master periodically;
# repl-timeout # #默认值60, specify the time-out. Note This parameter includes the time to bulk transfer data and ping the response.
------The following security-related settings------
# requirepass foobared # # #指定一个密码, the client connection is also required by the password to successfully connect;
# rename-command Config b840fc02d524045429941cc15f59e41cb7be6c52 # # #重定义命令, such as renaming the Config command to a very complex name:
# Rename-command CONFIG "" Cancels this command;
-----The following settings for resource throttling------
# maxclients 10000 # #指定客户端的最大并发连接数, the default is no limit until Redis cannot create a new process, setting the parameter value to 0 also means no limit, and if the parameter specifies a value, Redis closes all new connections when the concurrent connection reaches the specified value. and returns the error message ' Max number of clients reached ';
# maxmemory <bytes> # # #设置redis最大可使用内存. When the maximum memory is reached, Redis attempts to delete the key values according to the set recycle policy. If the key value cannot be deleted, or if the retention policy is set to not clear, Redis returns an error message to the memory-issuing request. This parameter is useful when Redis is cached as a first-level LRU.
# maxmemory-policy VOLATILE-LRU # # #默认值volatile-lru, specify the purge policy in the following ways:
VOLATILE-LRU, remove the key with a 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 a error on write operations
# maxmemory-samples 3 # # #默认值3, LRU and minimum TTL policies are not rigorous strategies, but approximate estimates, so you can choose to sample values for inspection.
-----The following configuration for append----
Only mode settings, by default Redis asynchronously dump data to disk, in extreme cases this may cause the loss of some data (such as sudden server outage), if the data is more important, do not want to lose, you can enable the direct write mode, In this mode, Redis synchronizes all the received writes to the Appendonly.aof file, which rebuilds all the data in memory when the Redis service starts. Note that this pattern has a very large impact on performance.
AppendOnly No # #默认值no, specifies whether write-through mode is enabled;
# appendfilename Appendonly.aof # # #直写模式的默认文件名appendonly. aof
Appendfsync: Call Fsync () mode to let the operating system write data to disk, data synchronization mode, there are the following modes:
Always: Called every time, such as security, but the slowest speed;
Everysec: Synchronization per second, which is also the default mode;
No: Do not call Fsync, the operating system determines when synchronization, such as fast mode;
No-appendfsync-on-rewrite: Default Value 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 too many fsync () calls.
Auto-aof-rewrite-percentage: Default Value 100
Auto-aof-rewrite-min-size: Default Value 64MB
# Appendfsync Always
Appendfsync everysec
# Appendfsync No
-----The following settings related to Advanced configuration----
Hash-max-zipmap-entries: The default value of 512, when the number of elements of a map reaches the maximum, but the maximum element length does not reach the set threshold, its hash encoding takes a special way (more efficient 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 of 64, sets the maximum length of the value of the element in the map;
List-max-ziplist-entries: Default value 512, similar to hash, the list array that satisfies the condition also takes a special way to save space.
List-max-ziplist-value: Default Value 64
Set-max-intset-entries: The default value of 512, when the data in a set type is a numeric type, and the number of integral elements in set does not exceed the specified value, a special encoding is used.
Zset-max-ziplist-entries: Default value of 128, similar to hash and list.
Zset-max-ziplist-value: Default Value 64
Activerehashing: The default is yes to control whether the hash is automatically rebuilt. Active rehashing uses 1 microseconds of CPU time per 100 microseconds to reorganize the Redis hash table. Rebuilding is a lazy way, the more you write a hash table, the more steps you need to perform rehashing, and the rehashing operation will execute if the server is currently idle. If the requirement for real-time is high and it is difficult to accept the 2 microsecond latency that Redis occasionally has, you can set activerehashing to No, otherwise the recommended setting is yes to save memory space.
This article is from the "Square Hill" blog, please be sure to keep this source http://523514.blog.51cto.com/513514/1410021