ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 数据库 >> 其他数据库 >> redis学习笔记--安装、启动、关闭

redis学习笔记--安装、启动、关闭

来源:网络整理     时间:2016-03-15     关键词:

本篇文章主要介绍了"redis学习笔记--安装、启动、关闭",主要涉及到方面的内容,对于其他数据库感兴趣的同学可以参考一下: // 下载 ming@ming-VirtualBox:~$ wget http://download.redis.io/releases/redis-3.0....

// 下载
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 

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

......

# 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、1、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

以上就介绍了redis学习笔记--安装、启动、关闭,包括了方面的内容,希望对其他数据库有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_442277.html

相关图片

相关文章