3.Zookeeper安装配置
一、主机配置
(一)创建hadoop用户
说明:由于目标端hadoop集群已创建,无需再次创建此用户。
[root@s142133 ~]# useradd -m hadoop -s /bin/bash
[root@s142133 ~]# id hadoop uid=54322(hadoop) gid=54331(hadoop) groups=54331(hadoop) [root@s142133 ~]# passwd hadoop Changing password for user hadoop. New password: BAD PASSWORD: The password is shorter than 8 characters
Retype new password: passwd: all authentication tokens updated successfully.
(二)安装Java环境
Java环境可选择Oracle 的JDK,或是OpenJDK,现在一般Linux系统默认安装的基本是OpenJDK,如RedHat7.4 默认安装了OpenJDK 1.8,如下:
[hadoop@s142133 ~]$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[hadoop@s142133 ~]$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
1.JDK下载安装
自行下载jdk安装包,手动安装JDK1.8:
[hadoop@s142133 ~]$ ls -ltr jdk-8u221-linux-x64.tar.gz -rw-r--r-- 1 oracle oinstall 153530841 Aug 12 10:38 jdk-8u221-linux-x64.tar.gz [hadoop@s142133 ~]$ tar -xvf jdk-8u221-linux-x64.tar.gz [hadoop@s142133 ~]$ mv jdk1.8.0_221 jdk8
2.配置环境变量
export JAVA_HOME=/home/hadoop/jdk8 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH export PATH=$JAVA_HOME/bin:$PATH
3.检验JDK信息
[hadoop@s142133 ~]$ source .bash_profile [hadoop@s142133 ~]$ java -version java version "1.8.0_221" Java(TM) SE Runtime Environment (build 1.8.0_221-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
二、Zookeeper安装及配置
说明:在一台机器上模拟3个 zk server的集群安装。
(一)下载并解压软件
说明:解压到3个目录
[hadoop@s142133 ~]$ ls -ltr zookeeper-3.4.6.tar.gz -rw-r--r-- 1 hadoop hadoop 17699306 Feb 25 2016 zookeeper-3.4.6.tar.gz [hadoop@s142133 ~]$ tar -xvf zookeeper-3.4.6.tar.gz [hadoop@s142133 ~]$ mkdir zookeeper [hadoop@s142133 ~]$ mv zookeeper-3.4.6 zookeeper/zookeeper-1 [hadoop@s142133 ~]$ cp -r zookeeper/zookeeper-1 zookeeper/zookeeper-2 [hadoop@s142133 ~]$ cp -r zookeeper/zookeeper-1 zookeeper/zookeeper-3 [hadoop@s142133 ~]$ ls -ltr zookeeper/ total 12 drwxr-xr-x 10 hadoop hadoop 4096 Feb 20 2014 zookeeper-1 drwxr-xr-x 10 hadoop hadoop 4096 Aug 17 00:55 zookeeper-2 drwxr-xr-x 10 hadoop hadoop 4096 Aug 17 00:55 zookeeper-3
(二)修改配置文件
注意:clientPort分别设置为2181、2182、2183
1.zk节点1配置
[hadoop@s142133 ~]$ vi /home/hadoop/zookeeper/zookeeper-1/conf/zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/home/hadoop/zookeeper/zookeeper-1/data dataLogDir=/home/hadoop/zookeeper/zookeeper-1/log clientPort=2181 server.1=localhost:2287:3387 server.2=localhost:2288:3388 server.3=localhost:2289:3389
2.zk节点2配置
[hadoop@s142133 ~]$ vi /home/hadoop/zookeeper/zookeeper-2/conf/zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/home/hadoop/zookeeper/zookeeper-2/data dataLogDir=/home/hadoop/zookeeper/zookeeper-2/log clientPort=2182 server.1=localhost:2287:3387 server.2=localhost:2288:3388 server.3=localhost:2289:3389
3.zk节点3配置
[hadoop@s142133 ~]$ vi /home/hadoop/zookeeper/zookeeper-3/conf/zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/home/hadoop/zookeeper/zookeeper-3/data dataLogDir=/home/hadoop/zookeeper/zookeeper-3/log clientPort=2183 server.1=localhost:2287:3387 server.2=localhost:2288:3388 server.3=localhost:2289:3389
(三)创建数据、日志目录
手动创建dataDir、dataLogDir对应的目录,3个节点都需创建。
1.zk节点1创建目录
[hadoop@s142133 ~]$ mkdir -p /home/hadoop/zookeeper/zookeeper-1/data [hadoop@s142133 ~]$ mkdir -p /home/hadoop/zookeeper/zookeeper-1/log
2.zk节点2创建目录
[hadoop@s142133 ~]$ mkdir -p /home/hadoop/zookeeper/zookeeper-2/data [hadoop@s142133 ~]$ mkdir -p /home/hadoop/zookeeper/zookeeper-2/log
3.zk节点3创建目录
[hadoop@s142133 ~]$ mkdir -p /home/hadoop/zookeeper/zookeeper-3/data [hadoop@s142133 ~]$ mkdir -p /home/hadoop/zookeeper/zookeeper-3/log
(四)创建myid文件
说明:在每个zk server配置文件的dataDir对应的目录下,创建一个名为myid的文件,其中的内容必须与zoo.cfg中server.x 中的x相同,即:
/home/hadoop/zookeeper/zookeeper-1/data/myid 中的内容为1,对应server.1中的1
[hadoop@s142133 ~]$ cat /home/hadoop/zookeeper/zookeeper-1/data/myid 1
/home/hadoop/zookeeper/zookeeper-2/data/myid 中的内容为2,对应server.2中的2
[hadoop@s142133 ~]$ cat /home/hadoop/zookeeper/zookeeper-2/data/myid 2
/home/hadoop/zookeeper/zookeeper-3/data/myid 中的内容为3,对应server.3中的3
[hadoop@s142133 ~]$ cat /home/hadoop/zookeeper/zookeeper-3/data/myid 3
(五)启动zookeeper集群
[hadoop@s142133 ~]$ /home/hadoop/zookeeper/zookeeper-1/bin/zkServer.sh start JMX enabled by default Using config: /home/hadoop/zookeeper/zookeeper-1/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@s142133 ~]$ /home/hadoop/zookeeper/zookeeper-2/bin/zkServer.sh start JMX enabled by default Using config: /home/hadoop/zookeeper/zookeeper-2/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@s142133 ~]$ /home/hadoop/zookeeper/zookeeper-3/bin/zkServer.sh start JMX enabled by default Using config: /home/hadoop/zookeeper/zookeeper-3/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
(六)zookeeper测试
1.启动客户端
[hadoop@s142133 ~]$ /home/hadoop/zookeeper/zookeeper-1/bin/zkCli.sh -server localhost:2181 Connecting to localhost:2181 2019-08-17 01:08:30,807 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT 2019-08-17 01:08:30,816 [myid:] - INFO [main:Environment@100] - Client environment:host.name=s142133 2019-08-17 01:08:30,816 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_221 2019-08-17 01:08:30,819 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2019-08-17 01:08:30,819 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/home/hadoop/jdk8/jre 2019-08-17 01:08:30,819 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/home/hadoop/zookeeper/zookeeper-1/bin/../build/classes:/home/hadoop/zookeeper/zookeeper-1/bin/../build/lib/*.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../lib/slf4j-api-1.6.1.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../lib/netty-3.7.0.Final.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../lib/log4j-1.2.16.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../lib/jline-0.9.94.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../zookeeper-3.4.6.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../src/java/lib/*.jar:/home/hadoop/zookeeper/zookeeper-1/bin/../conf:.:/home/hadoop/jdk8/lib/dt.jar:/home/hadoop/jdk8/lib/tools.jar 2019-08-17 01:08:30,820 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/home/hadoop/jdk8/jre/lib/amd64/server:/home/hadoop/jdk8/jre/lib/amd64:/home/hadoop/jdk8/jre/../lib/amd64::/home/hadoop/jdk8/jre/lib/amd64/libjsig.so:/home/hadoop/jdk8/jre/lib/amd64/server/libjvm.so:/home/hadoop/jdk8/jre/lib/amd64/server:/home/hadoop/jdk8/jre/lib/amd64:/bigdata/ogg:/lib:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2019-08-17 01:08:30,820 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2019-08-17 01:08:30,820 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2019-08-17 01:08:30,820 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2019-08-17 01:08:30,820 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2019-08-17 01:08:30,820 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-693.el7.x86_64 2019-08-17 01:08:30,821 [myid:] - INFO [main:Environment@100] - Client environment:user.name=hadoop 2019-08-17 01:08:30,821 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/hadoop 2019-08-17 01:08:30,821 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/hadoop/zookeeper/zookeeper-1/bin 2019-08-17 01:08:30,823 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@421faab1 Welcome to ZooKeeper! JLine support is enabled 2019-08-17 01:08:30,959 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 2019-08-17 01:08:31,191 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2019-08-17 01:08:31,304 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x16c9b6514ad0000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0]
2.状态验证
[zk: localhost:2181(CONNECTED) 0]表示正常启动。
作者:小丁有只猫
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平有限,不足和错误之处在所难免,希望大家能够批评指出。