Zookeeper在Centos7上安装

84 阅读3分钟

准备工作

  • 准备3台虚拟机
  • jdk检测
[root@localhost ~]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
  • 防火墙检测

[root@localhost ~]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2019-06-28 04:37:57 EDT; 6 days ago
    Docs: man:firewalld(1)

[root@localhost ~]# service firewalld stop
    Redirecting to /bin/systemctl stop firewalld.service

[root@localhost ~]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
    Active: inactive (dead) since Thu 2019-07-04 08:04:47 EDT; 26s ago
    Docs: man:firewalld(1)
    Process: 687 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
    Main PID: 687 (code=exited, status=0/SUCCESS)
  • 创建用户
[root@localhost ~]# adduser hadoop
[root@localhost ~]# 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.
[root@localhost ~]# su hadoop
[hadoop@localhost root]$ cd 
[hadoop@localhost ~]$ mkdir soft
[hadoop@localhost ~]$ ll
total 0
drwxrwxr-x. 2 hadoop hadoop 6 Jul  4 08:08 soft

修改主机名和IP的映射关系

[root@localhost ~]# vi /etc/hostname 
[root@localhost ~]# vi /etc/hosts
[root@localhost ~]# cat /etc/hostname 
hadoop18
[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 hadoop18
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 hadoop18
18.2.196.18 hadoop

上传

上传用工具。

解压

su hadoop
[hadoop@localhost soft]$ tar -zxvf zookeeper-3.4.14.tar.gz 

重命名****

[hadoop@localhost soft]$ mv zookeeper-3.4.14 zookeeper

修改环境变量

  • 切换用户到root)并修改配置文件profile
[hadoop@localhost zookeeper]$ su -
Password: 
Last login: Thu Jul  4 08:27:17 EDT 2019 on pts/2
[root@localhost ~]# vi /etc/profile
export ZOOKEEPER_HOME=/home/hadoop/soft/zookeeper
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
  • 重新编译文件,修改完成后切换回hadoop用户
[root@localhost ~]# source /etc/profile
[root@localhost ~]# su hadoop
[hadoop@localhost root]$ 

注意:3台zookeeper都需要修改

修改配置文件

[hadoop@localhost ~]$ cd soft/zookeeper/conf/
[hadoop@localhost conf]$ cp zoo_sample.cfg zoo.cfg
[hadoop@localhost conf]$ 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=/tmp/zookeeper
# 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
minSessionTimeout=4000
maxSessionTimeout=10000
initLimit=5
syncLimit=2

#
# 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
dataDir=/home/hadoop/soft/zookeeper/data              
dataLogDir=/home/hadoop/soft/zookeeper/log
server.1=10.2.196.18:2888:3888
server.2=10.2.196.19:2888:3888
server.3=10.2.196.20:2888:3888
  • tickTime:发送心跳的间隔时间,以毫秒为单位。这个时间是作为zookeeper服务器与服务器之间或客户端与服务器之间维持心跳的事件间隔。也就是每隔tickTime发送一个心跳。
  • dataDir:存储内存中数据快照的位置,就是zookeeper保存数据的目录。默认情况下,zookeeper将写数据的日志文件也保存在这个位置。
  • clientPort:客户端连接zookeeper服务器的端口,zookeeper会监听该端口,接受客户端的访问请求。
  • initLimit:用来配置zookeeper接受客户端初始化连接时最长能忍受多少个心跳时间间隔,当超过10个心跳时间(也就是tickTime)长度后,zookeeper服务器还没有收到客户端的返回信息,则认为该客户端连接失败。总的时间长度就是10 * 2000=20秒(默认情况下)。
  • syncLimit:leader与follower之间发送消息,请求和应答时间长度,最长不能超过多少个tickTime的时间长度,总的时间长度就是5 * 2000=10秒(默认情况下)。
  • server.A=B:C:D:A表示这个是第几号服务器,B表示该服务器的ip地址,C表示该服务器与集群中的leader服务器蒋欢信息的端口,D表示如果集群中的leader服务器挂了,则通过该端口进行选举,选出一个新的leader。
server.1=hadoop18:2888:3888 (主机名, 心跳端口、数据端口)

创建文件夹:

[hadoop@localhost zookeeper]$ mkdir -m 755 data
[hadoop@localhost zookeeper]$ mkdir -m 755 log

在data文件夹下新建myid文件,myid的文件内容为:

[hadoop@localhost zookeeper]$ cd data
[hadoop@localhost data]$ vi myid

添加内容:

1

将集群下发到其他机器上

scp -r /home/hadoop/soft/zookeeper hadoop@hadoop19:/home/hadoop/soft/
scp -r /home/hadoop/soft/zookeeper hadoop@hadoop20:/home/hadoop/soft/

修改其他机器的配置文件

到hadoop19上:修改myid为:2 ,到hadoop20上:修改myid为:3

启动(每台机器)

zkServer.sh start

查看集群状态

jps
zkServer.sh status
[hadoop@hadoop20 zookeeper]$ ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/soft/zookeeper/bin/../conf/zoo.cfg
Mode: leader