http://www.linuxidc.com/Linux/2016-09/135071.htm

环境:CentOS 7.0 Redis 3.2.1

Redis的安装与启动

这里我把Redis放在/home/linuxidc/software/下,所以在该目录下执行下列命令:

$ wget http://download.redis.io/releases/redis-3.2.1.tar.gz
$ tar xzf redis-3.2.1.tar.gz
$ cd redis-3.2.1
$ make

至此Redis已经安装完成,首先试一下能不能把启动:

启动命令(在/home/linuxidc/software/redis-3.2.1目录下执行):

[root@localhost redis-3.2.1]# ./src/redis-server ../redis.conf

如下:

常见问题及解决方法

根据上图中的警告信息,下边是具体的解决方法

1、启动的时候没有设置配置文件

这个版本的时候需要指定,如果不指定的话,在后期修改了配置文件不会起到对应的效果

11292:C 25 Jul 13:13:58.034 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf

这个说的是在启动的时候要制定配置文件,如果没有指定的话就会按照默认的配置,因此我们要制定具体的位置,具体命令为:

[root@localhost src]# ./redis-server ../redis.conf

2、启动时报错及解决方法

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

2、WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

解决方法其实按照上边的说明就可以解决

第一个警告两个方式解决(overcommit_memory)

echo "vm.overcommit_memory=1" > /etc/sysctl.conf  或 vi /etcsysctl.conf

然后reboot重启机器,重启之后执行下边的内容

echo 1 > /proc/sys/vm/overcommit_memory  不需要启机器就生效

第二个警告解决

echo 511 > /proc/sys/net/core/somaxconn

其实在报错信息的时候已经给出了解决的方法,按照给定的具体的方法解决即可。

3、在上述 2 中的解决方法的一些参数说明

(1)overcommit_memory参数说明:

设置内存分配策略(可选,根据服务器的实际情况进行设置)
/proc/sys/vm/overcommit_memory
可选值:0、1、2。

0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

注意:redis在dump数据的时候,会fork出一个子进程,理论上child进程所占用的内存和parent是一样的,比如parent占用 的内存为8G,这个时候也要同样分配8G的内存给child,如果内存无法负担,往往会造成redis服务器的down机或者IO负载过高,效率下降。所 以这里比较优化的内存分配策略应该设置为 1(表示内核允许分配所有的物理内存,而不管当前的内存状态如何)。

(2)这里又涉及到Overcommit和OOM。
什么是Overcommit和OOM,在Unix中,当一个用户进程使用malloc()函数申请内存时,假如返回值是NULL,则这个进程知道当前没有可用内存空间,就会做相应的处理工作。许多进程会打印错误信息并退出。
Linux使用另外一种处理方式,它对大部分申请内存的请求都回复”yes”,以便能跑更多更大的程序。因为申请内存后,并不会马上使用内存。这种技术叫做Overcommit。
当内存不足时,会发生OOM killer(OOM=out-of-memory)。它会选择杀死一些进程(用户态进程,不是内核线程),以便释放内存。

(3)Overcommit的策略

Linux下overcommit有三种策略(Documentation/vm/overcommit-accounting):

  • 启发式策略。合理的overcommit会被接受,不合理的overcommit会被拒绝。
  • 任何overcommit都会被接受。
  • 当系统分配的内存超过swap+N%*物理RAM(N%由vm.overcommit_ratio决定)时,会拒绝commit。

overcommit的策略通过vm.overcommit_memory设置。
overcommit的百分比由vm.overcommit_ratio设置。

echo 2 > /proc/sys/vm/overcommit_memory
echo 80 > /proc/sys/vm/overcommit_ratio

当oom-killer发生时,linux会选择杀死哪些进程选择进程的函数是oom_badness函数(在mm/oom_kill.c中),该函数会计算每个进程的点数(0~1000)。点数越高,这个进程越有可能被杀死。每个进程的点数跟oom_score_adj有关,而且oom_score_adj可以被设置(-1000最低,1000最高)。

设置Redis外网可访问

值得注意的是在3.2.0以后的新版本中引入了一种proteced mode 模式,详见:http://redis.io/topics/security

在不修改配置文件任何内容的情况下,有以下几个默认的配置:

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 # By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes # Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared

简单的就是:

bind 127.0.0.1
protected-mode yes
# requirepass foobared

默认绑定的是127.0.01,默认开启了:protected-mode模式,按照官方的说法,如果默认开启了protected-mode模式在没有配置绑定IP和密码的情况下,是只允许回环地址进行访问的,就只允许127.0.0.1进行访问,那我们就在默认的配置下进行启动,通过SSH工具在其他机器上进行访问,看看运行的效果:

[root@localhost redis-3.2.1]# ./src/redis-server ../redis.conf

【转】CentOS 7.0 安装Redis 3.2.1详细过程和使用常见问题的更多相关文章

  1. CentOS 7.3 安装redis 4.0.2服务

    CentOS 7.3 安装redis 4.0.2服务 1.下载解压 下载地址:/home/xiaoming/ wget http://download.redis.io/releases/redis- ...

  2. Redis学习笔记(1)- CentOS 6.4 安装Redis

    Redis学习笔记(1)- CentOS 6.4 安装Redis 2013.10.13     学习环境 vm 10.1 + 默认.新装的干净 CentOS 6.4  64BIT系统     准备 1 ...

  3. CentOS 7.0安装配置Vsftp服务器

    一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  4. CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB)

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...

  5. CentOS 7.0安装

    CentOS 7.0安装 本次通过虚拟机的方法安装CentOS 7.0操作系统,开启虚拟机后会出现以下界面 1.选择第一项,Install CentOS 7 (安装CentOS 7),进入下面的界面 ...

  6. CentOS 7.0安装配置Vsftp服务器步骤详解

    安装Vsftp讲过最多的就是在centos6.x版本中了,这里小编看到有朋友写了一篇非常不错的CentOS 7.0安装配置Vsftp服务器教程,下面整理分享给各位. 一.配置防火墙,开启FTP服务器需 ...

  7. CentOS 7.0 安装配置LAMP服务器方法(Apache+PHP+MariaDB)(转)

    转自:http://www.jb51.net/os/188488.html 作者:佚名 字体:[增加 减小] 来源:osyunwei  准备篇: CentOS 7.0系统安装配置图解教程 http:/ ...

  8. 【转发】【linux】【ftp】CentOS 7.0安装配置Vsftp服务器

    adduser -d /var/www/android -g ftp -s /sbin/nologin ftp2 一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firew ...

  9. CENTOS 7 下安装 REDIS 5.0.6 完整步骤

    第一步:下载redis安装包 wget   http://download.redis.io/releases/redis-5.0.6.tar.gz 第二步:解压压缩包 tar -zxvf redis ...

随机推荐

  1. 清北刷题冲刺 10-29 a.m

    遭遇 /* 因为选的楼是个集合,与顺序无关 而且总花费=c[1]+c[2]+c[3]+|h[1]-h[2]|+|h[2]-h[3]| 我们规定走的顺序从高到低,那么绝对值就可以去掉 所以就可以约掉中间 ...

  2. 在mac上使用sublime text3搭建opencv3开发环境

    安装sublime text3 打开mac终端,安装brew 安装opencv3,终端输入下面的coomand: brew install opencv@3 注意:@3表示安装的版本,如果不加@3,那 ...

  3. VC添加全局热键的方法

    VC添加全局热键的方法 这个方法靠谱 http://blog.csdn.net/lujianfeiccie2009/article/details/7498704 VC添加全局热键的方法 标签: bu ...

  4. 根据从redis缓存的数据查询出来,在从数据库中取出所有的数据,俩个数据进行比较,去掉重复,剩下库中新插入的数据,取出新数据,然后把redis中的缓存数据清空把从数据库中查出来的所有数据放到redis缓存中

    参考代码: public String getNewCenter(HttpServletRequest request,HttpServletResponse resonse){ JSONObject ...

  5. JavaScript高级程序设计第三版-读书笔记(1-3章)

    这是我第一次用markdown,也是我第一次在网上记录我自己的学习过程. 第一章 JavaScript主要由以下三个不同的部分构成 ECMAScript   提供核心语言功能 DOM     提供访问 ...

  6. spring动态线程池(实质还是用了java的线程池)

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. spring事物的管理方式

    Spring事务配置的五种方式 转载大神总结: https://blog.csdn.net/xuanjiewu/article/details/51604967: 自己总结:这里只总结spring编程 ...

  8. aspnetcore进程内托管的坑-非常规方法解决Log4Net不写日志的问题

    问题描述:Log4Net,本地测试一切正常,发布后,无法自动创建文件夹和日志文件,无法写入文件. 一.在项目中配置Log4Net 请参考我的上一篇博客 <aspnetcore配置log4net并 ...

  9. Subversion Server Edge的搭建与配置

    1.Subversion Server Edge的搭建 当在操作系统为64位的配置服务器上部署时只能够选择Collabnet Subversion Edge,它集合了Subversion所需要一切资源 ...

  10. Java面向对象_常用类库api——二分查找算法

    概念:又称为折半查找,优点是比较次数少,查找速度快,平均性能好:缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表. 例: public class Bi ...