zookeeper集羣搭建

1、java環境安裝

1.下載jdk

jdk下載地址下載或者在服務器中用命令下載html

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz

注意,以上jdk-8u191-linux-x64.tar.gz的地址是會變的,因此下載地址須要替換成本身的。java

2.安裝

建立目錄linux

cd /usr/local/
mkdir java
cd java

接着把安裝包上傳到java文件夾中,解壓apache

tar zxvf jdk-8u191-linux-x64.tar.gz

       配置環境變量安全

       vi /etc/profile bash

       在文件的末尾輸入服務器

export JAVA_HOME=/usr/local/java/jdk1.8.0_191
export PATH=$PATH:$JAVA_HOME/bin

這裏注意本身的是否是jdk1.8.0_191cookie

      使環境變量在當前bash中生效oracle

      source /etc/profile socket

 

2、zookeeper安裝

1.下載

zookeeper下載地址下載安裝包

或者命令下載

cd /usr/local
mkdir zookeeper
cd zookeeper
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
tar zxvf zookeeper-3.4.13.tar.gz 

     2.配置

建立data文件夾,打開配置文件

cd zookeeper-3.4.13
mkdir data
cd conf mv zoo_sample.cfg zoo.cfg vi 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/local/zookeeper/zookeeper-1/data
dataLogDir=/usr/local/zookeeper/zookeeper-1/log
# 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 server.1=47.105.232.148:2888:3888 server.2=47.105.232.148:2889:3889 server.3=47.105.232.148:2890:3890
#
# 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

quorumListenOnAllIPs=true

以上紅色的須要注意,由於我用的是一臺服務器,因此三個zookeeper這裏配置應該不一樣,否則會衝突,黃色部分也要確保 server.一、server.2和server.3端口不衝突,若是是三臺服務器的話就不須要了。

這裏還須要注意的是,若是是在雲服務器上部署的,須要配置quorumListenOnAllIPs=true,用以監聽全部網卡,這個和雲服務器的一些虛擬技術有關,不然的話會拋異常

 [myid:0] - ERROR [/47.94.204.115:3888:QuorumCnxManager$Listener@763] - Exception while listening
java.net.BindException: 沒法指定被請求的地址 (Bind failed)
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
        at java.net.ServerSocket.bind(ServerSocket.java:375)
        at java.net.ServerSocket.bind(ServerSocket.java:329)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener.run(QuorumCnxManager.java:742)

另外這裏若是想配置java的一些參數的話,能夠在conf目錄下建立java.env ,例如我這想修改一下java佔用的內存爲100m

# heap size MUST be modified according to cluster environment

export JVMFLAGS="-Xms100m -Xmx100m $JVMFLAGS"

回到zookeeper目錄下

cp -r zookeeper-3.4.13/ zookeeper-1
cp -r zookeeper-3.4.13/ zookeeper-2
cp -r zookeeper-3.4.13/ zookeeper-3

接着依次修改配置文件中 dataDir dataLogDir clientPort

最後記得建立各自的myid

echo "1" > zookeeper-1/data/myid
echo "2" > zookeeper-2/data/myid
echo "3" > zookeeper-4/data/myid

依次啓動

./zookeeper-1/bin/zkServer.sh start
./zookeeper-2/bin/zkServer.sh start
./zookeeper-3/bin/zkServer.sh start

查看是否成功

這個是顯示失敗了,這裏多是配置文件出錯或者有什麼防火牆

我這裏是由於雲主機的安全組給擋住了

修改好以後先關閉

./zookeeper-1/bin/zkServer.sh stop
./zookeeper-2/bin/zkServer.sh stop
./zookeeper-3/bin/zkServer.sh stop

再次啓動,成功

 

相關文章
相關標籤/搜索