一、搭建前准备
192.168.1.99 sdw1
192.168.1.98 sdw2
192.168.1.97 sdw3
二、搭建
1、各主机修改/etc/hosts,/etc/hostname文件
/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.1.99 sdw1
192.168.1.98 sdw2
192.168.1.97 sdw3
/etc/hostname
sdw1
重启
2、 各主机安装jdk
# yum install java
3、安装zookeeper
(1)下载安装包
# wget -c https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
# tar xf apache-zookeeper-3.6.2-bin.tar.gz -C /usr/local/
# mv apache-zookeeper-3.6.2-bin zookeeper
(2)修改配置文件
cd /usr/local/zookeeper/conf
cp -r ./zoo_sample.cfg zoo.cfg
cat zoo.cfg | grep -v "^#"
vi zoo.cnf
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
clientPort=2181
server.1=sdw1:2888:3888
server.2=sdw2:2888:3888
server.3=sdw3:2888:3888
scp -r /usr/local/zookeeper/ sdw2:/usr/local/
scp -r /usr/local/zookeeper/ sdw3:/usr/local/
#两主机都运行
mkdir -p /data/zookeeper/data/
vi /data/zookeeper/data/myid
1 //与zoo.cfg配置文件中对应,sdw为server.1,所以该处填写为1
vi /etc/profile
#Zookeeper Environment
export ZK_HOME=/usr/local/zookeeper
export PATH=$PATH:$ZK_HOME/bin
开启zk(注意三个机器都要开启,之后再查看zk状态)
-- 后台启动zk
# zkServer.sh start-- 查看zk状态
# zkServer.sh status-- 前台启动zk并显示具体报错(若启动zk时报错可使用该方式启动排查问题)
# zkServer.sh start-foreground