Zookeeper学习(一、Linux搭建zookeeper)

1.zookeeper单机搭建

  • 下载:wget http://mirrors.shu.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz
  • 解压:tar -zxvf zookeeper-3.4.12.tar.gz
  • 配置文件:在conf目录下删除zoo_sample.cfg文件,创建一个配置文件zoo.cfg
tickTime=2000
dataDir=/usr/local/services/zookeeper/zk/data
dataLogDir=/usr/local/services/zookeeper/zk/dataLog        
clientPort=2181
  •  配置环境变量:在/etc/profile文件中加入如下内容:
export ZOOKEEPER_HOME=/usr/local/services/zookeeper/zk
export PATH=.:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$JAVA_HOME/bin:$PATH
  • 启动:启动:zkServer.sh start;关闭:zkServer.sh stop

2.zookeeper单机伪集群搭建 

在zk目录下新建data_1,data_2,data_3目录,分别新建myid文件,并分别写入1,2,3

在conf目录下新建zoo1.cfg,zoo2.cfg,zoo3.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.
dataDir=/usr/local/services/zookeeper/zk/data_1

# the port at which the clients will connect
clientPort=2181

#the location of the log file
dataLogDir=/usr/local/services/zookeeper/zk/logs_1

server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
# 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.
dataDir=/usr/local/services/zookeeper/zk/data_2

# the port at which the clients will connect
clientPort=2182

#the location of the log file
dataLogDir=/usr/local/services/zookeeper/zk/logs_2

server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
# 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.
dataDir=/usr/local/services/zookeeper/zk/data_3

# the port at which the clients will connect
clientPort=2183

#the location of the log file
dataLogDir=/usr/local/services/zookeeper/zk/logs_3

server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389

依次启动三个服务:

查看状态:

猜你喜欢

转载自blog.csdn.net/qq_33283652/article/details/84317922