Zookeeper在Centos7上搭建单节点应用

  (默认机器上已经安装并配置好了jdk)

1、下载zookeeper并解压

  $ tar -zxvf zookeeper-3.4.6.tar.gz

2、将解压后的文件夹移动到 /usr/local/ 目录下

  $ mv zookeeper-3.4.6/ /usr/local/

3、在zookeeper的目录下新建data 和 logs 两个目录

  $ cd /usr/local/zookeeper-3.4.6

  $ mkdir data

  $ mkdir logs

4、到zookeeper3.4.6/conf目录下将zoo_sample.cfg文件拷贝一份,命名为zoo.cfg

  $ cd /usr/local/zookeeper-3.4.6/conf

  $ cp zoo_sample.cfg zoo.cfg

5、修改zoo.cfg文件

  $ vim 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
# Leader与Follower之间发送消息,请求和应答时间长度,最长不超过多少个tickTime的时间长度 syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. #这个地方的目录地址改一下 dataDir=/usr/local/zookeeper-3.4.6/data #日志目录 dataLogDir=/usr/local/zookeeper-3.4.6/logs # 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
# 192.168.192.130 当前机器的ip
# 2888端口号是zookeeper服务之间通信的端口
# 3888是zookeeper与其他应用程序通信的端口
server.0=192.168.192.130:2888:3888

 

6、在 /usr/local/zookeeper-3.4.6/data下创建myid文件

  $ vim myid

# 这个数字跟步骤5中最下面的server.0要一样
0

 

7、zookeeper的配置环境变量(配置完成后要记得source /etc/profile 生效修改)

  $ vim /etc/profile

# jdk8 enviroment variables
export JAVA_HOME=/home/look/dev-software/jdk/jdk1.8.0_144
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
# Zookeeper enviroment variables
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.6

 

8、配置防火墙

  在防火墙中打开要用到的端口2181,2888,3888。用root权限执行命令。

  $ chkconfig iptables on

  $ service iptables start

       ✎编辑 /etc/sysconfig/iptables:

  $ vim /etc/sysconfig/iptables

  ✎增加以下三行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT

 

  ✎重启防火墙:

  $ service iptables restart

  ✎查看防火墙端口状态:

  $ service iptables status

9、启动并测试zookeeper

  $ cd /usr/local/zookeeper-3.4.6/bin

  (1)启动zookeeper

  $ ./zkServer.sh start

  (2)输入jps命令查看进程:

  $ jps

  1456 QuorumPeerMain

  1457 Jps

  其中,QuorumPeerMain 是zookeeper进程,启动正常

  (3)查看状态

  $ zkServer.sh status

  (4)查看zookeeper服务输入信息:

  服务信息输入文件在 /usr/local/zookeeper-3.4.6/bin/zookeeper.out

  $ tail -200f zookeeper.out

10、停止zookeeper 进程:

  $ cd /usr/local/zookeeper-3.4.6/bin

  $ zkServer.sh stop

11、配置zookeeper开机启动:

  $ vim /etc/rc.local 文件,加入

su - root -c '/usr/local/zookeeper3.4.6/bin/zkServer.sh start'

 

 

 

posted @ 2018-02-09 22:01  寻找风口的猪  阅读(523)  评论(0编辑  收藏  举报