In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what are the common operations of Redis under Linux", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the common operations of Redis under Linux" can help you solve your doubts.
Configuration of Redis
Install under Linux
] # wget http://download.redis.io/releases/redis-2.8.17.tar.gz]# tar xzf redis-2.8.17.tar.gz] # cd redis-2.8.17] # make
Start the redis service
] # cd src] #. / redis-server
The above startup redis uses the default configuration, or you can tell redis to use the specified configuration through the startup parameters
] #. / redis-server.. / redis.conf
Connect redis
[root@localhost src] #. / redis-cli127.0.0.1:6379 >
Redis configuration
The configuration file for redis is located in the Redis installation directory and the file name is redis.conf.
You can view or set configuration items through the CONFIG command
Example:
127.0.0.1 notice 6379 > config get loglevel1) "loglevel" 2) "notice"
Use * to get all configuration items
127.0.1 dump.rdb 6379 > config get * 1) "dbfilename" 2) "dump.rdb" 3) "requirepass" 4) "5)" masterauth "6)" 7) "unixsocket" 8) "9)" logfile "10)" 11) "pidfile" 12) "/ var/run/redis.pid" 13) "maxmemory" 14) "0" 15) "maxmemory-samples" 16) "3" 17) "timeout" "18)" 0 "19)" tcp-keepalive "20)" 0 "21)" auto-aof-rewrite-percentage "22)" 10023) "auto-aof-rewrite-min-size" 24) "67108864" 25) "hash-max-ziplist-entries" 26) "512" 27) "hash-max-ziplist-value" 28) "64" 29) "list-max-ziplist-entries" 30) "512" 31) "list-max -ziplist-value "32)" 64 "33)" set-max-intset-entries "34)" zset-max-ziplist-entries "36)" 12837) "zset-max-ziplist-value" 38) "64" 39) "hll-sparse-max-bytes" 40) "3000" 41) "lua-time-limit" 42) "5000" 43) "slowlog-log-slower-than" 44) "10000" 45) "latency-monitor-threshold" 46) "0" 47) "slowlog-max-len" 48) "12849)" port "50)" 6379 "51)" tcp-backlog "52)" databases "54)" 16 "55)" repl-ping-slave-period "56)" 10 "57)" repl-timeout "58)" 60 "59)" repl-backlog-size "60)" 1048576 "61)" repl " -backlog-ttl "62)" 3600 "63)" maxclients "64)" 10000 "65)" watchdog-period "66)" 0 "67)" slave-priority "68)" min-slaves-to-write "70)" 0 "71)" min-slaves-max-lag "72)" 10 "73)" hz "74)" 10 "75)" no-appendfsync-on-rewrite "76)" no "77) "slave-serve-stale-data" 78) "yes" 79) "slave-read-only" 80) "yes" 81) "stop-writes-on-bgsave-error" 82) "yes" 83) "daemonize" 84) "no" 85) "rdbcompression" 86) "yes" 87) "rdbchecksum" 88) "yes" 89) "activerehashing" 90) "yes" 91) "repl-disable-tcp-nodelay" 92) "no" 93) "aof-rewrite-incremental-fsync" 94) "yes" 95) "aof-load-truncated" 96) "yes" 97) "appendonly" 98) "no" 99) "dir" 100) / home/lxg/redis/redis-2.8.17/src "101)" maxmemory-policy "102)" volatile-lru "104)" appendfsync "105)" everysec "105)" save "106)" 3600 1,300 100 60 10000 "107)" loglevel The configuration items of "normal 000 slave 268435456 67108864 60 pubsub 33554432 8388608 60" 1111) "unixsocketperm" 268435456) "slaveof" 268435456) "notify-keyspace-events" 116) "bind" 118) "config get * redis.conf" are described as follows: 1. Redis does not run as a daemon by default. You can use yes to enable the daemon daemonize no2. Exe by modifying this configuration item. When Redis runs as a daemon, Redis writes pid to the / var/run/redis.pid file by default, and you can specify pidfile / var/run/redis.pid3 through pidfile. Specify the Redis listening port, and the default port is 6379. In a blog post, the author explained why 6379 is chosen as the default port, because 6379 has the number corresponding to MERZ on the phone button, and MERZ is taken from the name of Italian singer Alessia Merz port 63794. The bound host address bind 127.0.0.15. When the client is idle for how long to close the connection, if specified as 0, it means to turn off the function timeout 3006. Specifies the logging level. Redis supports a total of four levels: debug, verbose, notice, and warning. The default is verbose loglevel verbose7. The logging method defaults to standard output. If Redis is configured to run in daemon mode, and here the logging mode is configured as standard output, the log will be sent to / dev/null logfile stdout8. Set the number of databases. The default database is 0. You can use the SELECT command to specify the database id databases 169. 9 on the connection. Specify the length of time and the number of update operations to synchronize the data to the data file, and multiple conditions can be combined with three conditions provided in the save Redis default configuration file: save 9001 save 300 10 save 60 10000 represents 1 change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes), and 10000 changes in 60 seconds. 10. Specify whether to compress the data when storing to the local database. The default is that yes,Redis uses LZF compression. If you want to save CPU time, you can turn off this option, but it will cause the database file to become huge rdbcompression yes11. Specifies the local database file name, and the default value is dump.rdb dbfilename dump.rdb12. Specify the local database storage directory dir. / 13. Set the IP address and port of the master service when the machine is a slav service. When Redis starts, it automatically synchronizes data from master slaveof 14. When the master service sets password protection, the slav service connects to the master's password masterauth 15. 0. Set the Redis connection password. If the connection password is configured, the client needs to provide the password through the AUTH command when connecting to the Redis. By default, requirepass foobared16. Set the maximum number of client connections at a time. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that can be opened by Redis processes. If you set maxclients 0, there is no limit. When the number of client connections reaches the limit, Redis closes new connections and returns max number of clients reached error message maxclients 12817 to the client. Specify the maximum memory limit of Redis. Redis will load data into memory at startup. After reaching the maximum memory, Redis will first try to clear the expired or expiring Key. When this method is processed, the maximum memory setting will still be reached, and the write operation will no longer be performed, but the read operation can still be performed. Redis's new vm mechanism stores Key in memory and Value in swap area maxmemory 18. Specifies whether to log after each update operation. Redis writes data to disk asynchronously by default. If it is not enabled, it may result in data loss for a period of time in the event of a power outage. Because redis itself synchronizes data files according to the above save conditions, some data will only exist in memory for a period of time. The default is no appendonly no19. Specifies the update log file name, which defaults to appendonly.aof appendfilename appendonly.aof20. Specify the update log condition. There are three optional values: no: indicates that the operating system synchronizes the data cache to disk (fast) always: means to manually call fsync () after each update operation to write data to disk (slow, secure) everysec: means to synchronize every second (eclectic, default) appendfsync everysec21. Specify whether to enable the virtual memory mechanism, the default value is no, a brief introduction, the VM mechanism will be paged data storage, by the Redis less visited pages that is cold data swap to the disk, the visited pages are automatically swapped out to memory by the disk (in the following article I will carefully analyze the VM mechanism of Redis) vm-enabled no22. Virtual memory file path. Default is / tmp/redis.swap. Multiple Redis instances cannot share vm-swap-file / tmp/redis.swap23. All data larger than vm-max-memory is stored in virtual memory, no matter how small the vm-max-memory setting is, all index data is stored in memory (Redis's index data is keys), that is, when vm-max-memory is set to 0, all value actually exists on disk. The default value is 0 vm-max-memory 024. Redis swap files are divided into many page. An object can be stored on multiple page, but a page cannot be shared by multiple objects. Vm-page-size should be set according to the size of stored data. The author suggests that if many small objects are stored, the page size should be set to 32 or 64bytes. If you store large objects, you can use a larger page, or if you are not sure, use the default value of vm-page-size 3225. Set the number of page in the swap file, because the page table (a type of bitmap that indicates that the page is idle or used) is placed in memory, every 8 pages on disk will consume 1byte's memory. Vm-pages 13421772826. Set the number of threads to access the swap file, it is best not to exceed the number of cores of the machine, if set to 0, then all operations on the swap file are serial, which may cause a long delay. The default value is 4 vm-max-threads 427. Sets whether to merge smaller packets into a single packet when replying to the client. Default is to enable glueoutputbuf yes28. Specifies that when the number exceeds a certain number or the largest element exceeds a certain critical value, a special hashing algorithm hash-max-zipmap-entries 64 hash-max-zipmap-value 51229 is adopted. Specifies whether to activate reset hashing, which defaults to on (later on when introducing Redis's hashing algorithm) activerehashing yes30. Specify to include other configuration files that can use the same profile between multiple Redis instances on the same host, while each instance has its own specific profile include / path/to/local.conf parameter description
You can modify the configuration by modifying the redis.conf file or by using the config set command
127.0.0.1 6379 > config set loglevel 'notice'OK
How to stop / start / restart the redis service
The following content comes from: http://outofmemory.cn/code-snippet/37597/how-to-stop-start-restart-redis-server
If you installed redis with apt-get or yum install, you can stop / start / restart redis directly with the following command
/ etc/init.d/redis-server stop/etc/init.d/redis-server start/etc/init.d/redis-server restart
If redis is installed through source code, you can restart redis through the shutdown command of redis's client program redis-cli
Redis-cli-h 127.0.0.1-p 6379 shutdown
If none of the above methods successfully stops redis, the ultimate weapon kill-9 can be used.
Note:
1. Redis does not run as a daemon by default. You can use this configuration item to modify it and use yes to enable the daemon.
Daemonize no
\ 2. When Redis runs as a daemon, Redis writes pid to the / var/run/redis.pid file by default, which can be specified through pidfile
Pidfile / var/run/redis.pid
\ 3. Specify the Redis listening port, and the default port is 6379. In a blog post, the author explains why 6379 is chosen as the default port, because 6379 has the number corresponding to MERZ on the phone button, and MERZ is named after Italian singer Alessia Merz.
Port 6379
\ 4. Bound host address
Bind 127.0.0.1
5. When the client has been idle for how long, the connection is closed. If specified as 0, the function is disabled.
Timeout 300
\ 6. Specifies the logging level. Redis supports a total of four levels: debug, verbose, notice, and warning. The default is verbose.
Loglevel verbose
\ 7. Logging method. Default is standard output. If Redis is configured to run in daemon mode, and here the logging mode is configured as standard output, the log will be sent to / dev/null.
Logfile stdout
\ 8. Set the number of databases. The default database is 0. You can use the SELECT command to specify the database id on the connection.
Databases 16
\ 9. Specify how long and how many update operations will synchronize the data to the data file, which can be matched by multiple conditions.
Save
Three conditions are provided in the Redis default configuration file:
Save 900 1
Save 300 10
Save 60 10000
It represents 1 change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes), and 10000 changes in 60 seconds.
\ 10. Specify whether to compress data when stored in the local database. The default is that yes,Redis uses LZF compression. If you want to save CPU time, you can turn this option off, but it will cause the database file to become huge.
Rdbcompression yes
\ 11. Specifies the local database file name, which defaults to dump.rdb
Dbfilename dump.rdb
\ 12. Specify the local database storage directory
Dir. /
\ 13. Set the IP address and port of the master service when the machine is a slav service. When Redis starts, it automatically synchronizes data from master.
Slaveof
\ 14. When the master service is password protected, the password of the slav service connection master
Masterauth
\ 15. Set the Redis connection password. If the connection password is configured, the client needs to provide the password through the AUTH command when connecting to the Redis. It is disabled by default.
Requirepass foobared
\ 16. Set the maximum number of client connections at a time. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that can be opened by Redis processes. If you set maxclients 0, there is no limit. When the number of client connections reaches the limit, Redis closes the new connection and returns a max number of clients reached error message to the client
Maxclients 128
\ 17. Specify the maximum memory limit of Redis. Redis will load data into memory at startup. After reaching the maximum memory, Redis will first try to clear the expired or expiring Key. When this method is processed, the maximum memory setting will still be reached, and the write operation will no longer be performed, but the read operation can still be performed. Redis's new vm mechanism stores Key in memory and Value in swap area.
Maxmemory
\ 18. Specifies whether to log after each update operation. Redis writes data to disk asynchronously by default. If it is not enabled, it may result in data loss for a period of time in the event of a power outage. Because redis itself synchronizes data files according to the above save conditions, some data will only exist in memory for a period of time. Default is no
Appendonly no
\ 19. Specify the update log file name. Default is appendonly.aof.
Appendfilename appendonly.aof
\ 20. Specify the update log condition. There are three optional values: no: indicates that the operating system synchronizes the data cache to disk (fast) always: manually calls fsync () after each update operation to write data to disk (slow, secure) everysec: synchronizes once per second (eclectic, default)
Appendfsync everysec
\ 21. Specify whether to enable the virtual memory mechanism. The default value is no. For a brief introduction, the VM mechanism stores the data in pages. Redis will swap the cold data on the disk, which is less visited, and the pages that visit more will be automatically swapped out to memory by the disk (I will carefully analyze the VM mechanism of Redis in a later article).
Vm-enabled no
\ 22. Virtual memory file path. Default is / tmp/redis.swap, which cannot be shared by multiple Redis instances.
Vm-swap-file / tmp/redis.swap
\ 23. All data larger than vm-max-memory is stored in virtual memory, no matter how small the vm-max-memory setting is, all index data is stored in memory (Redis's index data is keys), that is, when vm-max-memory is set to 0, all value actually exists on disk. Default value is 0
Vm-max-memory 0
\ 24. Redis swap files are divided into many page. An object can be stored on multiple page, but a page cannot be shared by multiple objects. Vm-page-size should be set according to the size of the stored data. The author suggests that if many small objects are stored, the page size should be set to 32 or 64bytes. If large objects are stored, a larger page can be used. If you are not sure, use the default value.
Vm-page-size 32
\ 25. Set the number of page in the swap file, because the page table (a type of bitmap that indicates that the page is idle or used) is placed in memory, every 8 pages on disk will consume 1byte's memory.
Vm-pages 134217728
\ 26. Set the number of threads to access the swap file, it is best not to exceed the number of cores of the machine, if set to 0, then all operations on the swap file are serial, which may cause a long delay. The default value is 4
Vm-max-threads 4
\ 27. Sets whether to merge smaller packets into a single packet when replying to the client. Default is on.
Glueoutputbuf yes
\ 28. Specifies that a special hash algorithm is used when the number of elements exceeds a certain number or the largest element exceeds a critical value.
Hash-max-zipmap-entries 64
Hash-max-zipmap-value 512
\ 29. Specifies whether to activate reset hashing, which is enabled by default (more on later when introducing Redis's hashing algorithm)
Activerehashing yes
\ 30. Specify to include other profiles that can use the same profile between multiple Redis instances on the same host, while each instance has its own specific profile
Include / path/to/local.conf
After reading this, the article "what are the common operations of Redis under Linux" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
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.