1.创建文件夹
[root@localhost /]# cd usr/local
[root@localhost local]# mkdir zookeeper
2.解压至对应文件夹
[root@localhost Downloads]# tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz -C /usr/local/zookeeper
3.创建 data
[root@localhost zookeeper]# mkdir data
[root@localhost zookeeper]# mkdir logs
4.进入 conf 编辑配置文件
[root@localhost apache-zookeeper-3.6.0-bin]# cd conf
[root@localhost conf]# vi "zoo_sample.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=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/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
-- INSERT --
编辑好之后按“esc”退出到“命令模式”,再按“shift+:”进入“底行模式”,按“:wq”保存退出!!
5.进入文件夹启动 Zookeeper
[root@localhost apache-zookeeper-3.6.0-bin]# cd bin
[root@localhost bin]# ./zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper-3.6.0-bin/bin/../conf/zoo.cfg
grep: /usr/local/zookeeper/apache-zookeeper-3.6.0-bin/bin/../conf/zoo.cfg: No such file or directory
grep: /usr/local/zookeeper/apache-zookeeper-3.6.0-bin/bin/../conf/zoo.cfg: No such file or directory
mkdir: cannot create directory ‘’: No such file or directory
Starting zookeeper ... STARTED
成功报错,看来前面使用的 zoo_sample.cfg 是不行的。
6.删除文件 zoo_sample.cfg 新建 zoo.cfg
[root@localhost conf]# rm zoo_sample.cfg
rm: remove regular file ‘zoo_sample.cfg’? y
[root@localhost conf]# ls
configuration.xsl log4j.properties
这里误用 mkdir 创建文件使用 rm -r zoo.cfg 删除
[root@localhost conf]# rm -r zoo.cfg
rm: remove directory ‘zoo.cfg’? y
[root@localhost conf]# ls
configuration.xsl log4j.properties
使用 vi 直接创建 zoo.cfg
[root@localhost conf]# vi zoo.cfg
[root@localhost conf]# ls
configuration.xsl log4j.properties zoo.cfg
[root@localhost conf]# cd ..
[root@localhost apache-zookeeper-3.6.0-bin]# ls
修改对应文件夹 shift:wq 保存退出
tickTime=2000
dataDir=/usr/local/zookeeper/data
clientPort=2181
initLimit=5
syncLimit=2
7.进入对应文件夹启动 Zookeeper 图示成功
[root@localhost bin]# ./zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper-3.6.0-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
启动CLI
[root@localhost bin]# ./zkCli.sh
/usr/bin/java
Connecting to localhost:2181
......
Welcome to ZooKeeper!
......
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
附上停止 Zookeeper 服务器命令 zkServer.sh stop
末言:说真的是真不觉 vi 好用,补上一些常用命令,后续还会整理。
vi fileName 进入编辑,不存在就创建
i 进入编辑模式
esc 退出编辑进入 vi 命令模式
shift : 退出 vi 命令模式进入底行模式
wq 保存退出
q 直接退出