Zookeeper

Zookeeper是一个分布式的,开放源代码的分布式应用协调服务(有用的给响应,没用的从服务列表剔除)。它是一开源项目,依赖于jdk。并且他说Hadoop和Habase的一个重要组件。
Zookeeper的搭建
1单台搭建方式
其中只有一台zookeeper为用户提供服务
2集群搭建
可以实现高可用的状态,一般都是基数台

单台搭建方式
修改静态ip
inet addr:192.168.6.130







2配置jdk https://pan.baidu.com/s/1pm-1VLq04WlV5c4ckEwXNw

[root@localhost ~]# vim /etc/profile

全新的虚拟机无jdk需要自己配置

#set java env
JAVA_HOME=/usr/local/src/java/jdk1.7.0_51
JAVA_BIN=/usr/local/src/java/jdk1.7.0_51/bin
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# mkdir java
[root@localhost src]# cd java/

导入jdk的jar包到虚拟机



解压

[root@localhost java]# ls
jdk-7u51-linux-x64.tar.gz 
[root@localhost java]# tar -xvf jdk-7u51-linux-x64.tar.gz 

查看版本

[root@localhost java]# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

注意jdk的安装路径

[root@localhost java]# pwd
/usr/local/src/java

去官网下载zookeeper https://zookeeper.apache.org/






https://pan.baidu.com/s/1fjxWHWZXAYbE9I1IammcpQ
进入上一级目录,上传zookeeper安装文件

[root@localhost java]# cd ../
[root@localhost src]# pwd
/usr/local/src
[root@localhost src]# ls
java  zookeeper-3.4.10.tar.gz

解压

[root@localhost src]# tar -xvf zookeeper-3.4.10.tar.gz 

查看

[root@localhost src]# ls
java zookeeper-3.4.10
[root@localhost src]# cd zookeeper-3.4.10
[root@localhost zookeeper-3.4.10]# ls
bin              ivy.xml               src
build.xml        lib                   zookeeper-3.4.10.jar
conf             LICENSE.txt           zookeeper-3.4.10.jar.asc
contrib          NOTICE.txt            zookeeper-3.4.10.jar.md5
dist-maven       README_packaging.txt  zookeeper-3.4.10.jar.sha1
docs             README.txt
ivysettings.xml  recipes

在根目录创建数据文件和日志文件文件夹

[root@localhost zookeeper-3.4.10]# mkdir data log

pwd复制当前路径

[root@localhost zookeeper-3.4.10]# pwd
/usr/local/src/zookeeper-3.4.10
[root@localhost zookeeper-3.4.10]# cd conf/
[root@localhost conf]# ls
configuration.xsl  log4j.properties  zoo_sample.cfg

复制一份zoo_sample.cfg,改名为zoo.cfg

[root@localhost conf]# cp zoo_sample.cfg zoo.cfg
[root@localhost conf]# ls
configuration.xsl  log4j.properties  zoo.cfg  zoo_sample.cfg

编辑配置文件

[root@localhost conf]# vim zoo.cfg

数据文件夹 改12行的dataDir=/tmp/zookeeper

dataDir=/usr/local/src/zookeeper-3.4.10/data

日志文件夹 在13行新增

dataLogDir=/usr/local/src/zookeeper-3.4.10/log

clientPort=2181代表服务的连接端口

:wq

完整代码

# 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/src/zookeeper-3.4.10/data
dataLogDir=/usr/local/src/zookeeper-3.4.10/log
# 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

关闭防火墙

[root@localhost conf]# service iptables stop

启动zookeeper

[root@localhost conf]# cd ../
[root@localhost zookeeper-3.4.10]# cd bin
[root@localhost bin]# ls
README.txt  zkCleanup.sh  zkCli.cmd  zkCli.sh  zkEnv.cmd  zkEnv.sh  zkServer.cmd  zkServer.sh
[root@localhost bin]# sh zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

重启命令是

[root@localhost bin]# sh zkServer.sh restart

那么关闭命令是

[root@localhost bin]# sh zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.4.10/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

验证

[root@localhost bin]# sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: standalone

出现上述信息代表成功, standalone带代表单击
以下命令为查询当前zookeeper的信息

[root@localhost bin]# jps
3450 QuorumPeerMain
3520 Jps

验证数据和日志文件夹

[root@localhost bin]# cd ../
[root@localhost zookeeper-3.4.10]# cd data
[root@localhost data]# ls
version-2  zookeeper_server.pid
[root@localhost data]# cd ../log
[root@localhost log]# ls
version-2

你可能感兴趣的:(Zookeeper)