zookeeper configuration information and tool learning

 

 

 

1. Delete log method and snapshot file method

 

1" Automatically delete the day function

 

java -Djava.ext.dirs=lib org.apache.zookeeper.server.PurgeTxnLog log_path snap_path -n 10

 

log_path: the path of the log

 

snap_path: data snapshot path

 

Where -n indicates how many files to keep, not less than 3. This example indicates 10 pieces of data

 

Lib : indicates the path to the jar package library

 

Example:

 

java -Djava.ext.dirs=lib org.apache.zookeeper.server.PurgeTxnLog /usr/zookeeper-3.4.6_2/data /usr/zookeeper-3.4.6_2/logs -n

 

2" Write a script to delete log and snapshot data

 

We deleteLogAndSnapshot.sh

 

#!/bin/bash
#snapshot file dir
dataDir=/usr/zookeeper/data/snapshot/version-2
#tran log dir
dataLogDir=/usr/zookeeper/log/snapshot/version-2
#zk log dir
#Leave 10 files
count=10
count=$[$count+1]
ls -t $dataLogDir/log.* | tail -n +$count | xargs rm -f
ls -t $dataDir/snapshot.* | tail -n +$count | xargs rm -f
加入定时任务:

 

crontab –e

 

2 2 * * * /usr/zookeeper/bin/deleteLogAndSnapshot.sh > /dev/null 2>&1

 

cron file syntax:

 

Hourly day, month and week command

 

0-59 0-23 1-31 1-12 0-6 command

 

The cron service provides the crontab command to set the cron service. The following are some parameters and descriptions of this command:

 

crontab -u //Set a user's cron service, generally root users need this parameter when executing this command
  crontab -l //List the details of a user's cron service
  crontab -r //Delete no user cron service
  crontab -e //edit a user's cron service
  For example, root to view his own cron settings: crontab -u root -l
  Another example, root wants to delete fred's cron settings: crontab -u fred -r
  is editing cron When serving, the edited content has some formats and conventions, enter: crontab -u root -e

 

3" Starting from 3.4.0, zookeeper provides the function of automatically cleaning snapshots and transaction logs in zoo.cfg, which can be cleaned regularly by configuring the two parameters autopurge.snapRetainCount and autopurge.purgeInterval. These two parameters are configured in zoo.cfg:
autopurge.purgeInterval This parameter specifies the cleaning frequency in hours. It needs to fill in an integer of 1 or greater. The default is 0, which means that the self-cleaning function is not enabled.
The autopurge.snapRetainCount parameter is used in conjunction with the above parameter, this parameter specifies the number of files to retain. The default is to keep 3.

 

2. Set the zookeeper memory

 

zookeeper/bin/zkEnv.sh

 

When installing, there is no java.env file in this path, you need to create a new one yourself:

vi java.env

The contents of the java.env file are as follows:

 

#!/bin/sh

export JAVA_HOME=/usr/java/jdk

# heap size MUST be modified according to cluster environment

export JVMFLAGS="-Xms512m -Xmx1024m $JVMFLAGS"

For memory allocation, it depends on the project and machine conditions. If the memory is sufficient, an appropriate size can improve the performance of zk

 

3. zookeeper command

 

Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

 

 

 

4. zookeeper view log command

 

java -classpath .:slf4j-api-1.6.1.jar:zookeeper-3.4.9.jar  org.apache.zookeeper.server.LogFormatter   ../Data/datalog/version-2/log.1

 

into lib

 

java -classpath .:slf4j-api-1.6.1.jar:zookeeper-3.4.6.jar  org.apache.zookeeper.server.LogFormatter   ../logs/version-2/log.dc81

 

5. Zoo.cfg parameter description:

 

 

 

# 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=/usr/zookeeper-3.4.6_2/data

 

### log file 保存日志文件

 

dataLogDir=/usr/zookeeper-3.4.6_2/logs

 

# 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  保留快照文件个数 默认3

 

autopurge.snapRetainCount=3

 

# Purge task interval in hours

 

# Set to "0" to disable auto purge feature 1小时清理一下日志

 

autopurge.purgeInterval=1

 

 

 

#2888,3888 are election port 设置集群通讯

 

 

 

#server.1=192.168.90.107:2889:3881

 

#server.2=192.168.6.24:2890:3882

 

 

 

#其中,

 

#2888 端口号是 zookeeper 服务之间通信的端口。

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326504968&siteId=291194637