zookeeper技术学习,更多知识请访问https://www.itkc8.com
现象:
1.QuorumPeerMain进程可能正常启动。但使用zkServer.sh status查看状态时报:[richard@richard3 zookeeper-3.4.6]$ bin/zkServer.sh status
JMX enabled by default
Using config: /home/richard/zookeeper-3.4.6/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
2.查看日志发现报错:
2016-01-16 19:04:51,488 [myid:0] - WARN [WorkerSender[myid=0]:QuorumCnxManager@
382] - Cannot open channel to 2 at election address /192.168.1.112:3888
Java.NET.ConnectException: 拒绝连接
at java.net.PlainSocketImpl.socketConnect(Native Method) ............
我试过几种方案:
1.防火墙未关闭,因为我使用的是centos7,防火墙关闭方法与以前不一样了,从网上查了一下,使用chkconfig iptables off关闭。问题未解决。
2.java版本太高?因为我用的是java8,所以怀疑java版本问题。降到java7。同样未能解决问题。
3.网上查到
1)打开zkServer.sh 找到
status)
STAT=`echo stat | nc localhost $(grep clientPort "$ZOOCFG" | sed -e 's/.*=//') 2> /dev/null| grep Mode`
在nc与localhost之间加上 -q 1 (是数字1而不是字母l)
如果已存在则去掉
我用的是zookeeper-3.4.6,zkServer.sh脚本文件里根本没有这一行,我的zkServer.sh中是下面这样:
STAT=`"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
-cp "$CLASSPATH" $JVMFLAGS org.apache.zookeeper.client.FourLetterWordMain \
$clientPortAddress $clientPort srvr 2> /dev/null \
| grep Mode`
if [ "x$STAT" = "x" ]
then
echo "Error contacting service. It is probably not running."
exit 1
else
echo $STAT
exit 0
fi
所以此法无效。
3.虚拟机的问题?我就装了windows 和Linux双系统。
在纯linux下装了虚拟机也不管用。
。。。。。。。
今天经过一天的奋斗结果发现原因竟是最简单的问题:防火墙的问题。其实应该把iptables和firewall都关掉才行,而我只把iptables关闭了,而firewall却逍遥法外,应该用下面方法把firewall也关掉。
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
CentOS7默认的防火墙不是iptables,而是firewalle.
安装iptable iptable-service
[plain] view plain copy
- #先检查是否安装了iptables
- service iptables status
- #安装iptables
- yum install -y iptables
- #升级iptables
- yum update iptables
- #安装iptables-services
- yum install iptables-services
禁用/停止自带的firewalld服务
[plain] view plain copy
- #停止firewalld服务
- systemctl stop firewalld
- #禁用firewalld服务
- systemctl mask firewalld
设置现有规则
[plain] view plain copy
- #查看iptables现有规则
- iptables -L -n
- #先允许所有,不然有可能会杯具
- iptables -P INPUT ACCEPT
- #清空所有默认规则
- iptables -F
- #清空所有自定义规则
- iptables -X
- #所有计数器归0
- iptables -Z
- #允许来自于lo接口的数据包(本地访问)
- iptables -A INPUT -i lo -j ACCEPT
- #开放22端口
- iptables -A INPUT -p tcp --dport 22 -j ACCEPT
- #开放21端口(FTP)
- iptables -A INPUT -p tcp --dport 21 -j ACCEPT
- #开放80端口(HTTP)
- iptables -A INPUT -p tcp --dport 80 -j ACCEPT
- #开放443端口(HTTPS)
- iptables -A INPUT -p tcp --dport 443 -j ACCEPT
- #允许ping
- iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
- #允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
- iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
- #其他入站一律丢弃
- iptables -P INPUT DROP
- #所有出站一律绿灯
- iptables -P OUTPUT ACCEPT
- #所有转发一律丢弃
- iptables -P FORWARD DROP
其他规则设定
[plain] view plain copy
- #如果要添加内网ip信任(接受其所有TCP请求)
- iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
- #过滤所有非以上规则的请求
- iptables -P INPUT DROP
- #要封停一个IP,使用下面这条命令:
- iptables -I INPUT -s ***.***.***.*** -j DROP
- #要解封一个IP,使用下面这条命令:
- iptables -D INPUT -s ***.***.***.*** -j DROP
保存规则设定
[plain] view plain copy
- #保存上述规则
- service iptables save
开启iptables服务
[plain] view plain copy
- #注册iptables服务
- #相当于以前的chkconfig iptables on
- systemctl enable iptables.service
- #开启服务
- systemctl start iptables.service
- #查看状态
- systemctl status iptables.service
解决vsftpd在iptables开启后,无法使用被动模式的问题
1.首先在/etc/sysconfig/iptables-config中修改或者添加以下内容
[html] view plain copy
- #添加以下内容,注意顺序不能调换
- IPTABLES_MODULES="ip_conntrack_ftp"
- IPTABLES_MODULES="ip_nat_ftp"
2.重新设置iptables设置
[plain] view plain copy
- iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
以下为完整设置脚本
[plain] view plain copy
- #!/bin/sh
- iptables -P INPUT ACCEPT
- iptables -F
- iptables -X
- iptables -Z
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A INPUT -p tcp --dport 22 -j ACCEPT
- iptables -A INPUT -p tcp --dport 21 -j ACCEPT
- iptables -A INPUT -p tcp --dport 80 -j ACCEPT
- iptables -A INPUT -p tcp --dport 443 -j ACCEPT
- iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
- iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
- iptables -P INPUT DROP
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD DROP
- service iptables save
- systemctl restart iptables.service
zookeeper技术学习,更多知识请访问https://www.itkc8.com