1. 程式人生 > >Zookeeper學習(一、Linux搭建zookeeper)

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

依次啟動三個服務:

檢視狀態: