1.1, 准备三台服务器node1,node2,node3.

1.2, [root@liunx local]#yum install -y java #安装java相关

[root@liunx local]#cd /usr/local #进入到目录并下载:

     [root@liunx local]# wget http://mirrors.shu.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

[root@liunx local]#  tar -zxvf zookeeper- 3.4.10.tar.gz

      解压并给Zookeeper做一个软链接 :

       [root@liunx local]# ln -s /usr/local/zookeeper-3.4.10.tar.gz  /usr/local/zookeeper

       [root@liunx local]#cd /usr/local/zookeeper/conf/

     [root@liunx local]#mv zoo_sample.cfg zoo.cfg #重新命名为zoo.cfg

     [root@liunx local]#vim zoo.cfg #编辑zoo.cfg

     zookeeper 集群相关配置实践-LMLPHP

[root@liunx local]#wq #保存退出

      [root@liunx local]#mkdir -p /data/{zk1,zk2,zk3}

[root@liunx local]#echo "1" > /data/zk1/myid #分别给myid写入1,2,3

      [root@liunx local]#echo "2" > /data/zk2/myid

      [root@liunx local]#echo "3" > /data/zk3/myid

      [root@liunx local]#scp -rp /usr/local/zookeeper @192.168.80.130: /usr/local/zookeeper/ #把zookeeper相关配置分别推送到node2,node3服务器上去

[root@liunx local]#scp -rp /data/ @192.168.80.130: /data/ # 把刚建的zk1,zk2,zk3也分别推送到node2,node3服务器

二 ,node2服务器

[root@liunx local2]#cd /usr/local/zookeeper/conf/

[root@liunx local2]#vim zoo.cfg #node2服务器上的内容如下:

    zookeeper 集群相关配置实践-LMLPHP

三,node3服务器

[root@liunx local3]#cd /usr/local/zookeeper/conf/

[root@liunx local3]#vim zoo.cfg #node3服务器上的内容如下:

     zookeeper 集群相关配置实践-LMLPHP

四,zookeeper 启动以及角色查看(其它两台服务器都按以下操作)

[root@liunx local1]#/usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg #启动node1服务器

     [root@liunx local1]#/usr/local/zookeeper/bin/zkServer.sh status /usr/local/zookeeper/conf/zoo.cfg #查看node1  zookeeper 状态

    zookeeper 集群相关配置实践-LMLPHP

[root@liunx local1]#/usr/local/zookeeper/bin/zkCli.sh -server 192.168.80.132:2181 #测试连接node1上的zookeeper集群,出现以下证明一切OK

zookeeper 集群相关配置实践-LMLPHP

      [root@liunx local1]#[root@liunx local1]#/usr/local/zookeeper/bin/zkServer.sh stop /usr/local/zookeeper/conf/zoo.cfg #停止服务

[root@liunx local1]#/usr/local/zookeeper/bin/zkServer.sh restart /usr/local/zookeeper/conf/zoo.cfg #重启

五,总结以及注意事项:

1.1 必须要关闭防火墙否则会出现以下错误:

zookeeper 集群相关配置实践-LMLPHP

[root@liunx local1]#firewall-cmd --state #查看防火墙状态

     [root@liunx local1]#systemctl stop firewalld.service #关闭防火墙

05-08 08:25