标签:
1,准备:
A:三台linxu服务器:
10.112.29.177
10.112.29.172
10.112.29.174
命令 hostname 得到每台机器的 hostname
vm-10-112-29-177
vm-10-112-29-172
vm-10-112-29-174
分别创建
/opt/zookeeper/server1/data
/opt/zookeeper/server1/dataLog
/opt/zookeeper/server2/data
/opt/zookeeper/server2/dataLog
/opt/zookeeper/server3/data
/opt/zookeeper/server3/dataLog
B:下载zookeeper
版本:zookeeper-3.4.8.tar.gz
解压 tar -zxvf zookeeper-3.4.8.tar.gz
zookeeper-3.4.8
C:下载jdk
版本: jdk-7u80-linux-x64.gz
解压 tar -zxvf jdk-7u80-linux-x64.gz
jdk1.7.0_80
D:配置java环境变量
/etc/profile 文件中加入:
export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$PATH:/usr/java/jdk1.7.0_80/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
# 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=/opt/zookeeper/server1/data
dataLogDir=/opt/zookeeper/server1/dataLog
server.
1
=vm-10-112-29-177
:
2888
:
3888
server.
2
=vm-10-112-29-172
:
2888
:
3888
server.
3
=vm-10-112-29-174
:
2888
:
3888
# 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
dataDir=/opt/zookeeper/server2/data
dataLogDir=/opt/zookeeper/server2/dataLog
dataDir=/opt/zookeeper/server3/data
dataLogDir=/opt/zookeeper/server3/dataLog
tickTime:zookeeper中使用的基本时间单位, 毫秒值。
initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个 tickTime 时间间隔数。这里设置为
5
表名最长容忍时间为
5
*
2000
=
10
秒。
syncLimit:这个配置标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是
2
*
2000
=
4
秒。
dataDir 和 dataLogDir 看配置就知道干吗的了,不用解释。
clientPort:监听client连接的端口号,这里说的client就是连接到Zookeeper的代码程序。
server.{myid}={ip}:{leader服务器交换信息的端口}:{当leader服务器挂了后, 选举leader的端口}
maxClientCnxns:对于一个客户端的连接数限制,默认是
60
,这在大部分时候是足够了。但是在我们实际使用中发现,在测试环境经常超过这个数,经过调查发现有的团队将几十个应用全部部署到一台机器上,以方便测试,于是这个数字就超过了。
修改zoo.cfg非常简单,然后还需要创建myid文件:
cd server1
echo
1
> myid
然后拷贝server1为server2和server3,并修改其中的zoo.cfg配置,当然也要修改myid的内容为
2
和
3
。
下面给出
3
个server的zoo.cfg 内容:
# server1
tickTime=
2000
initLimit=
5
syncLimit=
2
dataDir=/opt/zookeeper/server1/data
dataLogDir=/opt/zookeeper/server1/dataLog
clientPort=
2181
server.
1
=vm-10-112-29-177
:
2888
:
3888
server.
2
=vm-10-112-29-172
:
2888
:
3888
server.
3
=vm-10-112-29-174
:
2888
:
3888
标签:
原文地址:http://www.cnblogs.com/8899man/p/5743710.html