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. Handler,MessageQueue Loop 和Message的原理解析

    先介绍和handler一起工作的几个组件 Handler的方法介绍 代码示例 package liu.peng.weather; import java.util.Timer; import java ...

  2. markdown语法(看这张图就够了)

    这是维基百科的一张图,基本就够用了 https://en.wikipedia.org/wiki/Markdown#Example

  3. HMM:隐马尔科夫模型-维特比算法

    http://blog.csdn.net/pipisorry/article/details/50731584 目标-解决HMM的基本问题之二:给定观察序列O=O1,O2,-OT以及模型λ,如何选择一 ...

  4. 重载重写重定义-易混淆概念-C++编译器处理方式

    1.函数重载 1)必须在同一个类中进行. 2)子类无法重载父类的函数,父类同名函数将被名称覆盖 3)重载是在编译期间根据参数类型和个数决定函数调用 2.函数重写 1)必须发生于父类与子类之间 2)并且 ...

  5. 08_Android中的SimpleAdapter的使用

     1 目的界面 2.编写Android清单文件 <?xml version="1.0" encoding="utf-8"?> <manif ...

  6. E-JSON数据传输标准

    简介 E-JSON的设计目标是使业务系统向浏览器端传递的JSON数据保持一致,容易被理解和处理,并兼顾传输的数据量.E-JSON依托于http协议(rfc2616)与JSON数据交换格式(rfc462 ...

  7. MySQL学习笔记_10_MySQL高级操作(下)

    MySQL高级操作(下) 五.MySQL预处理语句 1.设置预处理stmt,传递一个数据作为where的判断条件 prepare stmt from "select * from table ...

  8. Linux学习笔记 --iptables防火墙配置

    iptables防火墙配置 一.防火墙简介 1.功能: 1)通过源端口,源IP地址,源MAC地址,包中特定标记和目标端口,IP,MAC来确定数据包是否可以通过防火墙 2)分割内网和外网[附带的路由器的 ...

  9. 【一天一道LeetCode】#24. Swap Nodes in Pairs

    一天一道LeetCode系列 (一)题目 Given a linked list, swap every two adjacent nodes and return its head. For exa ...

  10. Java-Iterator总结

    纸上得来终觉浅,绝知此事要躬行  --陆游    问渠那得清如许,为有源头活水来  --朱熹 迭 代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构. ...