zookeeper集群的搭建
(1)准备三台机器
vi /etc/hosts
192.168.33.201 hadoop1
192.168.33.202 hadoop2
192.168.33.203 hadoop3
设置三个机器的本机免密登录(三台机器配置一样):
ssh-keygen -t rsa ---一直回车即可
cd /root/.ssh/ ---生成了公钥和私钥
cat id_rsa.pub >> authorized_keys ---将三台机器的公钥追加到授权文件中,并且分发到三台机器 /root/.ssh/下
more authorized_keys ---可以查看到里面追加的公钥
ssh hadoop2 --- 测试hadoop1 链接hadoop2
这三台机器是在之前安装好常用软件(jdk)配置好环境变量
vi /etc/profile
export JAVA_HOME =/mnt/jdk-1.8.0_60
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
(2)将zookeeper安装包上传到hadoop1的/usr/local中。
lrzsz是一款在linux里可代替ftp上传和下载的程序。
要想使用lrzsz进行上传rz(也可直接鼠标拖拽)和下载sz,则必须安装lrzsz。可以使用yum install lrzsz自动安装,必须有网络。没有网络,可以制作yum本地源。
(3)解压
tar -zxvf /usr/local/zookeeper-3.4.5.tar.gz
mv zookeeper-3.4.5 zookeeper
同时拷贝到其他两台机器上
cd /usr/local
scp -r -P 22 remote_username@remote_ip:/usr/local/zookeeper ./
xshell窗口同时打开三台窗口命令行,一个窗口命令同时在三台机器上执行的方式如下:
xhell工具-》发送键输入到所有会话
(4)修改环境变量
vi /etc/profile
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
刷新环境变量
source /etc/profile
注意:3台机器都要修改
(5)修改配置文件
cd /usr/local/zookeeper/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
添加内容:
dataDir=/usr/local/zookeeper/data (不能放在临时文件夹中,需新建data文件夹)
dataLogDir=/usr/local/zookeeper/log(新建log文件夹,可不要!!!)
server.1=hadoop1:2888:3888 (主机名, 心跳端口、数据端口)
server.2=hadoop2:2888:3888(都是默认端口)
server.3=hadoop3:2888:3888(2888是leader和follow之间通信,3888是投票选举时用的端口)
注意server.后面的数字必须是1开头增加
创建文件夹
mkdir /usr/local/zookeeper/data
mkdir /usr/local/zookeeper/log
在data文件夹中新建myid文件,myid文件的内容为1(一句话创建:echo 1 > myid)
cd data
echo 1 > myid
添加内容对应的机器值如下:
hadoop1 echo 1 > myid
hadoop2 echo 2 > myid
hadoop3 echo 3 > myid
(6)将三台机器的防火墙关闭掉,service iptables stop ,查看service iptables status
启动,在三个节点上分别都要执行命令
cd /usr/local/zk/bin
zkServer.sh start
启动完了之后,在bin目录下多了一个zookeeper.out
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=/usr/local/zookeeper-3.4.9/data
dataLogDir=/usr/local/zookeeper-3.4.9/datalog
# the port at which the clients will connect
clientPort=2181
server.1=hadoop1:2888:3888
server.2=hadoop2:2888:3888
server.3=hadoop3:2888:3888
# the maximum number of client connections.
# increase this if you need to handle more clients
#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
#
# 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=5
autopurge.snapRetainCount=20
autopurge.purgeInterval=5
autopurge.snapRetainCount=20
上面设置的参数表示:间隔5个小时清理一次,log文件保存20个,snapshot快照文件保存20个。若zookeeper启动时超过设置的文件时,就会执行删除文件的操作。