zookeeper启动后查看状态报Error contacting service. It is probably not running.错误

在集群上安装并启动zookeeper后,查看zookeeper状态,出现以下情况:

[hadoop@oceanbase06 zookeeper-3.4.12]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.12/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

但实际上zookeeper进程是启动了并且正常运行的:

[hadoop@oceanbase06 hadoop]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.12/bin/../conf/zoo.cfg
Starting zookeeper ... already running as process 16783.

使用jps命令查看已启动进程,报错如下:

[hadoop@oceanbase06 zookeeper-3.4.12]$ jps
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

从报错可以看出是Java虚拟机(JVM)分配的内存大于系统可用内存数,所以没有足够的空间分配给JVM来创建Object。
解决方法:可以看看机器的系统内存目前还剩下多少,保证足够启动Java时设定的内存。

在/etc/profile中设置JVM参数并生效

export _JAVA_OPTIONS="-Xmx10240M"

重新启动zookeeper,查看状态,不再报错。

[hadoop@oceanbase06 zookeeper-3.4.12]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower
[hadoop@oceanbase06 zookeeper-3.4.12]$ 

[hadoop@oceanbase06 zookeeper-3.4.12]$ jps
Picked up _JAVA_OPTIONS: -Xmx10240M
17528 Jps
17326 QuorumPeerMain

如果JVM的-Xmx设置太大,可能会报如下错误:

[hadoop@oceanbase06 ~]$ java -version
Picked up _JAVA_OPTIONS: -Xmx10240M
Error occurred during initialization of VM
Could not reserve enough space for the card marking array

你可能感兴趣的:(分布式)