Linux系统安装Redis遇到的问题及解决(2)

[root@rac1 ~]#  cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-3.10.0-327.el7.x86_64 root=UUID=0dd676f4-cb3b-469d-b5e6-73defbc87f4e ro rhgb quiet transparent_hugepage=never  ---->>>有此行。
[root@rac1 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]  ---->>>[never]表示成功禁用THP。
[root@rac1 ~]# cd /sys/kernel/mm/
[root@rac1 mm]# ls -lrt
total 0
drwxr-xr-x 4 root root 0 Jun  9 19:32 hugepages
drwxr-xr-x 2 root root 0 Jun  9 19:32 ksm
drwxr-xr-x 3 root root 0 Jun  9 19:35 transparent_hugepage
[root@rac1 mm]# cd transparent_hugepage/
[root@rac1 transparent_hugepage]# ls -lrt
total 0
-rw-r--r-- 1 root root 4096 Jun  9 19:35 enabled
-rw-r--r-- 1 root root 4096 Jun  9 19:35 use_zero_page
drwxr-xr-x 2 root root    0 Jun  9 19:35 khugepaged
-rw-r--r-- 1 root root 4096 Jun  9 19:35 defrag
[root@rac1 transparent_hugepage]# cat enabled
always madvise [never]
[root@rac1 transparent_hugepage]# pwd
/sys/kernel/mm/transparent_hugepage
[root@rac1 transparent_hugepage]# grep AnonHugePages /proc/meminfo
AnonHugePages:        0 kB ---------->>>返回值若是零,代表成功禁用THP。
[root@rac1 transparent_hugepage]#

亲测是有效的。

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通,就是访问不了,此时突然想起我用的坑货云了,那里是访问白名单设置,

Linux系统安装Redis遇到的问题及解决

我早就设置了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 通了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/526025d0c972a40ef17c3af51f4af0e3.html