centos安装zookeeper(非集群)

Posted on Posted in linux
Tips: 本文创建于2015年12月2日,已超过 2 年,内容或图片可能已经失效!

centos安装zookeeper(非集群)

官网

环境

Distributor ID: CentOS  
Description:    CentOS release 6.5 (Final)  
Release:    6.5  
Codename:   Final  
需要安装java jdk环境(配置环境变量)  
export JAVA_HOME=/usr/java/jdk1.7.0_80  
export JRE_HOME=/usr/java/jdk1.7.0_80/jre  
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH  
export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib  
export LC_ALL=zh_CN.UTF-8  

安装

cd /usr/local      
tar zxvf zookeeper-3.3.6.tgz.gz      
cd zookeeper-3.3.6/conf/      
cp -rf zoo_sample.cfg zoo.cfg      
vim zoo.cfg       
      
# The number of milliseconds of each tick      
tickTime=2000      
# The number of ticks that the initial       
# synchronization phase can take      
initLimit=10    #这个配置项是用来配置Zookeeper接受客户端(这里所说的客户端不是用户连接Zookeeper服务器的客户端,而是Zookeeper服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒      
# The number of ticks that can pass between       
# sending a request and getting an acknowledgement      
syncLimit=5     #这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒。      
# the directory where the snapshot is stored.      
# the port at which the clients will connect      
clientPort=2181      
dataDir=/usr/local/zookeeper-3.3.6/ZooData/data      
dataLogDir=/usr/local/zookeeper-3.3.6/ZooData/logs      
server.1=iZ25siitw28Z:2888:38888    #单点可以不要这个配置  
#server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。      
      
mkdir /usr/local/zookeeper-3.3.6/ZooData/{data,logs}      
      
cd /usr/local/zookeeper-3.3.6/ZooData/data      
touch myid      
#编辑"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      
      
vim /etc/profile      
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.3.6      
export PATH=$ZOOKEEPER_HOME/bin:$PATH      
export PATH      
      
./bin/zkServer.sh start      
JMX enabled by default      
      
Using config: /usr/local/zookeeper-3.3.6/bin/../conf/zoo.cfg      
Starting zookeeper ... /usr/local/zookeeper-3.3.6/ZooData/data/zookeeper_server.pid      
STARTED 

测试

./bin/zkCli.sh     
Connecting to localhost:2181    
2015-12-02 16:28:42,094 - INFO  [main:Environment@97] - Client environment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT    
2015-12-02 16:28:42,097 - INFO  [main:Environment@97] - Client environment:host.name=iZ25siitw28Z    
2015-12-02 16:28:42,098 - INFO  [main:Environment@97] - Client environment:java.version=1.7.0_80    
2015-12-02 16:28:42,098 - INFO  [main:Environment@97] - Client environment:java.vendor=Oracle Corporation    
2015-12-02 16:28:42,099 - INFO  [main:Environment@97] - Client environment:java.home=/usr/java/jdk1.7.0_80/jre    
2015-12-02 16:28:42,099 - INFO  [main:Environment@97] - Client environment:java.class.path=/usr/local/zookeeper-3.3.6/bin/../build/classes:/usr/local/zookeeper-3.3.6/bin/../build/lib/*.jar:/usr/local/zookeeper-3.3.6/bin/../zookeeper-3.3.6.jar:/usr/local/zookeeper-3.3.6/bin/../lib/log4j-1.2.15.jar:/usr/local/zookeeper-3.3.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.3.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.3.6/bin/../conf:    
2015-12-02 16:28:42,099 - INFO  [main:Environment@97] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib    
2015-12-02 16:28:42,100 - INFO  [main:Environment@97] - Client environment:java.io.tmpdir=/tmp    
2015-12-02 16:28:42,100 - INFO  [main:Environment@97] - Client environment:java.compiler=<NA>    
2015-12-02 16:28:42,101 - INFO  [main:Environment@97] - Client environment:os.name=Linux    
2015-12-02 16:28:42,101 - INFO  [main:Environment@97] - Client environment:os.arch=amd64    
2015-12-02 16:28:42,101 - INFO  [main:Environment@97] - Client environment:os.version=2.6.32-431.23.3.el6.x86_64    
2015-12-02 16:28:42,102 - INFO  [main:Environment@97] - Client environment:user.name=root    
2015-12-02 16:28:42,102 - INFO  [main:Environment@97] - Client environment:user.home=/root    
2015-12-02 16:28:42,102 - INFO  [main:Environment@97] - Client environment:user.dir=/usr/local/zookeeper-3.3.6/bin    
2015-12-02 16:28:42,104 - INFO  [main:ZooKeeper@379] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7f188439    
2015-12-02 16:28:42,119 - INFO  [main-SendThread():ClientCnxn$SendThread@1058] - Opening socket connection to server localhost/127.0.0.1:2181    
Welcome to ZooKeeper!    
2015-12-02 16:28:42,132 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@947] - Socket connection established to localhost/127.0.0.1:2181, initiating session    
JLine support is enabled    
2015-12-02 16:28:42,143 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@736] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x15161bb550f0003, negotiated timeout = 30000    
    
WATCHER::    
    
WatchedEvent state:SyncConnected type:None path:null    
[zk: localhost:2181(CONNECTED) 0] create /mydata 'abc'    
Node already exists: /mydata    
[zk: localhost:2181(CONNECTED) 1] get /mydata    
'abc'    
cZxid = 0x6    
ctime = Wed Dec 02 16:09:53 CST 2015    
mZxid = 0x6    
mtime = Wed Dec 02 16:09:53 CST 2015    
pZxid = 0x6    
cversion = 0    
dataVersion = 0    
aclVersion = 0    
ephemeralOwner = 0x0    
dataLength = 5    
numChildren = 0    
[zk: localhost:2
181(CONNECTED) 2]  
  
[root@iZ25siitw28Z zookeeper-3.3.6]# jps  
5253 QuorumPeerMain    #zookeeper 进程名  
5343 Jps 
» 转载请注明来源:若我若鱼 » centos安装zookeeper(非集群)

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen + seventeen =