redis學習筆記1--安裝、啓動、關閉

// 下載
ming@ming-VirtualBox:~$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz
// 安裝
ming@ming-VirtualBox:~$ tar zxvf redis-3.0.7.tar.gz
root@ming-VirtualBox:~# cd redis-3.0.7/
root@ming-VirtualBox:~# make
root@ming-VirtualBox:~# make test
root@ming-VirtualBox:~# make install

// 經過初始化腳本啓動Redis  redis

root@ming-VirtualBox:~# cd utils/
root@ming-VirtualBox:~# cp redis_init_script /etc/init.d/redis_6379
root@ming-VirtualBox:~# mkdir /etc/redis   
root@ming-VirtualBox:~# mkdir -p /var/redis/6379
root@ming-VirtualBox:~# cp redis.conf /etc/redis/6379.cnf
// 簡單地修改2個配置參數

root@ming-VirtualBox:~# vi /etc/redis/6379.conf

...... shell

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
......
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/redis/6379
......

// 啓動redis
ming@ming-VirtualBox:~$ sudo /etc/init.d/redis_6379 start
Starting Redis server...
12912:M 15 Mar 14:23:19.873 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 12912
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               


12912:M 15 Mar 14:23:19.881 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
12912:M 15 Mar 14:23:19.882 # Server started, Redis version 3.0.7
12912:M 15 Mar 14:23:19.882 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
12912:M 15 Mar 14:23:19.883 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
12912:M 15 Mar 14:23:19.883 * The server is now ready to accept connections on port 6379

// 解決啓動中出現的warnings
warning 1: 
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
解釋:'somaxconn'定義了系統中每個端口最大的監聽隊列的長度,這是個全局的參數,默認值爲128。
處理:
root@ming-VirtualBox:~# echo 511 >/proc/sys/net/core/somaxconn
root@ming-VirtualBox:~# echo "net.core.somaxconn = 551" > /etc/sysctl.conf
warning 2:
overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
解釋:'overcommit_memory'指定了內核針對內存分配的策略,其值能夠是0、一、2。                               
0 -- 表示內核將檢查是否有足夠的可用內存供應用進程使用;若是有足夠的可用內存,內存申請容許;不然,內存申請失敗,並把錯誤返回給應用進程。 
1 -- 表示內核容許分配全部的物理內存,而無論當前的內存狀態如何。
2 -- 表示內核容許分配超過全部物理內存和交換空間總和的內存。
處理
root@ming-VirtualBox:~# echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
root@ming-VirtualBox:~# echo 1 > /proc/sys/vm/overcommit_memory
warning 3:
you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
解釋:'Transparent Huge Pages (THP)'是一個使管理Huge Pages自動化的抽象層。目前好像問題挺多,不少的數據庫產品都是要求(建議)關閉該功能的。
處理:
root@ming-VirtualBox:~# echo never > /sys/kernel/mm/transparent_hugepage/enabled
// 再次啓動redis
ming@ming-VirtualBox:~$ sudo /etc/init.d/redis_6379 start &
ming@ming-VirtualBox:~$ ss -nat | grep 6379
LISTEN     0      511          *:6379                     *:*                  
LISTEN     0      511         :::6379                    :::*

// 關閉redis  數據庫

ming@ming-VirtualBox:~$ sudo redis-cli SHUTDOWN
2497:M 15 Mar 15:29:43.531 # User requested shutdown...
2497:M 15 Mar 15:29:43.531 * Saving the final RDB snapshot before exiting.
2497:M 15 Mar 15:29:43.535 * DB saved on disk
2497:M 15 Mar 15:29:43.535 # Redis is now ready to exit, bye bye...
[1]+  Done                    sudo /etc/init.d/redis_6379 start
相關文章
相關標籤/搜索