Linux搭建Zookeeper环境之单机模式和集群模式配置

Linux搭建Zookeeper环境
1.Zookeeper
Linux搭建Zookeeper环境之单机模式和集群模式配置
Linux搭建Zookeeper环境之单机模式和集群模式配置
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
All of these kinds of services are used in some form or another by distributed applications. 
Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. 
Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage.
Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.
 
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
  ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。
  ZooKeeper包含一个简单的原语集提供Java和C的接口。
  ZooKeeper代码版本中,提供了分布式独享锁、选举、队列的接口,代码在zookeeper-3.4.3\src\recipes。其中分布锁和队列有Java和C两个版本,选举只有Java版本。
主要作用是用来解决分布式应用中经常遇到的一些数据管理问题,如集群管理、统一命名管理、分布式配置管理、分布式消息队列、分布式锁、分布式通知协调
官方网站:https://zookeeper.apache.org/
2.Zookeeper 下载安装
【1】官网下载【http://zookeeper.apache.org/releases.html】zookeeper安装包:zookeeper-3.5.3-beta.tar.gz
Linux搭建Zookeeper环境之单机模式和集群模式配置
Linux搭建Zookeeper环境之单机模式和集群模式配置
Linux搭建Zookeeper环境之单机模式和集群模式配置
Linux搭建Zookeeper环境之单机模式和集群模式配置
【2】利用Xftp5工具把zookeeper安装包:zookeeper-3.5.3-beta.tar.gz上传到Linux服务器:/usr/local/zookeeper
Linux搭建Zookeeper环境之单机模式和集群模式配置
【3】利用XShell5工具登录到Linux服务器进入到:cd /usr/local/zookeeper
Connecting to 192.168.3.4:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
 
Last login: Wed Apr  4 10:29:33 2018 from 192.168.3.3
[root@marklin ~]# cd /usr/local/zookeeper
[root@marklin zookeeper]# ll
total 41632
-rw-r--r--. 1 root root 42630656 Apr  4 11:15 zookeeper-3.5.3-beta.tar.gz
[root@marklin zookeeper]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
【4】输入tar -xvf 解压:tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin zookeeper]# tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin zookeeper]# ll
total 41636
drwxr-xr-x. 10  502 games     4096 Apr  3  2017 zookeeper-3.5.3-beta
-rw-r--r--.  1 root root  42630656 Apr  4 11:15 zookeeper-3.5.3-beta.tar.gz
[root@marklin zookeeper]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
【5】配置zookeeper环境变量,输入:vim /etc/profile
#Setting ZOOKEEPER_HOEM PATH
export ZOOKEEPER_HOEM=/usr/local/zookeeper/zookeeper-3.5.3
export PATH=${PATH}:${ZOOKEEPER_HOEM}/bin
Linux搭建Zookeeper环境之单机模式和集群模式配置
【6】配置zookeeper输入:cd zookeeper-3.5.3/conf
[root@marklin zookeeper]# cd zookeeper-3.5.3/conf
[root@marklin conf]#
[root@marklin conf]# ll
total 12
-rw-r--r--. 1 502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1 502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
将conf目录中的zoo_sample.cfg文件复制为zoo.cfg,输入:cp zoo_sample.cfg zoo.cfg
[root@marklin conf]# cp zoo_sample.cfg zoo.cfg
[root@marklin conf]# ll
total 16
-rw-r--r--. 1  502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1  502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 root root   922 Apr  4 11:33 zoo.cfg
-rw-r--r--. 1  502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
【7】zookeeper配置部署服务这里拓展一下,可配置单机模式[standalone]和集群模式[zookeeper-cluster]:
单机模式:安装上述配置修改对应的data和logs目录即可
集群模式:集群模式主要有两种形式:
1)使用多台机器部署一个ZooKeeper服务:在每台机器上运行一个ZooKeeper Server进程,在生产环境中,一般使用使用多台机器部署一个ZooKeeper服务
2)使用一台机器部署多个ZooKeeper服务:在该台机器上运行多个ZooKeeper Server进程,在练习测试环境中,一般使用使用一台机器部署多个ZooKeeper服务
【8】单机模式配置部署调整:
  在/usr/local/zookeeper目录创建:mkdir zookeeper-standalone
Linux搭建Zookeeper环境之单机模式和集群模式配置
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
单机模式环境变量调整:vim /etc/profile 
#Setting ZOOKEEPER_HOEM PATH
export ZOOKEEPER_HOEM=/usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3
export PATH=${PATH}:${ZOOKEEPER_HOEM}/bin
Linux搭建Zookeeper环境之单机模式和集群模式配置
修改配置zookeepe:cd /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/conf
[root@marklin ~]# cd /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/conf
[root@marklin conf]# ll
total 12
-rw-r--r--. 1 502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1 502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
将conf目录中的zoo_sample.cfg文件复制为zoo.cfg,输入:cp zoo_sample.cfg zoo.cfg
[root@marklin conf]# cp zoo_sample.cfg zoo.cfg
[root@marklin conf]# ll
total 16
-rw-r--r--. 1  502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1  502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 root root   922 Apr  4 12:20 zoo.cfg
-rw-r--r--. 1  502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
单机模式修改配置文件zoo.cfg,输入:vim zoo.cfg
# The number of milliseconds of each tick
tickTime=2000 -- 心跳间隔时间,zookeeper中使用的基本时间单位,毫秒值。每隔2秒发送一个心跳
# The number of ticks that the initial
# synchronization phase can take
initLimit=10 -- leader与客户端连接超时时间。表示10个心跳间隔
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5 -- Leader与Follower之间的超时时间,表示2个心跳间隔
# 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/zookeeper/repository/zookeeper-standalone/data -- 数据目录
dataLogDir=/usr/local/zookeeper/repository/zookeeper-standalone/logs -- 日志目录
# the port at which the clients will connect
clientPort=2181 -- 客户端连接端口
Linux搭建Zookeeper环境之单机模式和集群模式配置
单机模式Zookeeper 日志输出到指定文件夹:
【1】 修改zookeeper-standalone安装目录conf中log4j.properties:
修改zookeeper.root.logger=INFO, CONSOLE 默认配置为:zookeeper.root.logger=INFO,ROLLINGFILE
#zookeeper.root.logger=INFO, CONSOLE 
zookeeper.root.logger=INFO,ROLLINGFILE
Linux搭建Zookeeper环境之单机模式和集群模式配置
修改#log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender 默认配置为:log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender  --按天统计
#log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender
Linux搭建Zookeeper环境之单机模式和集群模式配置
【2】修改调整 zookeeper-standalone安装目录还需要改bin/zkEnv.sh:
修改#ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs" 为指定的日志目录:ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-standalone/logs":
    #ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
    ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-standalone/logs"
修改#ZOO_LOG4J_PROP="INFO,CONSOLE" 为刚才配置的:ZOO_LOG4J_PROP="INFO,ROLLINGFILE":
    #ZOO_LOG4J_PROP="INFO,CONSOLE"
    ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
if [ "x${ZOO_LOG_DIR}" = "x" ]
then
    #ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
    ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-standalone/logs"
fi
 
if [ "x${ZOO_LOG4J_PROP}" = "x" ]
then
    #ZOO_LOG4J_PROP="INFO,CONSOLE"
    ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
fi
Linux搭建Zookeeper环境之单机模式和集群模式配置
【3】启动测试:
启动zookeeper-standalone服务,输入zkServer.sh start:
[root@marklin conf]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
查看zookeeper-standalone服务的状态,输入zkServer.sh status:
[root@marklin conf]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone
[root@marklin conf]#
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
停止zookeeper-standalone单机服务,输入:zkServer.sh stop:
[root@marklin conf]# zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
 
查看data和logs目录:
data:
Linux搭建Zookeeper环境之单机模式和集群模式配置
logs:
Linux搭建Zookeeper环境之单机模式和集群模式配置
 
【9】集群模式配置部署:
在/usr/local/zookeeper/zookeeper-cluster/cluster-master 目录解压zookeeper安装包:tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-master]# tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-master]# ll
total 41636
drwxr-xr-x. 10  502 games     4096 Apr  3  2017 zookeeper-3.5.3
-rw-r--r--.  1 root root  42630656 Apr  4 11:51 zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-master]#
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
 
在/usr/local/zookeeper/zookeeper-cluster/cluster-slave1目录解压zookeeper安装包:tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-slave1]# tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-slave1]# ll
total 41636
drwxr-xr-x. 10  502 games     4096 Apr  3  2017 zookeeper-3.5.3-beta
-rw-r--r--.  1 root root  42630656 Apr  4 11:51 zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-slave1]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
在/usr/local/zookeeper/zookeeper-cluster/cluster-slave2 目录解压zookeeper安装包:tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-slave2]# tar -xvf zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-slave2]# ll
total 41636
drwxr-xr-x. 10  502 games     4096 Apr  3  2017 zookeeper-3.5.3
-rw-r--r--.  1 root root  42630656 Apr  4 11:52 zookeeper-3.5.3-beta.tar.gz
[root@marklin cluster-slave2]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
集群模式环境变量:vim /etc/profile 
#Setting ZOOKEEPER_HOEM PATH
export ZOOKEEPER_HOEM=/usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3
export PATH=${PATH}:${ZOOKEEPER_HOEM}/bin
export ZOOKEEPER_MASTER_HOEM=/usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3
export PATH=${PATH}:${ZOOKEEPER_MASTER_HOEM}/bin
export ZOOKEEPER_SLAVE1_HOEM=/usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3
export PATH=${PATH}:${ZOOKEEPER_SLAVE1_HOEM}/bin
export ZOOKEEPER_SLAVE2_HOEM=/usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3
export PATH=${PATH}:${ZOOKEEPER_SLAVE2_HOEM}/bin
Linux搭建Zookeeper环境之单机模式和集群模式配置
集群模式conf目录中的zoo_sample.cfg文件复制为zoo.cfg:
在/usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3/conf,输入:cp zoo_sample.cfg zoo.cfg
[root@marklin cluster-master]# cd zookeeper-3.5.3/conf
[root@marklin conf]# ll
total 12
-rw-r--r--. 1 502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1 502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]# cp zoo_sample.cfg zoo.cfg
[root@marklin conf]# ll
total 16
-rw-r--r--. 1  502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1  502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 root root   922 Apr  4 13:23 zoo.cfg
-rw-r--r--. 1  502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
在/usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3/conf,输入:cp zoo_sample.cfg zoo.cfg
[root@marklin cluster-slave1]# cd zookeeper-3.5.3/conf
[root@marklin conf]# ll
total 12
-rw-r--r--. 1 502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1 502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]# cp zoo_sample.cfg zoo.cfg
[root@marklin conf]# ll
total 16
-rw-r--r--. 1  502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1  502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 root root   922 Apr  4 13:25 zoo.cfg
-rw-r--r--. 1  502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
在/usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3/conf,输入:cp zoo_sample.cfg zoo.cfg
[root@marklin cluster-slave2]# cd zookeeper-3.5.3/conf
[root@marklin conf]# ll
total 12
-rw-r--r--. 1 502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1 502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]# cp zoo_sample.cfg zoo.cfg
[root@marklin conf]# ll
total 16
-rw-r--r--. 1  502 games  535 Apr  3  2017 configuration.xsl
-rw-r--r--. 1  502 games 2712 Apr  3  2017 log4j.properties
-rw-r--r--. 1 root root   922 Apr  4 13:26 zoo.cfg
-rw-r--r--. 1  502 games  922 Apr  3  2017 zoo_sample.cfg
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
集群模式修改配置文件zoo.cfg:
cluster-master修改配置zoo.cfg,输入:
# 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/zookeeper/repository/zookeeper-cluster/cluster-master/data
dataLogDir=/usr/local/zookeeper/repository/zookeeper-cluster/cluster-master/logs
# the port at which the clients will connect
clientPort=2182
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
Linux搭建Zookeeper环境之单机模式和集群模式配置
 
cluster-slave1修改配置zoo.cfg,输入:
# 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/zookeeper/repository/zookeeper-cluster/cluster-slave1/data
dataLogDir=/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave1/logs
# the port at which the clients will connect
clientPort=2183
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
Linux搭建Zookeeper环境之单机模式和集群模式配置
cluster-slave2修改配置zoo.cfg,输入:
# 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/zookeeper/repository/zookeeper-cluster/cluster-slave2/data
dataLogDir=/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave2/logs
# the port at which the clients will connect
clientPort=2184
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
PS: 因为是在一台机器上模拟集群,所以端口不能重复,这里用2182~2184,2888~2890,以及3888~3890相互错开。另外每个zk的instance,都需要设置独立的数据存储目录、日志存储目录,所以dataDir、dataLogDir这二个节点对应的目录,需要手动先创建好:
cluster-master:在/usr/local/zookeeper/repository/zookeeper-cluster/cluster-master创建data 和logs文件目录
Linux搭建Zookeeper环境之单机模式和集群模式配置
cluster-slave1:在/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave1创建data 和logs文件目录
Linux搭建Zookeeper环境之单机模式和集群模式配置
cluster-slave2:在/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave2创建data 和logs文件目录
Linux搭建Zookeeper环境之单机模式和集群模式配置
另外还有一个非常关键的设置,在每个zookeeper server配置文件的dataDir所对应的目录下,必须创建一个名为myid的文件,其中的内容必须与zoo.cfg中server.x 中的x相同,即
cluster-master:在/usr/local/zookeeper/repository/zookeeper-cluster/cluster-master/data创建一个名为myid的文件,并标识为1
[root@marklin ~]# cd /usr/local/zookeeper/repository/zookeeper-cluster/cluster-master
[root@marklin cluster-master]# ll
total 0
drwxr-xr-x. 2 root root 18 Apr  4 13:52 data
drwxr-xr-x. 2 root root  6 Apr  4 12:17 logs
[root@marklin cluster-master]# cd data
[root@marklin data]# ll
total 4
-rw-r--r--. 1 root root 3 Apr  4 13:52 myid
[root@marklin data]#
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
cluster-slave1:在/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave1/data创建一个名为myid的文件,并标识为2
[root@marklin zookeeper-cluster]# cd /usr/local/zookeeper/repository/zookeeper-cluster/cluster-salve1
[root@marklin cluster-salve1]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr  4 12:17 data
drwxr-xr-x. 2 root root 6 Apr  4 12:17 logs
[root@marklin cluster-salve1]# cd data
[root@marklin data]# vim myid
[root@marklin data]# ll
total 4
-rw-r--r--. 1 root root 2 Apr  4 13:56 myid
[root@marklin data]#
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
cluster-slave2:在/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave2/data创建一个名为myid的文件,并标识为3
[root@marklin ~]# cd /usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave2
[root@marklin cluster-slave2]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr  4 12:17 data
drwxr-xr-x. 2 root root 6 Apr  4 12:17 logs
[root@marklin cluster-slave2]# cd data/
[root@marklin data]# vim myid
[root@marklin data]# ll
total 4
-rw-r--r--. 1 root root 2 Apr  4 13:59 myid
[root@marklin data]#
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
集群模式Zookeeper 日志输出到指定文件夹:
【1】 修改cluster-master,cluster-slave1,cluster-slave2的安装目录conf中log4j.properties:
修改zookeeper.root.logger=INFO, CONSOLE 默认配置为:zookeeper.root.logger=INFO,ROLLINGFILE
#zookeeper.root.logger=INFO, CONSOLE 
zookeeper.root.logger=INFO,ROLLINGFILE
Linux搭建Zookeeper环境之单机模式和集群模式配置
修改#log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender 默认配置为:log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender  --按天统计
#log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender
Linux搭建Zookeeper环境之单机模式和集群模式配置
 
【2】修改cluster-master,cluster-slave1,cluster-slave2的安装目录中bin/zkEnv.sh:
cluster-master:
修改#ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs" 为指定的日志目录:ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-cluster/cluster-master/logs":
    #ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
    ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-cluster/cluster-master/logs"
 
修改#ZOO_LOG4J_PROP="INFO,CONSOLE" 为刚才配置的:ZOO_LOG4J_PROP="INFO,ROLLINGFILE":
    #ZOO_LOG4J_PROP="INFO,CONSOLE"
    ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
Linux搭建Zookeeper环境之单机模式和集群模式配置
cluster-slave1:
修改#ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs" 为指定的日志目录:ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave1/logs":
    #ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
    ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave1/logs"
修改#ZOO_LOG4J_PROP="INFO,CONSOLE" 为刚才配置的:ZOO_LOG4J_PROP="INFO,ROLLINGFILE":
    #ZOO_LOG4J_PROP="INFO,CONSOLE"
    ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
Linux搭建Zookeeper环境之单机模式和集群模式配置
cluster-slave2:
修改#ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs" 为指定的日志目录:ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave2/logs":
    #ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
    ZOO_LOG_DIR="/usr/local/zookeeper/repository/zookeeper-cluster/cluster-slave2/logs"
修改#ZOO_LOG4J_PROP="INFO,CONSOLE" 为刚才配置的:ZOO_LOG4J_PROP="INFO,ROLLINGFILE":
    #ZOO_LOG4J_PROP="INFO,CONSOLE"
    ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
Linux搭建Zookeeper环境之单机模式和集群模式配置
【3】启动测试:
启动zookeeper-standalone服务,输入zkServer.sh start:
[root@marklin conf]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
查看zookeeper-standalone服务的状态,输入zkServer.sh status:
[root@marklin conf]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone
[root@marklin conf]#
 
Linux搭建Zookeeper环境之单机模式和集群模式配置
停止zookeeper-standalone单机服务,输入:zkServer.sh stop:
[root@marklin conf]# zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@marklin conf]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
测试客户端连接:zookeeper-standalone,cluster-master,cluster-slave1,cluster-slave2
测试客户端连接zookeeper-standalone,输入:zkCli.sh -server 127.0.0.1:2181
[root@marklin conf]# zkCli.sh -server 127.0.0.1:2181
log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.
log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.DailyRollingFileAppender.
Connecting to 127.0.0.1:2181
Welcome to ZooKeeper!
JLine support is enabled
 
WATCHER::
 
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]
Linux搭建Zookeeper环境之单机模式和集群模式配置
测试客户端连接cluster-master,输入:zkCli.sh -server 127.0.0.1:2182
[root@marklin data]# zkCli.sh -server 127.0.0.1:2182
log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.
log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.DailyRollingFileAppender.
Connecting to 127.0.0.1:2182
Welcome to ZooKeeper!
JLine support is enabled
[zk: 127.0.0.1:2182(CONNECTING) 0]
Linux搭建Zookeeper环境之单机模式和集群模式配置
测试客户端连接cluster-slave1,输入:zkCli.sh -server 127.0.0.1:2183
[root@marklin data]# zkCli.sh -server 127.0.0.1:2183
log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.
log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.DailyRollingFileAppender.
Connecting to 127.0.0.1:2183
Welcome to ZooKeeper!
JLine support is enabled
[zk: 127.0.0.1:2183(CONNECTING) 0]
Linux搭建Zookeeper环境之单机模式和集群模式配置
测试客户端连接cluster-slave2,输入:zkCli.sh -server 127.0.0.1:2184
[root@marklin data]# zkCli.sh -server 127.0.0.1:2184
log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.
log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.DailyRollingFileAppender.
Connecting to 127.0.0.1:2184
Welcome to ZooKeeper!
JLine support is enabled
[zk: 127.0.0.1:2184(CONNECTING) 0]
Linux搭建Zookeeper环境之单机模式和集群模式配置
【4】查看jps 进程:
jps:Java Virtual Machine Process Status Tool ,显示当前所有java进程pid的命令
[root@marklin ~]# jps
6832 ZooKeeperMain
6246 QuorumPeerMain
6679 ZooKeeperMain
6760 ZooKeeperMain
6907 ZooKeeperMain
7004 Jps
[root@marklin ~]#
Linux搭建Zookeeper环境之单机模式和集群模式配置
 

相关推荐