redis用处很广泛,我不再啰嗦了,我按照网上教程想在linux上安装下,开始了踩坑过程,网上买了一个linux centos7.3,滴滴云的,巨坑无比啊,不建议大家用这家的! redis 为4.0,

1.登录云服务并下载安装:

首先登录不是root用户,需要切换下,执行sudo su切为root用户,感觉这样很不方便,于是咨询下,回复是这样的:

(1) 然后换回root用户了,开始wget下载,提示没有这个命令,好吧,开始安装它yum -y install wget

下载完后就解压, 执行:tar xzf redis-4.0.9.tar.gz

(2) 进入 cd redis-4.0.9,执行 make,此时有可能报错:

gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c  类似的;那么再去安装GCC环境, yum -y install gcc automake autoconf libtool make

参考链接:https://blog.csdn.net/ygl6150373/article/details/50984420

 (3)安装成功,开始启动前准备,修改redis.conf里 bind的IP,直接注释掉这一行,让外网可以访问,如果是3.2以后版本,还需要修改保护模式 protected-mode yes 改为no,注意修改完这个配置后,下次启动要指定 redis.conf,不然不起作用!

2.开始启动

如果你linux没什么问题可能就直接启动成功了,但有些时候会报3个警告,比如我就碰到了,2.8不会,4.0会,猜想可能是4.0对内存要求高了

第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

意思是:TCP  backlog设置值,511没有成功,因为 /proc/sys/net/core/somaxconn这个设置的是更小的128.

临时解决方法:(即下次启动还需要修改此值)

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

永久解决方法:(即以后启动还需要修改此值)

将其写入/etc/rc.local文件中。

当然上面这个解决办法是网上的,我试了,直接改somaxconn下次启动仍然这样,而写到rc.local我不知道怎么写,直接写也是没用的,所以我又找到另外一个方法是可以的

在/etc/sysctl.conf中添加如下

net.core.somaxconn = 2048,此值根据你的内存自己写定义,大于511即可

第二个警告: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!在内存不足的情况下,后台程序save可能失败。建议在文件 /etc/sysctl.conf 中将overcommit_memory修改为1。

这个警告的处理我忘记了这个是否有效,应该有效的

第三个警告:you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.

意思是:你使用的是透明大页,可能导致redis延迟和内存使用问题。执行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 修复该问题。

临时解决方法:

echo never > /sys/kernel/mm/transparent_hugepage/enabled。

永久解决方法:

将其写入/etc/rc.local文件中。

这个解决方案也是网上的,但是根本没用,至少我这里是没用的,所以我采取的是这个,修改etc/default/grub  里值,GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS0,115200 transparent_hugepage=never"

在此行后面加了 transparent_hugepage=never,并执行,参考连接:https://blog.csdn.net/msdnchina/article/details/72968215

亲测是有效的.

3.远程连接

终于顺利启动了, 启动顺序这样: cd /redis/redis-4.0.9/src ,然后执行 ./redis-server  ../redis.conf,记住,一定要指定conf文件,不然上面修改IP和保护模式都没用了.

不容易啊,现在开始在另外一个窗口里进入redis, cd /redis/redis-4.0.9/src,执行./redis-cli,进入redis,set个键取下看是否正常,然后开始进入远程连接;

我本地用的springboot,推荐大家使用,sprinboot自带有springboot-redis功能,会自动加载redis配置文件,但它使用的redistemplate感觉并不好用,所以此时我用的还是jedis

但一访问就报错,Caused by: java.net.SocketTimeoutException: connect timed out,然后我试着去关闭防火墙,如下:

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

systemctl stop firewalld.service #停止

firewall systemctl disable firewalld.service #禁止firewall开机启动

init 6 #重启虚拟机,然后再输入第一条命令查看防火墙状态

在centos7.2里这样操作防火墙是没问题的,然后并没什么用,还是time out,试了很多方法还是不行,本地可以Ping通,就是访问不了,此时突然想起我用的坑货云了,那里是访问白名单设置,

我早就设置了6379端口的白名单,却忘了绑定服务器,这里的DC2相当于阿里的ECS,结果一直报超时,无奈,改了这个之后,马上就可以了.

然后又报下面的错误 :

JedisConnectionException: java.net.SocketException: Software caused connection abort: socket write error"异常

或者:Unable to validate object

或者可能会有下面大段的错误:Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

此时说明redis.conf里设置没起作用,说明你启动时忘了指定conf,于是按正确方法启动  ./redis.server ../redis.conf,终于可以ping 通了

总结下:在安装完redis后,修改bindIP,和保护模式,并修改服务器防火墙的端口访问,在服务器上能访问redis的情况下,如果远程不能访问时,请检查下是否使用了云服务器及云服务器的IP及端口限制是否设置正常.

另外,还有其它设置,如是否使用密码,超时等待时间,持久化策略等下次再更.

linux上安装redis的踩坑过程的更多相关文章

  1. linux上安装redis的踩坑过程2

    昨天在linux上安装redis后马上发现了其它问题,服务器很卡,cpu使用率上升,top命令查看下,原来有恶意程序在挖矿,此程序入侵了很多redis服务器,马上用kill杀掉它 然后开始一些安全策略 ...

  2. Linux上安装Redis教程

    Redis的安装步骤: 步骤1.安装redis必须已经安装了gcc,如果没安装gcc 就使用命令 yum install -y gcc步骤2.下载redis包 下载地址:http://download ...

  3. linux 上安装 redis

    一.安装gcc Redis是c语言开发的. 安装 redis 需要 c 语言的编译环境.如果没有 gcc 需要在线安装. yum install gcc-c++ 二.下载 redis 链接:https ...

  4. Linux上安装Redis

    很多编程的小朋友一提到Linux脑袋就大了,我也一样,我是一个大专的学生,没有学过Linux,感觉自己欠缺很多,也知道了人和人之间的差距,当你真正的走上社会,才知道社会是什么,才知道没有学历找工作有多 ...

  5. linux上安装redis并使用

    1.下载:curl -O http://download.redis.io/releases/redis-4.0.6.tar.gz 2.在/usr/local/redis上解压:tar -zxvf r ...

  6. 安装GourdScanV2的踩坑过程

    环境:ubuntu 16.04.1 1.安装dcoker sudo apt-get install docker.io 坑:sudo apt-get install docker 2.下载关于dock ...

  7. 如何在Linux上安装Redis(内附详细教程)

    前言 hello,好久不见,又断更了一段时间.同事大部分离职了,但是活还是一样,所以只能硬着头皮顶上.现在总算歇会了,决定开启Redis源码系列,希望不要啪啪啪打脸. ​ 什么是redis? Redi ...

  8. linux 上安装redis

    下载地址:http://redis.io/download,下载最新文档版本. 本教程使用的最新文档版本为 2.8.17,下载并安装: $ wget http://download.redis.io/ ...

  9. 在linux上安装redis

    下载Redis安装包 wget  http://download.redis.io/releases/redis-3.2.9.tar.gz 解压Redis安装包 tar -zxvf redis-3.2 ...

随机推荐

  1. linux命令指usermod(管理用户以及权限的命令)

    usermod命令:用来修改用户帐号的各项设定. 示例:usermod -a -G usergroupnewuser 或者usermod -aGusergroup newuser 语法:usermod ...

  2. Android初级教程理论知识(第一章快速入门)

    一.综合介绍. Android项目的目录结构 Activity:应用被打开时显示的界面 src:项目代码 R.java:项目中所有资源文件的资源id Android.jar:Android的jar包, ...

  3. 1022. Digital Library (30) -map -字符串处理

    题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...

  4. HTML5哪点事

    HTML5哪点事 [引子] 微信圈里,很多朋友时常讲起HTML5,是未来很重要的一项技术,小老虎则更关注HTML5具体包含哪些技术内容. [技术内容] 1.说到底就是传统:html + css + j ...

  5. 一个App与另一个App之间的交互,添加了自己的一些理解

    URL Scheme 是什么? iOS有个特性就是应用将其自身"绑定"到一个自定义 URL scheme 上,该 scheme用于从浏览器或其他应用中启动本应用.常见的分享到第三方 ...

  6. how tomcat works读书笔记 七 日志记录器

    大家可以松一口气了,这个组件比较简单,这一节和前面几节想比,也简单的多. Logger接口 Tomcat中的日志记录器都必须实现org.apache.catalina.Logger接口. packag ...

  7. ibatis中多表联接查询

     目前,我在做项目的时候,用到了spring + struts2 +ibatis 框架.平时用到的都是一张简单的表,来进行数据的增.删.改.查.而现在突然需要用到其它的一张表,或多张表进行联接查询 ...

  8. Altium Designer设计PCB板之“精神”

    通过一小段时间的练习,感觉先领悟设计PCB板的“精神”更加重要.在这里,我指的“精神”是指PCB板中涉及的元器件原理图及其封装设计.当然,设计PCB板还有其他方面重要的精神需要掌握.本文所提到的“精神 ...

  9. SQL Queries and Multi-Org Architecture in Release 12

    In this Document   Abstract   History   Details   Previous Releases   Release 12   Multi-Org Session ...

  10. Android特效专辑(四)——APP主页框架TabHost绑定ViewPager的替换者TabLayout

    Android特效专辑(四)--APP主页框架TabHost绑定ViewPager的替换者TabLayout 现在很多app都在追求简单明了,功能又要强大,不过我还是喜欢之前的app风格,就是TabH ...