[Hadoop][Zookeeper]Cluster + HA

# ZOOKEEPER 国内安装文件下载地址
# ZOOKEEPER_WEB_FILE=https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

# 是否下载 ZOOKEEPER 安装文件
# wget -P /tmp $ZOOKEEPER_WEB_FILE

# ZOOKEEPER 安装文件
# ZOOKEEPER_INSTALL_FILE=/tmp/zookeeper-3.4.10.tar.gz

# ZOOKEEPER 目录
# ZOOKEEPER_INSTALL_DIR=/opt/zookeeper-3.4.10
# ZOOKEEPER_HOME=/opt/zookeeper

# 安装 ZOOKEEPER
tar -C /opt -xf $ZOOKEEPER_INSTALL_FILE
ln -s $ZOOKEEPER_INSTALL_DIR $ZOOKEEPER_HOME

# 创建组和用户
groupadd zookeeper
useradd -g zookeeper zookeeper -s /sbin/nologin

# 文件存放目录
mkdir -p /mnt/zookeeper/data
mkdir -p /var/log/zookeeper
chown zookeeper:zookeeper -R /mnt/zookeeper/data
chown zookeeper:zookeeper -R /var/log/zookeeper

#创建配置文件
cat <<EOF | tee $ZOOKEEPER_HOME/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/mnt/zookeeper/data
dataLogDir=/var/log/zookeeper
clientPort=2181
server.1=zookeeper01:2888:3888
server.2=zookeeper02:2888:3888
server.3=zookeeper03:2888:3888
EOF

chown zookeeper:zookeeper -R $ZOOKEEPER_INSTALL_DIR
chown zookeeper:zookeeper -R $ZOOKEEPER_LINK_DIR

#systemd开机配置
cat <<EOF | tee /usr/lib/systemd/system/zookeeper.service
[Unit]
Description=zookeeper
After=syslog.target network.target

[Service]
Type=forking
Environment=ZOO_LOG_DIR=/var/log/zookeeper
# Environment=ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
ExecStart=/opt/zookeeper/bin/zkServer.sh start
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
Restart=always
User=zookeeper
Group=zookeeper

[Install]
WantedBy=multi-user.target
EOF

#每台zookeeper的id不一样
# echo "1" > /mnt/zookeeper/data/myid
# echo "2" > /mnt/zookeeper/data/myid
# echo "3" > /mnt/zookeeper/data/myid

systemctl enable zookeeper
systemctl start zookeeper
systemctl status zookeeper

firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=2888/tcp --permanent
firewall-cmd --zone=public --add-port=3888/tcp --permanent
firewall-cmd --reload

#检测是否可用
#echo conf | nc $HOSTNAME 2181

posted @ 2017-05-26 17:07  wuzhenzhou  阅读(184)  评论(0编辑  收藏  举报