linux 中zookeeper集群搭建

安装包放置在 /usr/myapp
cd /usr/myApp/
tar -zxf zookeeper-3.4.9.tar.gz
cd /usr/myApp/zookeeper-3.4.9

1.3 配置
在主目录下创建data和logs两个目录用于存储数据和日志:
cd /usr/myApp/zookeeper-3.4.9
mkdir data
mkdir logs

3.1 conf/zoo.cfg文件修改
三个zookeeper的conf/zoo.cfg修改如下:

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/myapp/zookeeper-3.4.9/data
dataLogDir=/usr/myapp/zookeeper-3.4.9/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

server.1=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888

cd /usr/myApp/zookeeper-3.4.9

机器1echo '1' > data/myid
机器2echo '2' > data/myid
机器3echo '3' > data/myid

进入bin目录,启动、停止、重启分和查看当前节点状态(包括集群中是何角色)别执行:

sh ./zkServer.sh start /usr/myApp/zookeeper-3.4.9/conf/zoo.cfg
./zkServer.sh stop
./zkServer.sh restart
./zkServer.sh status

你可能感兴趣的:(linux 中zookeeper集群搭建)