场景:由于主服务器在处理并发请求上用了Memcache消息队列的方法,优先将用户请求存到memcache的队列中,然后通过定时脚本运行接口取队列信息存储于数据库,而再给主服务器做负载均衡的时候,负载服务器打算访问主服务器的Memcache存储信息于队列中,然而负载服务器连接不上主服务器的Memcache。
测试负载服务器能否连接主服务器的memcache(默认端口11211)
telnet x.x.x.x 11211
如果连接成功
如果访问被拒
处理访问被拒的情况
1.配置iptables,打开memcached的端口,允许公网访问[root@iZbp ~]# iptables -A INPUT -p tcp –dport 11211 -j ACCEPT
[root@iZbp ~]# iptables -A INPUT -p udp –dport 11211 -j ACCEPT
[root@iZbp conf]# service iptables save
[root@iZbp conf]# service iptables restart2.查看iptables配置文件,确认规则已添加
[root@iZbp conf]# vim /etc/sysconfig/iptables
3.修改memcached的配置文件,去掉15行OPTIONS中的-l 127.0.0.1,为空
/****************修改前**********************/
[root@iZbp include]# vim /etc/init.d/memcached
11 PORT=11211
12 USER=memcached
13 MAXCONN=1024
14 CACHESIZE=984
15 OPTIONS=”-l 127.0.0.1”
16 DAEMON=/usr/local/memcached/bin/memcached
/******************修改后********************/
11 PORT=11211
12 USER=memcached
13 MAXCONN=1024
14 CACHESIZE=984
15 OPTIONS=””
16 DAEMON=/usr/local/memcached/bin/memcached
/***************************************************/
tips:如果找不到配置文件,可以使用find命令查找:
find / -name memcached.conf 或者 find / -name memcached4.重启服务
[root@iZbp include]# service memcached restart
Stopping memcached: [ OK ]
Starting memcached: [ OK ]5.尝试连接
telnet ip 11211