CentOS下配置redis容许远程链接

© 版权声明:本文为博主原创文章,转载请注明出处html

1. 目的redis

  由于想要学习redis,所以在虚拟机中安装了redis,为了实如今物理机能够访问redis,弄了很久;所以记录下来,以避免忘记。安全

2. 环境tcp

  虚拟机:CentOS Linux release 7.4.1708 (Core)post

  redis:4.0.8学习

  防火墙:iptablesui

3. 配置spa

  3.1 配置redis.conf.net

    将 bind 127.0.0.1 使用#注释掉,改成# bind 127.0.0.1(bind配置的是容许链接的ip,默认只容许本机链接;若远程链接需注释掉,或改成0.0.0.0)3d

    将 protected-mode yes 改成 protected-mode no(3.2以后加入的新特性,目的是禁止公网访问redis cache,加强redis的安全性)

    将 requirepass foobared 注释去掉,foobared为密码,也可修改成别的值(可选,建议设置)

  3.2 设置iptables规则,容许外部访问6379端口

    iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT

    临时生效,重启后失效。若想永久生效,请参考另外一篇文章:http://www.cnblogs.com/jinjiyese153/p/8600855.html

  3.3 启动redis,并指定配置文件

    ./redis-server ../redis.conf

4. 检查

  本机安装RedisDesktopManager进行redis远程链接。

 

CentOS配置iptables规则并使其永久生效

 

© 版权声明:本文为博主原创文章,转载请注明出处

 1. 目的

  最近为了使用redis,配置远程链接的使用须要使用iptable是设置容许外部访问6379端口,可是设置完成后重启老是失效。所以百度了一下如何设置永久生效,并记录。

 2. 设置

  2.1 添加iptables规则

iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT

  2.2 保存

service iptables save

  执行这个命令的时候有时候可能会报错:The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

  这是由于没有安装iptables服务,直接使用yum安装iptables服务便可.

yum install iptables-services

  安装完成后,从新执行 service iptables save 命令便可保存成功。

  2.3 配置iptables开机自启

  保存后重启依然没有生效,后百度得知,须要设置iptables开机自启才可以使配置生效。

  执行以下命令(老版本命令为:service iptables on),设置iptables开机自启

systemctl enable iptables.service

 3. 注意

  需关闭firewalld防火墙

  systemctl stop firewalld.service

  systemctl disable firewalld.service

参考:

http://blog.csdn.net/donglynn/article/details/73530542

https://www.v2ex.com/t/114397

相关文章
相关标签/搜索