Zookeeper 3.4.x安装和配置--Linux篇

阅读目录:

1. 关闭防火墙和Selinux

2. 安装所需环境JDK

3. 下载Zookeeper 3.4.x版本

4. 配置并启动Zookeeper

5. 验证并配置自启动

6. 说明

1. 关闭防火墙和Selinux

        Linux的防火墙是咱们新手的噩梦,很多情况会出现能ping通,但是访问不了Web页面。所以开始就干掉它!

    1.1 关闭防火墙

    [root@localhost ~]# /etc/init.d/iptables stop
    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    iptables: Flushing firewall rules:                         [  OK  ]
    iptables: Unloading modules:                               [  OK  ]

    1.2 开机自动关闭防火墙

    [root@localhost ~]# chkconfig iptables off

    1.3 查看Selinux状态

    [root@localhost ~]# sestatus
    SELinux status: enabled 
    SELinuxfs mount: /sys/fs/selinux 
    SELinux root directory: /etc/selinux 
    Loaded policy name: targeted 
    Current mode: enforcing 
    Mode from config file: enforcing 
    Policy MLS status: enabled 
    Policy deny_unknown status: allowed 
    Max kernel policy version: 28

    1.4 关闭selinux

    [root@localhost ~]# vim /etc/selinux/config 

修改 SELINUX=disabled 
注:永久开启->改成:SELINUX=enforcing

2. 安装所需环境JDK

    直接参考本文:https://my.oschina.net/u/3209432/blog/1576928

3. 下载Zookeeper 3.4.x版本

    注:创建两个目录存放log日志和data数据

    [root@localhost /]# mkdir /usr/local/zookeeper
    [root@localhost /]# mkdir /usr/local/zookeeper/data
    [root@localhost /]# mkdir /usr/local/zookeeper/dataLog

    3.1 下载Zookeeper 3.4.x

    [root@localhost /]# cd /usr/local/zookeeper
    [root@localhost zookeeper]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz

    3.2 解压

    [root@localhost zookeeper]# tar -zxvf zookeeper-3.4.11.tar.gz

4. 配置并启动Zookeeper

    4.1 进入Zookeeper 3.4.x 的配置文件夹

    [root@localhost zookeeper]# cd /usr/local/zookeeper/zookeeper-3.4.11/conf

    4.2 备份配置文件(做修改用)

    [root@localhost conf]# mv zoo_sample.cfg zoo.cfg

    4.3 修改配置文件zoo.cfg

    [root@localhost conf]# vim zoo.cfg

    增加标红的两行

# The number of ticks that can pass between 
# 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 
# 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
#
# 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=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/dataLog

    4.4 配置zookeeper环境变量

    [root@localhost conf]# vim /etc/profile

    在文本末最后一行添加如下代码:

export ZOOKEEPER_HOME=/usr/local/zookeeper/zookeeper-3.4.11

export PATH=$ZOOKEEPER_HOME/bin:$PATH

保存退出。

    4.5 使配置立即生效

    [root@localhost conf]# source /etc/profile

    4.6 启动Zookeeper

    [root@localhost conf]# /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh start 
    ZooKeeper JMX enabled by default
    Using config: /usr/local/zookeeper/zookeeper-3.4.11/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED

5. 验证并配置自启动

    5.1 验证

    [root@localhost conf]# /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /usr/local/zookeeper/zookeeper-3.4.11/bin/../conf/zoo.cfg
    Mode: standalone

    5.2 创建编辑自启动文件

    [root@localhost conf]# vim /etc/rc.d/init.d/zookeeper

#!/bin/bash  
##chkconfig:2345 20 90  
#description:zookeeper  
#processname:zookeeper  
export JAVA_HOME=/usr/java/jdk1.8.0_144
case $1 in
        start) su root /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh start;;
        stop) su root /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh stop;;
        status) su root /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh status;;
        restart) su /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh restart;;
        *) echo "require start|stop|status|restart" ;;
esac

    5.3 授予文件权限

    [root@localhost conf]# chmod +x /etc/rc.d/init.d/zookeeper

6. 说明

    说明:本次使用

       操作系统:CentOS 6.8 64位

       Zookeeper版本:3.4.11

    注:如遇到下载链接失效,可以尝试访问:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper

猜你喜欢

转载自my.oschina.net/u/3209432/blog/1626469