1.将ZOOKEEPER安装包上传到服务器上
/usr/local
2.解压并重命名目录
tar xzvf zookeeper-3.4.8.tar.gz
mv zookeeper-3.4.8 zookeeper
3.修改环境变量
vi /etc/profile
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin
修改完环境变量后必须应用
source /etc/profile
查看是否修改成功
echo $ZOOKEEPER_HOME
4.修改zookeeper配置文件
cd /usr/local/zookeeper/conf
mv zoo_sample.cfg zoo.cfg
mkdir -p /usr/local/zookeeper/data
然后将以下内容或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=/usr/local/zookeeper/data
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
server.1=name1:2888:3888
server.2=name2:2888:3888
server.3=data1:2888:3888
server.4=data2:2888:3888
server.5=data3:2888:3888
以上需要注意的是有几个机器就用几个server.
server.n=主机名:端口号1:端口号2 端口号1和端口号2万万不能一样
server.1=xxxx:yyyy:zzzz //此处指的是你有多少台zookeeper 每台安装zookeeper的服务器主机名又叫什么以及相应的端口号。
在/usr/local/zookeeper/data下生成myid文件
生成方法
echo 1 > /usr/local/zookeeper/data/myid
myid文件代表的意思是告诉zookeeper我是该集群中的第几号机器
然后在myid文件中从1开始填入对应的数字
5.以上步骤完成后启动zookeeper
zkServer.sh start 打开zookeeper
zkServer.sh status(看到stantalone说明是单节点,并且启动成功)
zkServer.sh stop 关闭zookeeper
zkServer.sh restart 重启zookeeper
输入命令:jps
26467 QuorumPeerMain ---->>>这个就代表zookeeper进程已经启动
46773 ResourceManager
46329 NameNode
26523 Jps
46876 NodeManager
46430 DataNode
46623 SecondaryNameNode
jps |grep -v Jps