码迷,mamicode.com
首页 > 其他好文 > 详细

(个人)Zookeeper集群环境部署

时间:2017-08-19 20:16:45      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:准备   服务   increase   timeout   ase   support   firewall   iat   containe   

一.准备工作
1. 下载zookeeper,下载地址:https://zookeeper.apache.org/releases.html#download 
2. 下载CentOS7的镜像,下载地址:https://www.centos.org/download/
3. 准备XManager,用于远程连接Linux,我用的是CentOS7.
4. 准备VMVare Workstation,安装好3台以上(至少3台才能集群)CentOS75. 设置好CentOS的JDK,本人使用的是最新的JDK8

二. Zookeeper部署

说明:该教程是在一个机器上部署的,请求1-5步完成后,重复在其他机器上进行操作.1. 将下载好的 zookeeper-3.4.10.tar.gz(我当前版本) 通过XFTP上传到Linux的指定目录,假设为 ZK_HOME 2. 在ZK_HOME中解压zookeeper
tar -zxvf zookeeper-3.4.10.tar.gz
3. 在ZK_HOME的conf目录中,复制zookeeper的配置为zoo.cfg(zk启动时候默认的配置文件)
cd /ZK_HOME
cp zoo_sample.cfg zoo.cfg
---如果是单机环境部署,可以直接通过此命令启动.
---ZK的启动参数有: {start|start-foreground|stop|restart|status|upgrade|print-cmd}
./zkServer.sh start 
4. 在ZK_HOME的conf目录的zoo.cfg的最后添加如下配置:
server.1=192.168.100.10:2888:3181
server.2=192.168.100.11:2888:3181
server.3=192.168.100.12:2888:3181
说明:
a. 2888表示follower节点与leader节点交换信息的端口号b. 3181是在leader节点挂掉后,进行leader选举需要的端口.本步骤完成后,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=/tmp/zookeeper
# 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=192.168.100.10:2888:3181
server.2=192.168.100.11:2888:3181
server.3=192.168.100.12:2888:3181
5. 在ZK_HOME的zoo.cfg中有一个
dataDir=/tmp/zookeeper
此时需要在该指定目录下创建myid文件,其中的文件内容为zoo.cfg最后部分的配置获取.获取规则:假设本机ip为192.168.100.10 那么此时的myid文件中只有一行内容各位1
cd /tmp
mkdir /zookeeper
vim myid
---通过vim设置myid
6. 启动启动ZK跳转到ZK的bin目录下,然后运行
-- 启动zookeeper
./zkServer.sh start
-- 查看运行状态
./zkServer.sh status 
7. 连接zookeeper,其中连接端口为2181 
zkCli.sh -server 192.168.100.10:2181,192.168.100.11:2181,192.168.100.12:2181
如果连接成功可以看到如下信息
2017-08-19 01:48:03,042 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
2017-08-19 01:48:03,057 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=localhost
2017-08-19 01:48:03,057 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_144
2017-08-19 01:48:03,075 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-08-19 01:48:03,076 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.8.0_144/jre
2017-08-19 01:48:03,076 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/lcf-tools/zookeeper-3.4.10/bin/../build/classes:/lcf-tools/zookeeper-3.4.10/bin/../build/lib/*.jar:/lcf-tools/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/lcf-tools/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/lcf-tools/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/lcf-tools/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/lcf-tools/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/lcf-tools/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/lcf-tools/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/lcf-tools/zookeeper-3.4.10/bin/../conf:
2017-08-19 01:48:03,079 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-08-19 01:48:03,080 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017-08-19 01:48:03,080 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2017-08-19 01:48:03,081 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2017-08-19 01:48:03,081 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2017-08-19 01:48:03,081 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-514.26.2.el7.x86_64
2017-08-19 01:48:03,082 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2017-08-19 01:48:03,082 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2017-08-19 01:48:03,082 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/lcf-tools/zookeeper-3.4.10/conf
2017-08-19 01:48:03,087 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=192.168.100.10:2181,192.168.100.11:2181,192.168.100.12:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@1a86f2f1
2017-08-19 01:48:03,195 [myid:] - INFO  [main-SendThread(192.168.100.10:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 192.168.100.10/192.168.100.10:2181. Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
JLine support is enabled
2017-08-19 01:48:03,746 [myid:] - INFO  [main-SendThread(192.168.100.10:2181):ClientCnxn$SendThread@876] - Socket connection established to 192.168.100.10/192.168.100.10:2181, initiating session
[zk: 192.168.100.10:2181,192.168.100.11:2181,192.168.100.12:2181(CONNECTING) 0] 2017-08-19 01:48:04,093 [myid:] - INFO  [main-SendThread(192.168.100.10:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 192.168.100.10/192.168.100.10:2181, sessionid = 0x15df975935c0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

三. 补充内容

0. zookeeper目录中各个文件的认识
bin目录 
zk的可执行脚本目录,包括zk服务进程,zk客户端,等脚本。其中,.sh是Linux环境下的脚本,.cmd是Windows环境下的脚本。
conf目录 
配置文件目录。zoo_sample.cfg为样例配置文件,需要修改为自己的名称,一般为zoo.cfg。log4j.properties为日志配置文件。
lib 
zk依赖的包。
contrib目录 
一些用于操作zk的工具包。
1. 如果不想每次zookeeper都跳转到zk的bin目录,则可以将bin目录加入全局path中.注意第3行和第5行末尾
2. zookeeper启动后会在bin目录生成一个zookeeper.out的日志文件,可以通过tail指令进行查看
如果觉得麻烦,还可以直接通过添加指令的形式一起启动进行查看:
3. zoo.cfg配置文件解读
4. 启动后提示  java.net.NoRouteToHostException:No route to host 该问题为找不到路由,防火墙没有关闭.
---------------------------------------------------------------
Ubuntu(ubuntu-12.04-desktop-amd64)
查看防火墙状态:ufw status
关闭防火墙:ufw disable
---------------------------------------------------------------
centos6.0
查看防火墙状态:service iptables status
关闭防火墙:chkconfig iptables off    #开机不启动防火墙服务
--------------------------------------------------------------
centos7.0(默认是使用firewall作为防火墙,如若未改为iptables防火墙,使用以下命令查看和关闭防火墙)
查看防火墙状态:firewall-cmd --state
关闭防火墙:systemctl stop firewalld.service
5. 提示 Address aready in use ,该问题应该是端口被占用,通过如下指令查看端口占用:
-----查看端口占用------
方法一  lsof -i:端口号
方法二  netstat -tunlp|grep 端口号
-----杀掉进程---------
推荐方法  kill -s 9 3382  其中9为尽快杀掉进程的意思  3382为pid 















(个人)Zookeeper集群环境部署

标签:准备   服务   increase   timeout   ase   support   firewall   iat   containe   

原文地址:http://www.cnblogs.com/LiuChunfu/p/7397350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!