zookeeper集群安装
安装jdk
# tar fzx jjdk-8u191-linux-x64.tar.gz -C /opt/module/ # cd /opt/module && ln -sv jdk1.8.0_191/ jdk # vim /etc/profile export JAVA_HOME=/opt/module/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH # source /etc/profile
分发各节点
# ansible node[2..3] -m synchronize -a "src=/data/module/jdk1.8.0_201 dest=/data/module"
安装zookeeper
# tar xfz apache-zookeeper-3.5.5-bin.tar.gz -C /opt/module/ # cd /opt/module/ # ln -sv apache-zookeeper-3.5.5-bin/ zookeeper ‘zookeeper’ -> ‘apache-zookeeper-3.5.5-bin/’ # vim /etc/profile export HADOOP_HOME=/opt/module/hadoop-2.6.0 export JAVA_HOME=/opt/module/jdk export ZOOKEEPER_HOME=/opt/module/zookeeper export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar # source /etc/profile
配置zookeeper
# vim zookeeper/conf/zoo.cfg # 滴答时间,默认是2000毫秒,即2秒。它是zookeeper最小的时间单位 tickTime=2000 #表示用于在从节点与主节点之间建立初始化连接的时间上限 initLimit=10 #表示允许从节点与主节点处于不同步状态的时间上限,和initLimit一样,都是tickTime的倍数 syncLimit=5 # 事务提交日志目录 dataDir=/opt/module/apache-zookeeper-3.5.5-bin/zkTxData # 快照日志目录 dataLogDir=/opt/module/apache-zookeeper-3.5.5-bin/zkSnapshot # 客户端连接端口 clientPort=2181 # 限制连接到 ZooKeeper 的客户端的数量,此配置选项可以用来阻止某些类别的 Dos 攻击。 #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 # 指定了需要保留的文件数目。默认是保留3个。 #autopurge.snapRetainCount=3 # 3.4.0及之后版本,ZK提供了自动清理事务日志和快照文件的功能,这个参数指定了清理频率,单位是小时,需要配置一个 1或更大的整数,默认是0,表示不开启自动清理功能。 #autopurge.purgeInterval=1 #服务器地址遵循 server.X=hostname:peerPort:leaderPort 格式,X为服务器的ID,它必须是一个整数,不过不一定要从 0 开始,也不要求是连续的;hostname服务器的机器名或 IP 地址;peerPort用于节点间通信的 TCP 端口;leaderPort用于首> 领选举的 TCP 端口。 server.1=node1:2888:3888 server.2=node2:2888:3888 server.3=node3:2888:3888
创建日志目录
# mkdir /opt/module/apache-zookeeper-3.5.5-bin/zkTxData # mkdir /opt/module/apache-zookeeper-3.5.5-bin/zkSnapshot
配置免密登录
# ssh-keygen -t rsa -f /root/.ssh/id_rsa -P "" # yum install -y sshpass # for i in node{1..3};do sshpass -p123456 ssh-copy-id -i /root/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" $i;done
分发配置
# ansible node[2..3] -m synchronize -a "src=/opt/module/apache-zookeeper-3.5.5-bin dest=/opt/module/ perms=yes rsync_opts=--exclude=myid "
创建myid文件等
# ansible node[2..3] -m file -a "src=/opt/module/apache-zookeeper-3.5.5-bin state=link dest=/opt/module/zookeeper" # echo 1 > /opt/module/zookeeper/zkTxData/myid # ansible node2 -m shell -a ‘echo 2 > /opt/module/zookeeper/zkTxData/myid‘ # ansible node3 -m shell -a ‘echo 3 > /opt/module/zookeeper/zkTxData/myid‘ # ansible node[2..3] -m synchronize -a "src=/etc/profile dest=/etc" # ansible node[2..3] -m synchronize -a "src=/etc/hosts dest=/etc" # ansible node[2..3] -m shell -a "source /etc/profile"
编写zookeeper启动脚本
# vi /usr/local/bin/zookeeper_manager.sh #!/bin/bash #判断用户是否传参 if [ $# -ne 1 ];then echo "无效参数,用法为: $0 {start|stop|restart|status}" exit fi #获取用户输入的命令 cmd=$1 #定义函数功能 function zookeeperManger(){ case $cmd in start) echo "启动服务" remoteExecution start ;; stop) echo "停止服务" remoteExecution stop ;; restart) echo "重启服务" remoteExecution restart ;; status) echo "查看状态" remoteExecution status ;; *) echo "无效参数,用法为: $0 {start|stop|restart|status}" ;; esac } #定义执行的命令 function remoteExecution(){ for (( i=1 ; i<=3 ; i++ )) ; do tput setaf 2 echo ========== node${i} zkServer.sh $1 ================ tput setaf 9 ssh node${i} "source /etc/profile ; zkServer.sh $1" done } #调用函数 zookeeperManger # 添加权限 # chmod +x /usr/local/bin/zookeeper_manager.sh
启动zookeeper
# zookeeper_manager.sh start 启动服务 ========== node1 zkServer.sh start ================ ZooKeeper JMX enabled by default Using config: /opt/module/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED ========== node2 zkServer.sh start ================ ZooKeeper JMX enabled by default Using config: /opt/module/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED ========== node3 zkServer.sh start ================ ZooKeeper JMX enabled by default Using config: /opt/module/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
相关推荐
airfish000 2020-06-14
OwenJi 2020-05-08
Kafka 2020-09-18
CobingLiu 2020-06-16
iamdll 2020-07-29
deyu 2020-07-27
deyu 2020-07-21
Elmo 2020-07-19
deyu 2020-07-07
ZHANGYONGHAO0 2020-07-05
joynet00 2020-06-26
isHooky 2020-06-25
CobingLiu 2020-06-21
roddex00 2020-06-12
iamdll 2020-06-11
CobingLiu 2020-06-10
MrZhangAdd 2020-06-09
yixietianxia 2020-06-04