zookeeper单节点安装以及一些问题的解决办法

zookeeper单节点安装以及一些问题的解决办法#

下载:http://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/

解压后,把conf中的zoo_sample.cfg复制一份成为zoo.cfg,修改以下里面的内容:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.

# 此处是zk所在路径,只需修改此处
dataDir=/home/hadoop/app/zookeeper-3.4.5-cdh5.7.0/data/zk
dataLogDir=/home/hadoop/app/zookeeper-3.4.5-cdh5.7.0/data/zk/log

# the port at which the clients will connect
# 默认端口号
clientPort=2181
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
#server.1=hadoop001:2888:3888
#server.2=hadoop002:2888:3888
#server.3=hadoop003:2888:3888

启动zookeeper

[hadoop@hadoop001 bin]$ sudo ./zkServer.sh start
JMX enabled by default
Using config: /home/hadoop/app/zookeeper-3.4.5-cdh5.7.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

如果出现: Starting zookeeper ... already running as process xxx,删除zookeeper-server.pid文件,再重新启动

查看状态

[hadoop@hadoop001 bin]$ sudo ./zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/app/zookeeper-3.4.5-cdh5.7.0/bin/../conf/zoo.cfg
Mode: standalone

如果出现:Error contacting service. It is probably not running.
有以下解决办法:
1、zoo.cfg配置文件中指定目录却没有创建,创建相应目录即可
2、使用service iptables stop 关闭防火墙;使用service iptables status确认
3、打开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),如果已存在则去掉
4、2181端口被占用
但是我遇到的情况都不是上面提到的,后面查到有个zookeeper.out的文件,里面会有一些log信息。

查看zookeeper.out

cat zookeeper.out
2018-11-13 00:26:11,837 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configuration from: /home/hadoop/app/zookeeper-3.4.5-cdh5.7.0/bin/../conf/zoo.cfg
2018-11-13 00:26:11,843 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2018-11-13 00:26:11,843 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2018-11-13 00:26:11,843 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2018-11-13 00:26:11,844 [myid:] - WARN  [main:QuorumPeerMain@118] - Either no config or no quorum defined in config, running  in standalone mode
2018-11-13 00:26:11,862 [myid:] - INFO  [main:QuorumPeerConfig@101] - Reading configuration from: /home/hadoop/app/zookeeper-3.4.5-cdh5.7.0/bin/../conf/zoo.cfg
2018-11-13 00:26:11,863 [myid:] - INFO  [main:ZooKeeperServerMain@100] - Starting server
2018-11-13 00:26:11,878 [myid:] - INFO  [main:Environment@100] - Server environment:zookeeper.version=3.4.5-cdh5.7.0--1, built on 03/23/2016 18:31 GMT
2018-11-13 00:26:11,878 [myid:] - INFO  [main:Environment@100] - Server environment:host.name=hadoop001
2018-11-13 00:26:11,878 [myid:] - INFO  [main:Environment@100] - Server environment:java.version=1.7.0_101
2018-11-13 00:26:11,879 [myid:] - INFO  [main:Environment@100] - Server environment:java.vendor=Oracle Corporation

列出了log中的一部分,可能会出下如下问题:
1、nohup: failed to run command/usr/java/jdk1.8.0_65//bin/java’: No such file or directory`
这里可以看到是系统的环境变量有问题
查看系统环境变量

 [work@xxx zookeeper-3.4.6]$ export
    declare -x CVS_RSH="ssh"
    declare -x G_BROKEN_FILENAMES="1"
    declare -x HISTCONTROL="ignoredups"
    declare -x HISTSIZE="1000"
    declare -x HISTTIMEFORMAT="%F %T work "
    declare -x HOME="/home/work"
    declare -x JAVA_HOME="/usr/java/jdk1.8.0_65/"

修改系统环境变量

[work@xxx zookeeper-3.4.6]$ export JAVA_HOME=/usr

2、WARN [main:QuorumPeerMain@105] - Either no config or no quorum defined in config, running in standalone mode
可能是在你的zoo.cfg配置文件中没有这个路径:dataLogDir=/home/hadoop/app/zookeeper-3.4.5-cdh5.7.0/data/zk/log,在配置文件中加上上面路径(注意按自己的log文件路径,如果没有可以新建一个并设置)
最后再次启动,在查看状态和zookeeper.out文件

安装后用cli来测试一下
sudo ./zkCli.sh
出现下面内容,就可以了(只截取了一部分)

Connecting to localhost:2181
2018-11-13 00:12:39,103 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.5-cdh5.7.0--1, built on 03/23/2016 18:31 GMT
2018-11-13 00:12:39,110 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=hadoop001
2018-11-13 00:12:39,110 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_101
2018-11-13 00:12:39,118 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-11-13 00:12:39,119 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64/jre
......
WATCHER::

WatchedEvent state:SyncConnected type:None path:null

你可能感兴趣的:(bigData)