Installation on the Linux environment zookeeper

1 installation ZooKeeper

zookeeperGeneral recommendations for the odd number ( 2n+1) for quick 投票和选举, just over half of the elected host can
build a pseudo-cluster in the same Linuxinstallation in three ZooKeeperinstances. 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解压后的confcatalog, to zoo_sample.cfggive a copy and the name is zoo.cfgbecause zoo_sample.cfgonly the configuration template, we need to create the template-based zoo.cfg, and zookeeperreally read that zoo.cfgfile
cp zoo_sample.cfg zoo.cfg

1.3 Creating a data directory data

Because the zookeeperneed for temporary data directory because a file is created in the unzipped folder in the folder datadirectory
mkdir data
In addition, it is necessary for each Zookeeperin-app dataadd a file directory myid, inside the definition of each 服务的编号. Numbered requirements 数字, is 正整数you can use 回声命名to quickly define myidfile ,这个文件的名字必须是myid,其他的话回启动失败
echo 1 > myid

1.4 configuration files written Zookeeper

vi /usr/local/solrcloude/zookeeper1/conf/zoo.cfg

  • Modify the datapath of the data directory
  • clientPort=2181Client access port, three zookeeperinstances 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 of Leader服务器ports to exchange information, to determine the host running 是否宕机
    选举端口:if the cluster Leader服务器hung up, used to determine which Zookeeperservice as 主机
    three Zookeeperapplication 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 两个 Zookeeperstart. Start 单一 Zookeeper, unable to provide normal service.

# 启动
zookeeper1/bin/zkServer.sh start
# 查看状态
zookeeper1/bin/zkServer.sh status

1.7 Operating zkClinet

zkCli.shEnter zookeeperthe 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 zookeeperdata 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 Zookeeperbetween a server or a client and server to maintain the heartbeat interval, i.e. every tickTimetime will send a heartbeat.
dataDir: Location storage memory database snapshots, as the name suggests is the Zookeepersave directory data, by default, Zookeeperwill write the log file data is also stored in this directory.
clientPort: This port is the client connection Zookeeperport server Zookeeperlistens to this port, interview the client's request.
initLimit: This configuration item is used to configure Zookeeperaccepts a maximum number of heartbeats number of intervals can live with the client initiates the connection, when more than 10a heartbeat of time (ie tickTimeafter) the length of the Zookeeperserver has not received client information is returned, then the show the client connection fails. The total length of time is 10*2000=20in seconds.
syncLimit: This configuration item identifier Leaderand Followerbetween the message transmission, request and response time length, the number can not exceed the maximum tickTimelength of time, is the total length of time 5*2000=10in seconds

Published 334 original articles · won praise 186 · views 310 000 +

Guess you like

Origin blog.csdn.net/u012060033/article/details/104855291