zookeeper集群部署

1.部署环境

1.集群机器配置

node1: 192.168.1.250
node2: 192.168.1.251
node3: 192.168.1.252

2 下载和解压

wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.10.tar.gz
tar -xzvf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10 /usr/local/

3.设置环境变量

vi ~/.bash_profile
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.10
export PATH=$PATH:$ZOOKEEPER_HOME/bin

source ~/.bash_profile

4.配置zoo.conf文件

在${ZOOKEEPER_HOME}/conf目录下 执行

cp zoo_sample.cfg 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.
dataDir=/usr/local/zookeeper-3.4.10/data
# the port at which the clients will connect
clientPort=2181
dataLogDir=/usr/local/zookeeper-3.4.10/log

# The number of snapshots to retain in dataDir
# 这个参数和搭配purgeInterval使用,这个参数指定了需要保留的文件数目。默认是保留3个
autopurge.snapRetainCount=3

# Purge task interval in hours
# Set to "0" to disable auto purge feature
# 这个参数指定了清理频率,单位是小时,需要填写一个1或更大的整数,默认是0,表示不开启自己清理功能。
autopurge.purgeInterval=1

server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888

5.配置myid文件

在 ${ZOOKEEPER_HOME}/data创建myid文件
内容为zoo.conf中主机对应的ID

echo 1 > $ZOOKEEPER_HOME/data/myid

6.将zookeeper-3.3.5文件夹传输到其他机器上

scp -r /usr/local/zookeeper-3.4.10 salve01:/usr/local
scp -r /usr/local/zookeeper-3.4.10 salve02:/usr/local

按照步骤5修改myid文件,并按照步骤4设置每台机器的环境变量

8.启动

依次启动每个机器的zookeeper

/opt/zookeeper-3.4.10/bin/zkServer.sh start

9.验证

运行bin/zkServer.sh status检查启动状况或用jps检查会发现多了QuorumPeerMain进程

注意:zookeeper推荐部署奇数集群。

10.开机启动

vi /usr/lib/systemd/system/zookeeper.service 

内容如下:

[Unit]
Description=zookeeper
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/zookeeper-3.4.10/bin/zkServer.sh start
ExecReload=/usr/local/zookeeper-3.4.10/bin/zkServer.sh restart
ExecStop=/usr/local/zookeeper-3.4.10/bin/zkServer.sh stop

[Install]
WantedBy=multi-user.target

内容说明:

[Unit]:服务的说明
Description:描述服务
After:描述服务类别

[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:启动、重启、停止命令全部要求使用绝对路径

[Install]服务安装的相关设置,可设置为多用户

启动服务:

systemctl enable zookeeper
systemctl start zookeeper

参考:
http://blog.csdn.net/chenxiabinffff/article/details/51374635

你可能感兴趣的:(大数据)