CentOS7.2 安装zookeeper3.4.9

Zookeeper-3.4.9

下载Zookeeper-3.4.9

在/usr/local下创建hadoop文件夹

将下载的文件迁移到该文件夹下,并解压

 tar -zxvf zookeeper-3.4.9.tar.gz

进入conf配置文件夹

 cd zookeeper-3.4.9/conf/

复制zoo_sample.cfg文件并命名为zoo.cfg

 cp zoo_sample.cfg zoo.cfg

打开zoo.cfg,修改内容

#dataDir=/tmp/zookeeper
dataDir=/usr/local/hadoop/zookeeper-3.4.9/data  
dataLogDir=/usr/local/hadoop/zookeeper-3.4.9/logs  

修改后的完整内容:

# 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.

#dataDir=/tmp/zookeeper
dataDir=/usr/local/hadoop/zookeeper-3.4.9/data # 数据持久化路径
dataLogDir=/usr/local/hadoop/zookeeper-3.4.9/logs # 日志保存路径

# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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
View Code

修改zookeeper的环境变量,打开/etc/profile文件,并在末尾添加以下内容:

# idea - zookeeper-3.4.9 config start  
export ZOOKEEPER_HOME=/usr/local/hadoop/zookeeper-3.4.9/
export PATH=$ZOOKEEPER_HOME/bin:$PATH
export PATH
# idea - zookeeper-3.4.9 config start

添加后的完整内容:

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
fi

HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then 
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge

export JAVA_HOME=/usr/local/jdk/jdk1.8.0_121
export JRE_HOME=/usr/local/jdk/jdk1.8.0_121/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

# idea - zookeeper-3.4.9 config start  
export ZOOKEEPER_HOME=/usr/local/hadoop/zookeeper-3.4.9/
export PATH=$ZOOKEEPER_HOME/bin:$PATH
export PATH
# idea - zookeeper-3.4.9 config start  
View Code

使环境变量生效

 source /etc/profile

启动Zookeeper服务:

[root@localhost ~]#  zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

查询Zookeeper状态:

[root@localhost ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: standalone

停止Zookeeper服务:

[root@localhost ~]# zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper-3.4.9/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

重启Zookeeper服务:

[root@localhost ~]# zkServer.sh restart
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper-3.4.9/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper-3.4.9/bin/../conf/zoo.cfg
Stopping zookeeper ... no zookeeper to stop (could not find file /usr/local/hadoop/zookeeper-3.4.9/data # 数据持久化路径/zookeeper_server.pid)
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

设置为开机自启动:(都是网上找的,没有操作!)

方法1:

/etc/rc.d/rc.local

添加:

su -root -c '//usr/local/services/zookeeper/zookeeper-3.4.9/bin/zkServer.sh start'

方法2:

在/etc/rc.d/init.d文件夹下创建zookeeper文件

赋予操作权限

[root@localhost init.d]# touch zookeeper
[root@localhost init.d]# chmod +x zookeeper
[root@localhost init.d]# ls
functions  netconsole  network  README  redis_6379  zookeeper
[root@localhost init.d]# ls -a
.  ..  functions  netconsole  network  README  redis_6379  zookeeper
[root@localhost init.d]# ls -all
总用量 40
drwxr-xr-x.  2 root root    99 4月  10 21:24 .
drwxr-xr-x. 10 root root  4096 4月   9 23:08 ..
-rw-r--r--.  1 root root 15131 9月  12 2016 functions
-rwxr-xr-x.  1 root root  2989 9月  12 2016 netconsole
-rwxr-xr-x.  1 root root  6643 9月  12 2016 network
-rw-r--r--.  1 root root  1160 3月   3 11:23 README
-rwxr-xr-x.  1 root root  1702 4月   8 22:52 redis_6379
-rwxr-xr-x.  1 root root     0 4月  10 21:24 zookeeper
[root@localhost init.d]# chkconfig -add zookeeper
-add: 未知的选项
[root@localhost init.d]# chkconfig --add zookeeper

 zookeeper文件内容:

#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
case $1 in
          start) su root /usr/local/hadoop/zookeeper-3.4.9/bin/zkServer.sh start;;
          stop) su root /usr/local/hadoop/zookeeper-3.4.9/bin/zkServer.sh stop;;
          status) su root /usr/local/hadoop/zookeeper-3.4.9/bin/zkServer.sh status;;
          restart) su root /usr/local/hadoop/zookeeper-3.4.9/bin/zkServer.sh restart;;
          *)  echo "require start|stop|status|restart"  ;;
esac

将zookeeper添加到开机启动里面

chkconfig --add zookeeper

开机启动:

chkconfig zookeeper on

 ======

Centos7.2安装zookeeper3.5.2-alpha

为了测试Curator3.2.1,重新安装zookeeper-3.5.2-alpha.tar.gz

操作与上面一样,只是换了文件夹名称为zookeeper

[root@localhost conf]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.
[root@localhost conf]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START

解决:

查看logs里面的日志:

[root@localhost zookeeper-3.5.2]# cd logs
[root@localhost logs]# ls
version-2  zookeeper-hongdada-server-localhost.localdomain.out
[root@localhost logs]# vi version-2
[root@localhost logs]# vi zookeeper-hongdada-server-localhost.localdomain.out

logs:

2017-12-18 22:50:31,006 [myid:] - ERROR [main:ZooKeeperServerMain@76] - Unable to start AdminServer, exiting abnormally
org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL /commands
        at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:100)
        at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:127)
        at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:103)
        at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:61)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:125)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:79)
Caused by: java.net.BindException: 地址已在使用
        at sun.nio.ch.Net.bind0(Native Method)

很明显是由于端口占用。我服务器中的tomcat占用了8080端口,而zookeeper最近的版本中有个内嵌的管理控制台是通过jetty启动,也会占用8080 端口。

通过查看zookeeper的官方文档,发现有3种解决途径:

(1).删除jetty。

(2)修改端口。

修改方法的方法有两种,一种是在启动脚本中增加 -Dzookeeper.admin.serverPort=你的端口号.一种是在zoo.cfg中增加admin.serverPort=没有被占用的端口号

(3)停用这个服务,在启动脚本中增加"-Dzookeeper.admin.enableServer=false"

在zoo.cfg中添加配置admin.serverPort=2182

修改后的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.

#dataDir=/tmp/zookeeper
dataDir=/usr/local/hadoop/zookeeper-3.4.9/data
dataLogDir=/usr/local/hadoop/zookeeper-3.4.9/logs

# the port at which the clients will connect
clientPort=2181
admin.serverPort=2182
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
"zoo.cfg" 33L, 1045C
View Code

启动:

[root@localhost hadoop]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... already running as process 6664.
[root@localhost hadoop]# zkServer
bash: zkServer: 未找到命令...
[root@localhost hadoop]# zkServer.sh --version
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper/bin/../conf/zoo.cfg
Usage: /usr/local/hadoop/zookeeper//bin/zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|restart|status|print-cmd}
[root@localhost hadoop]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/hadoop/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone

 

http://blog.csdn.net/cg_perfect/article/details/53053060

http://www.procedurego.com/article/58182.html

http://www.cnblogs.com/hapday/p/5617730.html

http://m.blog.csdn.net/article/details?id=52313834

http://jingyan.baidu.com/article/fec7a1e5136c571190b4e720.html

http://blog.csdn.net/xiaoyu411502/article/details/51441890

https://www.cnblogs.com/feiye512/p/5923683.html

posted @ 2017-04-09 22:15  hongdada  阅读(676)  评论(0编辑  收藏  举报