1. 關閉防火牆和Selinux
2. 安裝所需環境JDK
3. 下載Zookeeper 3.4.x版本
4. 配置並啓動Zookeeper
5. 驗證並配置自啓動
6. 說明
Linux的防火牆是我們新手的噩夢,不少狀況會出現能ping通,可是訪問不了Web頁面。因此開始就幹掉它!html
1.1 關閉防火牆java
[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 開機自動關閉防火牆linux
[root@localhost ~]# chkconfig iptables off
1.3 查看Selinux狀態apache
[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 關閉selinuxvim
[root@localhost ~]# vim /etc/selinux/config
修改 SELINUX=disabled
注:永久開啓->改爲:SELINUX=enforcingbash
直接參考本文:http://www.javashuo.com/article/p-mdxsfevn-bw.htmlide
注:建立兩個目錄存放log日誌和data數據ui
[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.xthis
[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 解壓spa
[root@localhost zookeeper]# tar -zxvf zookeeper-3.4.11.tar.gz
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=1dataDir=/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.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 10 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
5.4 添加到開機自啓
[root@localhost conf]# cd /etc/rc.d/init.d/ [root@localhost conf]# chkconfig --add zookeeper
說明:本次使用
操做系統:CentOS 6.8 64位
Zookeeper版本:3.4.11
注:如遇到下載連接失效,能夠嘗試訪問:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper