歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Redis的部署使用文檔

Redis的部署使用文檔

日期:2017/2/28 15:30:01   编辑:Linux教程

簡述:Redis是一個key-value存儲系統。和Memcached類似,它支持存儲的value類型相對更多,包括string(字符串)、list(鏈表)、set(集合)和zset(有序集合)。這些數據類型都支持push/pop、add/remove及取交集並集和差集及更豐富的操作,而且這些操作都是原子性的。在此基礎上,redis支持各種不同方式的排序。與memcached一樣,為了保證效率,數據都是緩存在內存中。區別的是redis會周期性的把更新的數據寫入磁盤或者把修改操作寫入追加的記錄文件,並且在此基礎上實現了master-slave(主從)同步。

環境:CentOS 5.5 x64

下載安裝:

  1. cd /root/tools
  2. wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz
  3. tar zxvf redis-2.4.2.tar.gz
  4. cd redis-2.4.2
  5. make && make install
  6. cp redis.conf /etc/
  7. cd
  1. vi /etc/redis.conf
  1. daemonize yes
  2. pidfile /var/run/redis.pid
  3. port 6379
  4. #bind 127.0.0.1
  5. timeout 600
  6. loglevel notice
  7. logfile /elain/logs/redis/redis.log
  8. databases 16
  9. save 900 1
  10. save 300 10
  11. save 60 10000
  12. rdbcompression yes
  13. dbfilename dump.rdb
  14. dir /elain/data/redis/
  15. # maxclients 128
  16. appendonly yes
  17. appendfilename appendonly.aof
  18. # appendfsync always
  19. appendfsync everysec
  20. # appendfsync no
  21. requirepass elain
  22. no-appendfsync-on-rewrite no
  23. auto-aof-rewrite-percentage 100
  24. auto-aof-rewrite-min-size 64mb
  25. slowlog-log-slower-than 10000
  26. slowlog-max-len 1024
  27. really-use-vm yes
  28. vm-enabled yes
  29. vm-swap-file /tmp/redis.swap
  30. vm-max-memory 0
  31. vm-page-size 32
  32. vm-pages 134217728
  33. vm-max-threads 4
  34. hash-max-zipmap-entries 512
  35. hash-max-zipmap-value 64
  36. list-max-ziplist-entries 512
  37. list-max-ziplist-value 64
  38. set-max-intset-entries 512
  39. zset-max-ziplist-entries 128
  40. zset-max-ziplist-value 64
  41. activerehashing yes
  42. # include /path/to/local.conf
  43. # include /path/to/other.conf

啟動:

  1. redis-server /etc/redis.conf

開機加自啟動:

  1. echo "redis-server /etc/redis.conf" >>/etc/rc.local

測試:

  1. [root@md03 ~]# redis-cli -a elain
  2. redis 127.0.0.1:6379> set elain 123456
  3. OK
  4. redis 127.0.0.1:6379> get elain
  5. "123456"

查看狀態信息:

  1. [root@md04 ~]# redis-cli info
  2. redis_version:2.4.2
  3. redis_git_sha1:00000000
  4. redis_git_dirty:0
  5. arch_bits:64
  6. multiplexing_api:epoll
  7. process_id:2204
  8. uptime_in_seconds:25
  9. uptime_in_days:0
  10. lru_clock:2013834
  11. used_cpu_sys:0.00
  12. used_cpu_user:0.00
  13. used_cpu_sys_children:0.00
  14. used_cpu_user_children:0.00
  15. connected_clients:1
  16. connected_slaves:0
  17. client_longest_output_list:0
  18. client_biggest_input_buf:0
  19. blocked_clients:0
  20. used_memory:17505392
  21. used_memory_human:16.69M
  22. used_memory_rss:1617920
  23. used_memory_peak:17496792
  24. used_memory_peak_human:16.69M
  25. mem_fragmentation_ratio:0.09
  26. mem_allocator:jemalloc-2.2.1
  27. loading:0
  28. aof_enabled:1
  29. changes_since_last_save:5
  30. bgsave_in_progress:0
  31. last_save_time:1320372561
  32. bgrewriteaof_in_progress:0
  33. total_connections_received:1
  34. total_commands_processed:0
  35. expired_keys:0
  36. evicted_keys:0
  37. keyspace_hits:2
  38. keyspace_misses:8
  39. pubsub_channels:0
  40. pubsub_patterns:0
  41. latest_fork_usec:0
  42. vm_enabled:1
  43. role:master
  44. aof_current_size:237
  45. aof_base_size:237
  46. aof_pending_rewrite:0
  47. vm_conf_max_memory:0
  48. vm_conf_page_size:32
  49. vm_conf_pages:134217728
  50. vm_stats_used_pages:3
  51. vm_stats_swapped_objects:3
  52. vm_stats_swappin_count:0
  53. vm_stats_swappout_count:3
  54. vm_stats_io_newjobs_len:0
  55. vm_stats_io_processing_len:0
  56. vm_stats_io_processed_len:0
  57. vm_stats_io_active_threads:0
  58. vm_stats_blocked_clients:0
  59. db0:keys=4,expires=0

主從同步配置:
只需把/etc/redis.conf 復制到 從機上,主、從機上把127.0.0.1 IP 改成本機ip,然後在從機上的redis.conf 裡添加以下幾行,重啟即可:

  1. slave-serve-stale-data yes
  2. slaveof 主服務器IP 6379
  3. masterauth <master-password>

注:以上主從配置做了密碼驗證,也可不做驗證,不用加masterauth 選項

Copyright © Linux教程網 All Rights Reserved