我运行的是 centOs 6.3,我在本地机器上通过 remi 存储库安装了 redis-server。我可以运行 redis cli。
但是当我尝试通过 php 脚本连接时,我得到了
fsockopen(): unable to connect to 127.0.0.1:6379
我尝试在禁用 IPtables 后运行它,但那对我来说仍然不起作用。
这是运行时的 iptables 规则
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:6379
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
我也尝试运行以下命令,但没有成功。
setsebool -P httpd_can_network_connect 1
编辑: 网络状态监测
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:54980 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:33000 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33103 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33065 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33070 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33099 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33069 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33058 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33150 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33052 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33140 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:51634 69.59.197.29:80 ESTABLISHED
tcp 0 0 127.0.0.1:33137 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:44836 65.55.58.184:80 ESTABLISHED
tcp 0 0 127.0.0.1:33036 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33126 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33138 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33032 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33039 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:58613 74.125.135.125:5222 ESTABLISHED
tcp 0 0 127.0.0.1:33053 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33004 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33134 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33030 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33094 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33056 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33050 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33125 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33098 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33028 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33127 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33047 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33027 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33034 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33025 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33082 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33080 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33096 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33142 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33002 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33003 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33064 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33059 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33107 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33139 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33133 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33132 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33090 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33013 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33076 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33007 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33100 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33144 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33149 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33092 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33119 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:56835 74.125.236.151:80 ESTABLISHED
tcp 0 0 127.0.0.1:33116 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33008 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33106 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33046 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33062 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33086 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33001 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:39717 69.192.223.144:80 ESTABLISHED
tcp 0 0 127.0.0.1:33018 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33029 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33010 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33026 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33087 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33120 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33124 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:54740 69.59.197.29:80 ESTABLISHED
tcp 0 0 127.0.0.1:33019 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33068 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33024 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33084 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:49277 74.125.236.134:443 ESTABLISHED
tcp 0 0 127.0.0.1:33042 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33049 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33057 127.0.0.1:80 ESTABLISHED
tcp 1 0 192.168.11.33:51642 69.59.197.29:80 CLOSE_WAIT
tcp 0 0 127.0.0.1:33063 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33041 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33071 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33108 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33067 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:55675 173.194.69.93:443 ESTABLISHED
tcp 0 0 127.0.0.1:33009 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33097 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33102 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33105 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33136 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:47970 74.125.236.131:80 ESTABLISHED
tcp 0 0 127.0.0.1:33122 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33051 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33115 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33072 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:60243 108.161.188.213:80 TIME_WAIT
tcp 0 0 127.0.0.1:33113 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33040 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33130 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33048 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:47559 74.125.236.134:80 ESTABLISHED
tcp 0 0 127.0.0.1:33131 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33020 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33095 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:51535 74.125.236.102:80 ESTABLISHED
tcp 0 0 127.0.0.1:33005 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:37953 192.168.11.11:5222 ESTABLISHED
tcp 0 0 127.0.0.1:33022 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33077 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33101 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:49890 72.246.188.65:80 TIME_WAIT
tcp 0 0 127.0.0.1:33109 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33055 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33093 127.0.0.1:80 ESTABLISHED
tcp 609 0 192.168.11.33:51753 69.59.197.29:443 ESTABLISHED
tcp 0 0 127.0.0.1:33074 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:48157 108.161.189.75:80 TIME_WAIT
tcp 0 0 127.0.0.1:33088 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33079 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33128 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:50195 74.125.236.128:80 ESTABLISHED
tcp 0 0 192.168.11.33:54815 115.112.1.4:80 ESTABLISHED
tcp 0 0 127.0.0.1:33035 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:44316 74.125.236.143:443 ESTABLISHED
tcp 0 0 127.0.0.1:33121 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33075 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33104 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33043 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33143 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:55772 69.59.197.29:80 ESTABLISHED
tcp 0 0 127.0.0.1:33014 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:32999 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33147 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:46212 74.125.236.142:443 ESTABLISHED
tcp 0 0 127.0.0.1:33111 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:59920 192.168.11.1:143 ESTABLISHED
tcp 0 0 127.0.0.1:33135 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33017 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:39378 69.59.197.21:80 ESTABLISHED
tcp 0 0 192.168.11.33:56836 74.125.236.151:80 ESTABLISHED
tcp 0 0 127.0.0.1:33148 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33038 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33006 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33117 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33031 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33060 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:47560 74.125.236.134:80 TIME_WAIT
tcp 0 0 127.0.0.1:33129 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33145 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33023 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33081 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33114 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33118 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33123 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:49531 74.125.31.95:80 TIME_WAIT
tcp 0 0 127.0.0.1:33091 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33044 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33083 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33112 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33012 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33061 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:49893 72.246.188.65:80 TIME_WAIT
tcp 0 0 127.0.0.1:33073 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33054 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33016 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33089 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:60242 108.161.188.213:80 TIME_WAIT
tcp 0 0 127.0.0.1:33033 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33146 127.0.0.1:80 ESTABLISHED
tcp 0 0 127.0.0.1:33085 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:51927 69.59.197.29:80 ESTABLISHED
tcp 0 0 192.168.11.33:22 192.168.11.37:43447 ESTABLISHED
tcp 0 0 127.0.0.1:33037 127.0.0.1:80 ESTABLISHED
tcp 0 0 192.168.11.33:41758 74.125.236.159:80 ESTABLISHED
答案1
问题解决了@cjc 说 redis 没有监听 127.0.0.1 ip。在我的 predis 配置中,我提供了 0.0.0.0 作为 ip,它就开始工作了。