Redis安装+主从配置 过程中 的几个小 Tips

来源:互联网 发布:网络推广月度工作计划 编辑:程序博客网 时间:2024/05/24 07:23

首先Redis的安装前,先执行下面的命令:

# echo "vm.overcommit_memory=1" >>/etc/sysctl.conf
# echo "vm.swappiness=1" >>/etc/sysctl.conf


redis 安装是否成功,测试方法:
# /opt/redis/bin/redis-cli ping 
PONG                            # 正常安装显示结果。

redis 日志报错:
问题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.

解决办法:
# echo 511 > /proc/sys/net/core/somaxconn


问题2:
 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.

解决办法: 
# echo never > /sys/kernel/mm/transparent_hugepage/enabled 
# vi /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled 


问题3:
# telnet 192.168.56.10 6379
Trying 192.168.56.10...
Connected to 192.168.56.10.
Escape character is '^]'.
-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.
Connection closed by foreign host.

解决办法:
   1. # /opt/redis/bin/redis-cli
   127.0.0.1:6379> config set protected-mode no

   2. vi /data/redis/redis6379/6379.conf
   protected-mode no

   3. 启动服务 加选项。
   # /opt/redis/sbin/redis-server /data/redis/redis6379/6379.conf --protected-mode no

   4. 设置 bind 地址或者  权限认证密码
      a.  bind 地址 (主服务的配置文件设置,从不需要设置)
      bind 127.0.0.1 192.168.56.10

      b. 权限认证密码
      主配置文件:
        # vi /data/redis/redis6379/6379.conf
          port 6379
          requirepass redis

      从配置文件:
        # vi /data/redis/redis6379/6379.conf
          port 6379
          slaveof 192.168.56.10 6379
          masterauth redis
          requirepass redis  # 如果还有从服务器,需要否则不需要。

          主服务器上执行:
          # /opt/redis/bin/redis-cli -h 192.168.56.10 -a redis set city beijing

          从服务器上执行:
          # /opt/redis/bin/redis-cli -h 192.168.56.20 get city

0 0