高可用的zookeeper

Install zookeeper

wget  http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
tar -zxvf zookeeper-3.4.13.tar.gz
mv zookeeper-3.4.13 /usr/local/
useradd zookeeper
chown -R zookeeper.zookeeper /usr/local/zookeeper-3.4.13



cd /usr/local/zookeeper-3.4.13/conf/
cp zoo_sample.cfg zoo.cfg

ln -sf /usr/local/zookeeper-3.4.13/conf/zoo.cfg /etc/zookeeper/

mkdir -p /var/lib/zookeeper
chown -R zookeeper:zookeeper /var/lib/zookeeper

 用来标识主机
echo 1 > /var/lib/zookeeper/myid
echo 2 > /var/lib/zookeeper/myid 
echo 3 > /var/lib/zookeeper/myid

 修改配置文件

vi /etc/zookeeper/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
dataDir=/var/lib/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
maxClientCnxns=0
#
# 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

server.1=hd03.bitauto.com:2888:3888
server.2=hd04.bitauto.com:2888:3888
server.3=hd12.bitauto.com:2888:3888

 

172.17.2.146 hd01.bitauto.com hd01
172.17.2.147 hd02.bitauto.com hd02
172.17.2.148 hd03.bitauto.com hd03
172.17.2.149 hd04.bitauto.com hd04
172.17.2.150 hd05.bitauto.com hd05
172.17.2.249 hd06.bitauto.com hd06
172.17.2.250 hd07.bitauto.com hd07
172.17.2.105 hd08.bitauto.com hd08
172.17.2.33 hd09.bitauto.com hd09
172.17.2.21 hd10.bitauto.com hd10
172.17.2.22 hd11.bitauto.com hd11
172.17.2.23 hd12.bitauto.com hd12
172.17.2.24 hd13.bitauto.com hd13

  

1、安装

yum install csh

http://cr.yp.to/daemontools/daemontools-0.76.tar.gz下载

yum install gcc tcsh # gcc, csh 要求
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
tar -zxf daemontools-0.76.tar.gz
cd admin
mv daemontools-0.76 /var/lib/ # 非常重要, 安装完成后不能删除: /var/lib/daemontools-0.76
chown root:root -R /var/lib/daemontools-0.76
chmod 755 /var/lib/daemontools-0.76
cd /var/lib/daemontools-0.76/ # 必须进入此目录才能编译
./package/install
sed -i '$acsh -cf \x27\/command\/svscanboot &\x27' /etc/rc.d/rc.local

 

最后一句命令是在 ‘/etc/rc.d/rc.local’ 文件上加上了一句:

csh -cf '/command/svscanboot &'

启用:


sh /etc/rc.local
systemctl start rc-local

检查服务是否启动:

ps -ef|grep svscanboot
root     13716     1  0 04:44 pts/1    00:00:00 /bin/sh /command/svscanboot
 

  

使机器重启后生效:

chmod +x /etc/rc.d/rc.local                              # 必须有,否则重启不能启动 svscanboot 服务

 

如果你的glibc库比较新,此时你很可能会遇到下面错误:

/usr/bin/ld: errno:
TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference in envdir.o
/lib/libc.so.6: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [envdir] Error 1
Copying commands into ./command...
cp: cannot stat `compile/svscan': No such file or directory

为了解决这个问题,接着上面的安装步骤继续:

cd src
wget http://www.qmail.org/moni.csi.hu/pub/glibc-2.3.1/daemontools-0.76.errno.patch
patch < daemontools-0.76.errno.patch
cd ..
package/install

通过ps -ef | grep svscan 来确认安装是否成功

然后添加监视进程

1 cd /service/

2  mkdir zookeeper

3 vim run 

4 填写内容为

#!/bin/bash
exec 2>&1
exec /usr/local/zookeeper-3.4.13/bin/zkServer.sh  start
date

 拥有执行权限

 chmod +x run

 

 

 

 

 

 

 

 

 

 

开机启动  暂时不需要

[root@localhost ~]# vi /etc/init.d/zookeeper 
#! /bin/sh
#
# chkconfig: 2345 90 10
# description: zookeeper daemon

. /etc/init.d/functions

# You will probably want to change only two following lines.
BASEDIR="/usr/local/zookeeper-3.4.9"
USER="zookeeper"

PROG="zookeeper"
CMD="bin/zkServer.sh"
RETVAL=0

start () {
echo -n $"Starting ${PROG}: "
runuser ${USER} -c "cd ${BASEDIR}
${CMD} start > /dev/null &"
echo
}

stop () {
echo -n $"Stopping ${PROG}: "
runuser ${USER} -c "cd ${BASEDIR}
${CMD} stop > /dev/null &"
echo
}

restart () {
stop
start
}


# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status}"
RETVAL=2
;;
esac

exit $RETVAL

# chmod 755 /etc/init.d/zookeeper
# /etc/init.d/zookeeper start
# chkconfig zookeeper on

 

posted @ 2018-11-09 20:49  史红星-shihongxing  阅读(169)  评论(0编辑  收藏  举报