Linux Redis啓用遠程鏈接


Linux上Redis要想被遠程程序經過6379接口telnet通。須要知足一下幾個條件html

1.     redis-server  ../conf/redis.conf   運行了。 而且telnet localhost 6379是通的。mysql

2.    conf/redis.conf  裏面的web

bind 127.0.0.1 ::1 這一行註釋掉。 redis

這裏的bind指的是隻有指定的網段才能遠程訪問這個redis。  註釋掉後,就沒有這個限制了。sql

或者bind 本身所在的網段vim


3.    conf/redis.conf裏面centos

protected-mode 要設置成no      (默認是設置成yes的, 防止了遠程訪問,在redis3.2.3版本後)
服務器


4. 看服務器用的是firewall-cmd  仍是iptablesssh

若是是iptables,就vim /etc/sysconfig/iptablestcp

增長一行

-A INPUT -p tcp -m state --state NeW -m tcp --dport 6379 -j ACCEPT

結果以下

# Generated by iptables-save v1.4.21 on Sat May 13 16:49:26 2017
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [180:33265]
:syn-flood - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 20000:30000 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NeW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NeW -m tcp --dport 6379 -j ACCEPT

-A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT
-A INPUT -p icmp -m limit --limit 1/sec --limit-burst 10 -j ACCEPT
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN
-A syn-flood -j REJECT --reject-with icmp-port-unreachable
COMMIT
# Completed on Sat May 13 16:49:26 2017

而後重啓iptables服務,在centos7裏操做以下,而且查看iptables最終的設置信息

[root@VM_196_224_centos redis-3.2.9]# systemctl restart iptables
[root@VM_196_224_centos redis-3.2.9]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:webcache
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ftp
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpts:dnp:ndmps
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:mysql
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:6379
ACCEPT     icmp --  anywhere             anywhere             limit: avg 100/sec burst 100
ACCEPT     icmp --  anywhere             anywhere             limit: avg 1/sec burst 10
syn-flood  tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,ACK/SYN
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited
相關文章
相關標籤/搜索