安装zookeeper之前先安装java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
tar -xf jdk-8u231-linux-x64. tar .gz -C /usr/local/ cd /usr/local/ ln -sv jdk1.8.0_231/ jdk cat > /etc/profile .d /java .sh <<EOF export JAVA_HOME= /usr/local/jdk export JRE_HOME=\$JAVA_HOME /jre export CLASSPATH=.:\$JAVA_HOME /lib/dt .jar:\$JAVA_HOME /lib/tools .jar:\$JRE_HOME /lib export PATH=\$PATH:\$JAVA_HOME /bin :\$JRE_HOME /bin EOF . /etc/profile .d /java .sh java -version javac -version |
zookeeper下载地址:
1
|
https: //mirrors .aliyun.com /apache/zookeeper/ |
下载安装包:
1
|
wget https: //mirrors .aliyun.com /apache/zookeeper/zookeeper-3 .4.14 /zookeeper-3 .4.14. tar .gz |
配置DNS解析:
1
2
3
4
5
6
7
|
cat > /etc/hosts <<EOF 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.51 zookeeper1 192.168.0.52 zookeeper2 192.168.0.53 zookeeper3 EOF |
设置主机名:
1
2
3
|
hostnamectl set - hostname zookeeper1 hostnamectl set - hostname zookeeper2 hostnamectl set - hostname zookeeper3 |
配置免秘钥:
1
2
3
|
ssh -copy- id -i . ssh /id_rsa .pub root@zookeeper1 ssh -copy- id -i . ssh /id_rsa .pub root@zookeeper2 ssh -copy- id -i . ssh /id_rsa .pub root@zookeeper3 |
解压安装:
1
2
3
|
tar -xf zookeeper-3.4.14. tar .gz -C /usr/local/ cd /usr/local/ ln -sv zookeeper-3.4.14/ zookeeper |
配置环境变量:
1
2
3
4
5
|
cat > /etc/profile .d /zookeeper .sh <<EOF export ZOOKEEPER_HOME= /usr/local/zookeeper export PATH=\$PATH:\$ZOOKEEPER_HOME /bin EOF . /etc/profile .d /zookeeper .sh |
日志目录:
1
|
mkdir /usr/local/zookeeper/logs |
数据目录:
1
|
mkdir /data/zookeeper -pv |
配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
cat > /usr/local/zookeeper/conf/zoo .cfg <<EOF tickTime=2000 initLimit=10 syncLimit=5 dataDir= /data/zookeeper dataLogDir= /usr/local/zookeeper/logs clientPort=2181 # server.1 这个1是服务器的标识,可以是任意有效数字,标识这是第几个服务器节点,这个标识要写到dataDir目录下面myid文件里 # 指名集群间通讯端口和选举端口 server.1=zookeeper1:2287:3387 server.2=zookeeper2:2287:3387 server.3=zookeeper3:2287:3387 EOF |
数据目录的myid文件的ID号和配置文件中的server.id对应:
1
2
3
4
5
6
|
zookeeper1 echo "1" > /data/zookeeper/myid zookeeper2 echo "2" > /data/zookeeper/myid zookeeper3 echo "3" > /data/zookeeper/myid |
复制配置文件到其他节点:
1
2
|
scp /usr/local/zookeeper/conf/zoo .cfg root@zookeeper2: /usr/local/zookeeper/conf/ scp /usr/local/zookeeper/conf/zoo .cfg root@zookeeper3: /usr/local/zookeeper/conf/ |
使用普通用户启动集群:这里要和hadoop配合使用,一般情况下root即可。
1
2
3
4
5
|
useradd hadoop cd /usr/local/ chown -R hadoop.hadoop zookeeper/ zookeeper chmod g+w /usr/local/zookeeper/logs/ chown -R hadoop.hadoop /data/zookeeper/ |
启动集群:
1
2
|
su hadoop zkServer.sh start |
查看状态:
1
2
3
4
|
~]$ zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/ .. /conf/zoo .cfg Mode: follower |
停止集群:
1
|
zkServer.sh stop |
本文来自博客园,作者:大码王,转载请注明原文链接:https://www.cnblogs.com/huanghanyu/