高可用的zookeeper

Install zookeeperhtml

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

 修改配置文件java

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

  

一、安裝apache

yum install cshvim

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

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’ 文件上加上了一句:ide

csh -cf '/command/svscanboot &'ui

啓用:this


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

檢查服務是否啓動:rest

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

  

使機器重啓後生效:code

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
相關文章
相關標籤/搜索