zookeeper集群
官方网站:
环境:
CentOS 7.1
zookeeper-3.4.8
jdk-1.8
官方推荐奇数节点,这里以3节点为例
一.安装jdk
略
二.安装zookeeper
1.创建用户
useradd -r -m zookeeper
echo zookeeper:zoo.123|chpasswd
说明:服务启停都由zookeeper用户来操作
2.调整资源限制
cat >/etc/security/limits.d/99-zookeeper-nproc.conf
<<HERE
zookeeper soft fsize
unlimited
zookeeper soft cpu
unlimited
zookeeper soft as
unlimited
zookeeper soft nofile
64000
zookeeper soft nproc
64000
zookeeper hard fsize
unlimited
zookeeper hard cpu
unlimited
zookeeper hard as
unlimited
zookeeper hard nofile
64000
zookeeper hard nproc
64000
HERE
3.安装zookeeper
tar -xvf zookeeper-3.4.8.tar.gz -C /opt/
mv /opt/zookeeper-3.4.8/ /opt/zookeeper
sed -i '/^ZOOBINDIR/c
ZOOBINDIR=/opt/zookeeper/bin' /opt/zookeeper/bin/zkEnv.sh
4.配置环境变量
cat
>/opt/zookeeper/conf/zookeeper-env.sh <<HERE
export JAVA_HOME=/opt/jdk
export
ZOO_LOG_DIR=/opt/zookeeper/logs
export
ZOOPIDFILE=/opt/zookeeper/run/zookeeper_server.pid
HERE
5.sysv
init脚本
cp /opt/zookeeper/src/packages/rpm/init.d/zookeeper
/etc/init.d/
sed -i '/zkEnv.sh/c source
/opt/zookeeper/bin/zkEnv.sh' /etc/init.d/zookeeper
sed -i 's#zkServer.sh#/opt/zookeeper/bin/zkServer.sh#g'
/etc/init.d/zookeeper
chmod +x /etc/init.d/zookeeper
chkconfig zookeeper on
chown -R zookeeper:
/opt/zookeeper
setfacl -R -m zookeeper:rwx
/opt/zookeeper
setfacl -R -m d:zookeeper:rwx
/opt/zookeeper
三.集群配置
1.所有节点
cat >/opt/zookeeper/conf/zoo.cfg <<HERE
tickTime=2000
dataDir=/opt/zookeeper/data
clientPort=2181
initLimit=5
syncLimit=2
server.1=node-a.example.com:2888:3888
server.2=node-b.example.com:2888:3888
server.3=node-c.example.com:2888:3888
HERE
2.myid
node-a节点
mkdir -p
/opt/zookeeper/data
echo 1 >/opt/zookeeper/data/myid
node-b节点
mkdir -p /opt/zookeeper/data
echo 2 >/opt/zookeeper/data/myid
node-c节点
mkdir -p /opt/zookeeper/data
echo 3 >/opt/zookeeper/data/myid
注意:
目前myid的取值范围为1-255,节点的myid在单个集群内必须唯一
如果不指定myid,集群模式下会无法启动,只能以standalone模式运行
四.启动集群
service zookeeper start
或者
/opt/zookeeper/bin/zkServer.sh start
或者
cd /opt/zookeeper
java -cp
zookeeper-3.4.8.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.16.jar:conf
org.apache.zookeeper.server.quorum.QuorumPeerMain
conf/zoo.cfg
提示:如果启动报错,请检查日志及权限
[zookeeper@node-a ~]$ /opt/zookeeper/bin/zkServer.sh
start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[zookeeper@node-a ~]$ /opt/jdk/bin/jps
9607 QuorumPeerMain
9631 Jps
五.测试集群
1.telnet
2.cli_mt
cd /opt/zookeeper/src/c
./configure && make
&& make install
cli_mt node-a.example.com:2181