我是靠谱客的博主 坚强冬日,最近开发中收集的这篇文章主要介绍zookeeper安装过程,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

准备工作为了区分我是建立zookeeper ,apache目录的如:

[root@localhost /]mkdir -p /usr/local/zookeeper

[root@localhost /]mkdir -p /usr/local/apache

切换到zookeeper目录下面

[root@localhost /]cd /usr/local/zookeeper

[root@localhost zookeeper]# wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

等待下载完毕

当前目录解压

[root@localhost zookeeper]# tar -zxvf zookeeper-3.4.6.tar.gz

[root@localhost zookeeper]# ll
总用量 17292
drwxr-xr-x. 10 1000 1000     4096 2月  20 2014 zookeeper-3.4.6
-rw-r--r--.  1 root root 17699306 1月  11 2016 zookeeper-3.4.6.tar.gz

创建两个目录

[root@localhost zookeeper]# mkdir -p /home/zookeeper/data
[root@localhost zookeeper]#
[root@localhost zookeeper]#
[root@localhost zookeeper]# mkdir -p /home/zookeeper/logs


[root@localhost zookeeper-3.4.6]# cd zookeeper-3.4.6/conf/
[root@localhost conf]# ll
总用量 12
-rw-rw-r--. 1 1000 1000  535 2月  20 2014 configuration.xsl
-rw-rw-r--. 1 1000 1000 2161 2月  20 2014 log4j.properties
-rw-rw-r--. 1 1000 1000  922 2月  20 2014 zoo_sample.cfg

[root@localhost conf]# cp zoo_sample.cfg zoo.cfg

[root@localhost conf]# vi 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=/home/zookeeper/data
dataLogDir=/home/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

server.1=172.17.215.188:2888:3888

server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务 器的 IP 地址或/etc/hosts 文件中映射了 IP 的主机名;C 表示的是这个服务器与 集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务 器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是 用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是 一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同 的端口号

[root@localhost conf]# vi /home/zookeeper/data/myid

1
~                                                                                                                                                                                              
~                                 
                                                                                                                                                             
                                                                                                                                                                                       


配置一下zookeeper的环境变量

[root@localhost java]# vi /etc/profile

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
..............................省略
unset i
unset pathmunge
export JAVA_HOME=/usr/local/java/jdk1.6.0_30/
export JAVA_BIN=/usr/local/java/jdk1.6.0_30/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
export ZOOKEEPER_HOME=/usr/local/zookeeper/zookeeper-3.4.6
export PATH="$PATH:$ZOOKEEPER_HOME/bin"

然后执行下面的  PS:如果没有配置JDK的需要配置JDK哦不然后面的jps命令用不了,虽然可以不用。。。。

[root@localhost java]# source /etc/profile


在防火墙中打开要用到的端口 2181、2888、3888 切换到 root 用户权限,执行以下命令:

[root@localhost java]# chkconfig iptables on

[root@localhost java]# service iptables start

编辑/etc/sysconfig/iptables

[root@localhost java]# vi /etc/sysconfig/iptables

增加以下 3 行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT

重启防火墙:

[root@localhost java]#service iptables restart

查看防火墙端口状态:

[root@localhost java]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num target prot opt source destination

1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED

2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0

3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0

4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22

5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2181

6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2888

7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:3888

下面省略。。。


[root@localhost java]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

用JPS简单多了

[root@localhost java]# jps
13497 Jps
13219 QuorumPeerMain
[root@localhost java]# ps -aux|grep zookeeper
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root     13219  0.2  3.2 1423804 33132 pts/1   Sl   17:00   0:02 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: -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     13509  0.0  0.0 103260   840 pts/1    S+   17:22   0:00 grep zookeeper


配置 zookeeper 开机使用 用户启动:

[root@localhost java]# vi /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
su - root -c '/usr/local/zookeeper/zookeeper-3.4.6/bin/zkServer.sh start'


开机就可以自己启动 了


参考文件:http://www.cnblogs.com/jeesml/p/5100610.html















最后

以上就是坚强冬日为你收集整理的zookeeper安装过程的全部内容,希望文章能够帮你解决zookeeper安装过程所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部