Article Directory
1 installation ZooKeeper
zookeeper
General recommendations for the odd number ( 2n+1
) for quick 投票和选举
, just over half of the elected host can
build a pseudo-cluster in the same Linux
installation in three ZooKeeper
instances. Use different ports to achieve the same time. Port assigned as follows:
Host computer | Service Port | Voting port | Election port |
---|---|---|---|
192.168.159.130 | 2181 | 2881 | 3881 |
192.168.159.130 | 2182 | 2882 | 3882 |
192.168.159.130 | 2182 | 2882 | 3882 |
1.1 Unzip
tar -zxvf zookeeper
1.2 Copy Profile
In the zookeeper解压后的conf
catalog, to zoo_sample.cfg
give a copy and the name is zoo.cfg
because zoo_sample.cfg
only the configuration template, we need to create the template-based zoo.cfg
, and zookeeper
really read that zoo.cfg
file
cp zoo_sample.cfg zoo.cfg
1.3 Creating a data directory data
Because the zookeeper
need for temporary data directory because a file is created in the unzipped folder in the folder data
directory
mkdir data
In addition, it is necessary for each Zookeeper
in-app data
add a file directory myid
, inside the definition of each 服务的编号
. Numbered requirements 数字
, is 正整数
you can use 回声命名
to quickly define myid
file ,这个文件的名字必须是myid,其他的话回启动失败
echo 1 > myid
1.4 configuration files written Zookeeper
vi /usr/local/solrcloude/zookeeper1/conf/zoo.cfg
- Modify the
data
path of the data directory clientPort=2181
Client access port, threezookeeper
instances not be the same port.
Also you need the following configuration:server.服务的编号=IP:投票端口:选举端口
服务器编号:
Indicates that this is the first few numbers server
投票端口:
is the服务器
cluster ofLeader服务器
ports to exchange information, to determine the host running是否宕机
选举端口:
if the clusterLeader服务器
hung up, used to determine whichZookeeper
service as主机
threeZookeeper
application configurations consistent.
server.1=192.168.120.132:2881:3881
server.2=192.168.120.132:2882:3882
server.3=192.168.120.132:2883:3883
1.5 Copy the same two Zookeeper
cp zookeeper1 zookeeper2 -r
cp zookeeper1 zookeeper3 -r
After the copy, to modifyzoo.cfg
1.6 Test start Zookeeper
To start at least 两个 Zookeeper
start. Start 单一 Zookeeper
, unable to provide normal service.
# 启动
zookeeper1/bin/zkServer.sh start
# 查看状态
zookeeper1/bin/zkServer.sh status
1.7 Operating zkClinet
zkCli.sh
Enter zookeeper
the client
operates according to the command prompt:
- Find (only absolute path):
ls / ls /zookeeper
- Created and assigned:
create /bhz hadoop
- Obtain:
get /bhz
- Set value:
set /bhz baihezhuo
You can see the zookeeper
data consistency of the cluster, create a node has two types: short ( ephemeral
) and lasting ( persistent
)
1.8 zoo.cfg Detailed
tickTime
: Basic events unit to 毫秒
the unit. This is a time Zookeeper
between a server or a client and server to maintain the heartbeat interval, i.e. every tickTime
time will send a heartbeat.
dataDir
: Location storage memory database snapshots, as the name suggests is the Zookeeper
save directory data, by default, Zookeeper
will write the log file data is also stored in this directory.
clientPort
: This port is the client connection Zookeeper
port server Zookeeper
listens to this port, interview the client's request.
initLimit
: This configuration item is used to configure Zookeeper
accepts a maximum number of heartbeats number of intervals can live with the client initiates the connection, when more than 10
a heartbeat of time (ie tickTime
after) the length of the Zookeeper
server has not received client information is returned, then the show the client connection fails. The total length of time is 10*2000=20
in seconds.
syncLimit
: This configuration item identifier Leader
and Follower
between the message transmission, request and response time length, the number can not exceed the maximum tickTime
length of time, is the total length of time 5*2000=10
in seconds