ZooKeeper安裝
ZooKeeper單機(jī)安裝
-
官網(wǎng)下載地址
-
環(huán)境
- centos7
- jdk8
-
創(chuàng)建用戶zookeeper
# 創(chuàng)建用戶組 groupadd zookeeper # 創(chuàng)建用戶 useradd -d /home/zookeeper -g zookeeper -G zookeeper -m zookeeper # 創(chuàng)建密碼 passwd zookeeper
-
上傳安裝包并解壓
[zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ ll total 35816 drwxr-xr-x 11 zookeeper zookeeper 4096 Mar 9 11:44 zookeeper-3.4.12 -rwxr-xr-x 1 zookeeper zookeeper 36667596 Mar 9 11:43 zookeeper-3.4.12.tar.gz [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$
-
修改配置文件
# 進(jìn)入配置目錄 cd zookeeper-3.4.12/conf/ # 修改配置文件名 cp zoo_sample.cfg zoo.cfg # 修改配置文件 vi zoo.cfg
# The number of milliseconds of each tick # tickTime:CS通信心跳數(shù) # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔拳氢,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳储耐。tickTime以毫秒為單位。 tickTime=2000 # The number of ticks that the initial # synchronization phase can take # initLimit:LF初始通信時(shí)限 # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)犯助。 initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement # syncLimit:LF同步通信時(shí)限 # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。 syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. # dataDir:數(shù)據(jù)文件目錄 # zookeeper保存數(shù)據(jù)的目錄暑脆,默認(rèn)情況下渠啤,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。 dataDir=/home/zookeeper/software/zookeeper-3.4.12/data # dataLogDir:日志文件目錄 # zookeeper保存日志文件的目錄添吗。 dataLogDir=/home/zookeeper/software/zookeeper-3.4.12/logs # the port at which the clients will connect # clientPort:客戶端連接端口 # 客戶端連接 Zookeeper 服務(wù)器的端口沥曹,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求根资。 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
-
命令匯總
# 啟動(dòng)命令 ./bin/zkServer.sh start # 停止命令 ./bin/zkServer.sh stop # 重啟命令 ./bin/zkServer.sh restart # 狀態(tài)查看命令 ./bin/zkServer.sh status
ZooKeeper集群?jiǎn)螜C(jī)部署
-
部署規(guī)劃
ip client端服務(wù)端口 zk通訊端口 zk選舉端口 127.0.0.1 2181 2887 3887 127.0.0.1 2182 2888 3888 127.0.0.1 2183 2889 3889 -
官網(wǎng)下載地址
-
環(huán)境
- centos7
- jdk8
-
創(chuàng)建用戶zookeeper
# 創(chuàng)建用戶組 groupadd zookeeper # 創(chuàng)建用戶 useradd -d /home/zookeeper -g zookeeper -G zookeeper -m zookeeper # 創(chuàng)建密碼 passwd zookeeper
-
上傳安裝包并解壓三份
[zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ ll total 35824 drwxr-xr-x 10 zookeeper zookeeper 4096 Mar 10 16:56 zk1 drwxr-xr-x 10 zookeeper zookeeper 4096 Mar 10 16:56 zk2 drwxr-xr-x 10 zookeeper zookeeper 4096 Mar 10 16:56 zk3 -rwxr-xr-x 1 zookeeper zookeeper 36667596 Mar 9 11:43 zookeeper-3.4.12.tar.gz [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$
-
創(chuàng)建myid文件
# zk1服務(wù)器 mkdir zk1/data cd zk1/data/
[zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ pwd /home/zookeeper/software/zk1/data [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ # 創(chuàng)建myid文件架专,并寫入內(nèi)容1 [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ cat myid 1 [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ # zk2, zk3服務(wù)器分別創(chuàng)建myid文件,分別寫入2玄帕,3
-
配置文件
# 進(jìn)入配置目錄 cd zk1/conf/ # 修改配置文件名 cp zoo_sample.cfg zoo.cfg
zk1-zoo.cfg
# The number of milliseconds of each tick # tickTime:CS通信心跳數(shù) # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔部脚,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。tickTime以毫秒為單位裤纹。 tickTime=2000 # The number of ticks that the initial # synchronization phase can take # initLimit:LF初始通信時(shí)限 # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)委刘。 initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement # syncLimit:LF同步通信時(shí)限 # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。 syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. # dataDir:數(shù)據(jù)文件目錄 # zookeeper保存數(shù)據(jù)的目錄鹰椒,默認(rèn)情況下锡移,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。 dataDir=/home/zookeeper/software/zk1/data # dataLogDir:日志文件目錄 # zookeeper保存日志文件的目錄漆际。 dataLogDir=/home/zookeeper/software/zk1/logs # the port at which the clients will connect # clientPort:客戶端連接端口 # 客戶端連接 Zookeeper 服務(wù)器的端口淆珊,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求奸汇。 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.myid文件中的值=ip:集群內(nèi)部通訊地址:集群選舉端口 server.1=127.0.0.1:2887:3887 server.2=127.0.0.1:2888:3888 server.3=127.0.0.1:2889:3889
zk2-zoo.cfg
# The number of milliseconds of each tick # tickTime:CS通信心跳數(shù) # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔施符,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。tickTime以毫秒為單位擂找。 tickTime=2000 # The number of ticks that the initial # synchronization phase can take # initLimit:LF初始通信時(shí)限 # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)戳吝。 initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement # syncLimit:LF同步通信時(shí)限 # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。 syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. # dataDir:數(shù)據(jù)文件目錄 # zookeeper保存數(shù)據(jù)的目錄贯涎,默認(rèn)情況下听哭,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。 dataDir=/home/zookeeper/software/zk2/data # dataLogDir:日志文件目錄 # zookeeper保存日志文件的目錄塘雳。 dataLogDir=/home/zookeeper/software/zk2/logs # the port at which the clients will connect # clientPort:客戶端連接端口 # 客戶端連接 Zookeeper 服務(wù)器的端口陆盘,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求败明。 clientPort=2182 # 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.myid文件中的值=ip:集群內(nèi)部通訊地址:集群選舉端口 server.1=127.0.0.1:2887:3887 server.2=127.0.0.1:2888:3888 server.3=127.0.0.1:2889:3889
zk3-zoo.cfg
# The number of milliseconds of each tick # tickTime:CS通信心跳數(shù) # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔礁遣,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。tickTime以毫秒為單位肩刃。 tickTime=2000 # The number of ticks that the initial # synchronization phase can take # initLimit:LF初始通信時(shí)限 # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)。 initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement # syncLimit:LF同步通信時(shí)限 # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。 syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. # dataDir:數(shù)據(jù)文件目錄 # zookeeper保存數(shù)據(jù)的目錄盈包,默認(rèn)情況下沸呐,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。 dataDir=/home/zookeeper/software/zk3/data # dataLogDir:日志文件目錄 # zookeeper保存日志文件的目錄呢燥。 dataLogDir=/home/zookeeper/software/zk3/logs # the port at which the clients will connect # clientPort:客戶端連接端口 # 客戶端連接 Zookeeper 服務(wù)器的端口崭添,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求叛氨。 clientPort=2183 # 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.myid文件中的值=ip:集群內(nèi)部通訊地址:集群選舉端口 server.1=127.0.0.1:2887:3887 server.2=127.0.0.1:2888:3888 server.3=127.0.0.1:2889:3889
-
啟動(dòng)
# zk1 /home/zookeeper/software/zk1/bin/zkServer.sh start # zk2 /home/zookeeper/software/zk2/bin/zkServer.sh start # zk3 /home/zookeeper/software/zk3/bin/zkServer.sh start
-
查看狀態(tài)
# zk1 /home/zookeeper/software/zk1/bin/zkServer.sh status ---------------- ZooKeeper JMX enabled by default Using config: /home/zookeeper/software/zk1/bin/../conf/zoo.cfg Mode: follower ---------------- # zk2 /home/zookeeper/software/zk2/bin/zkServer.sh status ---------------- ZooKeeper JMX enabled by default Using config: /home/zookeeper/software/zk2/bin/../conf/zoo.cfg Mode: leader ---------------- # zk3 /home/zookeeper/software/zk3/bin/zkServer.sh status ---------------- ZooKeeper JMX enabled by default Using config: /home/zookeeper/software/zk3/bin/../conf/zoo.cfg Mode: follower ----------------
?