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

再次启动,成功

 

相关文章
相关标签/搜索