Linux环境下安装zookeeper

Posted 煮海焚天

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux环境下安装zookeeper相关的知识,希望对你有一定的参考价值。

1. 下载安装文件zookeeper-3.4.6.tar.gz
 
2. 还是copy到虚拟机的centos系统桌面
 
3. 新建/usr/loca/zookeeper文件夹
[[email protected] ~]# mkdir -pv /usr/local/zookeeper
 
4.拷贝文件到指定文件夹
[[email protected] ~]# cd /root/Desktop/
[[email protected] ~]# cp ./zookeeper-3.4.6.tar.gz /usr/local/zookeeper
 
5. 解压
[[email protected] ~]# tar -zxvf jdk-8u121-linux-x64.tar.gz
 
6. 配置环境变量
[[email protected] ~]#cd /etc/
[[email protected] ~]#cp ./profile ./profile.bak -- 把文件备份一下
[[email protected] ~]#vi /etc/profile -- 编辑此配置文件
在文件末尾添加此段内容: -- 开始和--中间的一段.(注意,尽量保持环境变量名全大写,下划线隔开. 保持规范)
-- 开始
export ZOOKEEPER_INSTALL=/usr/local/zookeeper/zookeeper-3.4.6/
export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
-- 结束
 
7. 配置文件修改
[[email protected] zookeeper-3.4.6]# cd /usr/local/zookeeper/zookeeper-3.4.6/conf/ -- 进入文件所在路径
[[email protected] conf]# cp zoo_sample.cfg zoo.cfg -- 将zoo.sample.cfg拷贝出一份zoo.cfg出来. 文件名强制
 
8. 文件内容如下:
[[email protected] conf]# vi zoo.cfg -- 按i进入编辑模式. 修改完成之后, esc退出编辑模式, 大写字母Z双击即可保存.
# 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 -- 这里要设置一下文件路径 路径必须存在,不存在的话就新建一个呗
dataLogDir=/tmp/zookeeper/log -- 日志路径 路径必须存在,不存在的话就新建一个呗
# the port at which the clients will connect
clientPort=2181 -- 如果是多机器的话,在clientPort处添加服务器的ip
# 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
 
修改完之后 通过 > # cat zoo.cfg 查看.
 
 
9. 开启服务,关闭服务, 查看
[[email protected] bin]# cd /usr/local/zookeeper/zookeeper.3.4.6/bin/
[[email protected] bin]# ./zkServer.sh stop -- 停止服务
JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
 
[[email protected] bin]# ./zkServer.sh start -- 开启服务
JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
 
[[email protected] bin]# ./zkServer.sh status -- 查看状态
JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
 
[[email protected] bin]# ./zkCli.sh -- 客户端启动, 可以查看启动状态和日志
Connecting to localhost:2181
2017-03-08 06:15:26,918 [myid:] - INFO [main:[email protected]] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2017-03-08 06:15:26,923 [myid:] - INFO [main:[email protected]] - Client environment:host.name=localhost
2017-03-08 06:15:26,923 [myid:] - INFO [main:[email protected]] - Client environment:java.version=1.8.0_121
2017-03-08 06:15:26,925 [myid:] - INFO [main:[email protected]] - Client environment:java.vendor=Oracle Corporation
2017-03-08 06:15:26,926 [myid:] - INFO [main:[email protected]] - Client environment:java.home=/usr/local/java/jdk1.8.0_121/jre
2017-03-08 06:15:26,926 [myid:] - INFO [main:[email protected]] - Client environment:java.class.path=/usr/local/zookeeper/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../conf:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:
2017-03-08 06:15:26,926 [myid:] - INFO [main:[email protected]] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-03-08 06:15:26,926 [myid:] - INFO [main:[email protected]] - Client environment:java.io.tmpdir=/tmp
2017-03-08 06:15:26,926 [myid:] - INFO [main:[email protected]] - Client environment:java.compiler=<NA>
2017-03-08 06:15:26,930 [myid:] - INFO [main:[email protected]] - Client environment:os.name=Linux
2017-03-08 06:15:26,930 [myid:] - INFO [main:[email protected]] - Client environment:os.arch=amd64
2017-03-08 06:15:26,930 [myid:] - INFO [main:[email protected]] - Client environment:os.version=2.6.32-431.el6.x86_64
2017-03-08 06:15:26,931 [myid:] - INFO [main:[email protected]] - Client environment:user.name=root
2017-03-08 06:15:26,931 [myid:] - INFO [main:[email protected]] - Client environment:user.home=/root
2017-03-08 06:15:26,931 [myid:] - INFO [main:[email protected]] - Client environment:user.dir=/usr/local/zookeeper/zookeeper-3.4.6/bin
2017-03-08 06:15:26,940 [myid:] - INFO [main:[email protected]] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 [email protected]
Welcome to ZooKeeper!
2017-03-08 06:15:27,039 [myid:] - INFO [main-SendThread(localhost:2181):[email protected]] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2017-03-08 06:15:27,290 [myid:] - INFO [main-SendThread(localhost:2181):[email protected]] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
[zk: localhost:2181(CONNECTING) 0] 2017-03-08 06:15:27,445 [myid:] - INFO [main-SendThread(localhost:2181):[email protected]] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x15aae45f1330000, negotiated timeout = 30000
 
WATCHER::
 
WatchedEvent state:SyncConnected type:None path:null
 
[email protected] bin]# ps -ef | grep zookeeper -- 查看zookeeper的服务进程. 看样子还是挺嗨的.
root 9779 9774 0 05:26 pts/0 00:00:09 /usr/local/java/jdk1.8.0_121/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/zookeeper/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../conf:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib: org.apache.zookeeper.ZooKeeperMain
root 10188 10183 0 06:14 pts/0 00:00:00 /usr/local/java/jdk1.8.0_121/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/zookeeper/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../conf:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib: org.apache.zookeeper.ZooKeeperMain
root 10230 1 0 06:15 pts/1 00:00:01 /usr/local/java/jdk1.8.0_121/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/zookeeper/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../conf:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /usr/local/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
root 10282 10277 0 06:15 pts/0 00:00:01 /usr/local/java/jdk1.8.0_121/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/zookeeper/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.6/bin/../conf:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib:.:/usr/local/java/jdk1.8.0_121/lib/dt.jar:/usr/local/java/jdk1.8.0_121/lib/tools.jar:/usr/local/java/jdk1.8.0_121/jre/lib: org.apache.zookeeper.ZooKeeperMain
root 10314 8885 0 06:18 pts/0 00:00:00 grep zookeeper
 
10 到此, zookeeper的单机版安装完成.

以上是关于Linux环境下安装zookeeper的主要内容,如果未能解决你的问题,请参考以下文章

在Linux上部署Kettle环境

linux配置java环境变量(详细)

linux配置java环境变量(详细)

ubutu 下jdk安装

linux系统下安装和配置redis(2021版)

linux系统下安装和配置redis(2021版)