zookeeper集群搭建

一、java环境安装

1.下载jdk

jdk下载地址下载或者在服务器中用命令下载

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的地址是会变的,所以下载地址需要替换成自己的。

2.安装

创建目录

cd /usr/local/
mkdir java
cd java

接着把安装包上传到java文件夹中,解压

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

       配置环境变量

       vi /etc/profile 

       在文件的末尾输入

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

这里注意自己的是不是jdk1.8.0_191

      使环境变量在当前bash中生效

      source /etc/profile 

 

二、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.1、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

再次启动,成功

 

 

 

posted @ 2018-12-19 11:57  奋斗的菜鸡  阅读(2383)  评论(0编辑  收藏  举报