linux环境装配zookeeper
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
目前我们基本上做把zookeeper作为分布式服务处理,service服务通过zookeeper注册,action通过zookeeper找到对应的服务。安装也比较简单,我们目前安装的是3.4.6的版本,3.4.8的版本还只是测试版本。
1、下载地址:http://zookeeper.apache.org/releases.html
2、解压 tar zxvf zookeeper-3.4.6.tar.gz
3、复制conf目录下的zoo_sample.cfg,并命名为zoo.cfg
4、修改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=/datatmp/zookeeper/data dataLogDir=/datatmp/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 # # 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 #2888,3888 are election port server.1=zookeeper:2888:3888
5、创建dataDir参数指定的目录(这里指的是“ /datatmp/zookeeper/data”),并在目录下创建文件,命名为“myid”。
6、编辑“myid”文件,并在对应的IP的机器上输入对应的编号。如在zookeeper上,“myid”文件内容就是1。由于本次只在单点上进行安装配置,所以只有一个server.1。若还有其他服务器,比如地址为192.168.1.102,则在zoo.cfg文件中还需加入server.2=192.168.1.102:2888:3888。那么myid文件在192.168.1.102服务器上的内容就是2。至此,如果是多服务器配置,就需要将zookeeper-3.4.3目录拷贝到其他服务器,然后按照上述的方法修改myid。
安装好了,启动搞搞.
1.启动
zookeeper-3.4.6/bin/zkServer.sh start
2.输入jps命令查看进程
1573 QuorumPeerMain1654 Jps
其中,QuorumPeerMain是zookeeper进程,启动正常。
3、查看状态:zookeeper-3.4.3/bin/zkServer.sh status
-JMX enabled by defaultUsing config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfgMode: standalone
4、启动客户端脚本:zookeeper-3.4.3/bin/zkCli.sh -server zookeeper:2181
5、停止zookeeper进程:zookeeper-3.4.3/bin/zkServer.sh stop