Ubuntu18.04 builds a zookeeper stand-alone cluster

1. Download the installation package

sudo  wget -b http://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz -o /opt/archive/zookeeper.download.log

2. Create data and log directories and modify permissions

# Create 3*2=6 directories at the same time 
sudo
mkdir /data/{zk1,zk2,zk3}/ {data,logs}
# Modify permissions to all
sudo chown -R $USER:$GROUPS /data/{zk1 ,zk2,zk3}

3. Specify myid

echo "1" > /data/zk1/data/myid
echo "2" > /data/zk2/data/myid
echo "3" > /data/zk3/data/myid

4. Copy and modify the configuration file

cp /opt/zk/conf/zoo_sample.cfg /data/zk1/zoo.cfg

5. Configuration file

# The number of milliseconds of each tick
# heartbeat interval
tickTime=2000

# The number of ticks that the initial
# synchronization phase can take
# Heartbeat interval for the initial sync phase
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.
# Directory where snapshots are stored, do not use /tmp directory
dataDir=/data/zk1/data
dataLogDir=/data/zk1/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
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
# autopurge.purgeInterval = 1

# Heartbeat port, data port; after the election is completed, each node opens the data port; only the master node opens the heartbeat port and accepts heartbeat data
# server.N and myid are corresponding
server.1=bogon:2888:3888
server.2=bogon:2889:3889
server.3=bogon:2890:3890

  

6. Batch operation script

for zk in {1,2,3}
do
    myid=/data/zk${zk}/data/myid
    if [ ! -e "$myid" ];then
        echo $zk > $myid
    fi
    zkServer.sh $1 /data/zk${zk}/zoo.cfg
done

Guess you like

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