在主机1中安装clustershell工具
访问网站:http://clustershell.readthedocs.io/en/latest/install.html#red-hat-enterprise-linux-and-CentOS $ yum --enablerepo=extrasinstall epel-release $ yum installclustershell vim-clustershell配置clustershell,建立group
**在/etc/clustersheel目录下建立groups文件** Cd /etc/clustersheel Vi groups kafka: router[1-3] 注:router是主机名的前缀 在主机1中拷贝和解压安装包 -bash-4.1# tar -zxvfzookeeper-3.4.9.tar.gz -bash-4.1# tar -zxvfkafka_2.11-0.8.2.1.tgz 通过clustershell统一拷贝zookeeper和 kafaka的安装包 -bash-4.1# clush -g kafka -c/opt/kafka/ 验证是否拷贝成功 Ls /opt/kafka修改zookeeper的配置文件
-bash-4.1# cp zoo_sample.cfgzoo.cfg 修改每台主机的zoo.cfg中的zoo.cfg文件 增加集群信息 server.1=router1:2888:3888 server.2=router2:2888:3888 server.3=router3:2888:3888 注:2888端口是作为leader与follow间通讯的,3888端口是作为leader选举的。 同步zookeeper的配置文件 -bash-4.1# clush -g kafka -c/opt/kafka/zookeeper-3.4.9/conf/zoo.cfg 创建zookeeper数据目录 -bash-4.1# clush -g kafka mkdir/tmp/zookeeper 在每台机器中建立myid文件 主机1执行 -bash-4.1# echo "1" >/tmp/zookeeper/myid 主机2执行 -bash-4.1# echo "2" >/tmp/zookeeper/myid 主机3执行 -bash-4.1# echo "3" >/tmp/zookeeper/myid 主机1上验证 -bash-4.1# clush -g kafka cat/tmp/zookeeper/myid router2: 2 router3: 3 router1: 1 启动zookeeper集群,在主机1上执行 -bash-4.1# clush -g kafka"/opt/kafka/zookeeper-3.4.9/bin/zkServer.sh start/opt/kafka/zookeeper-3.4.9/conf/zoo.cfg" router3: ZooKeeper JMX enabled by default router3: Using config: /opt/kafka/zookeeper-3.4.9/conf/zoo.cfg router2: ZooKeeper JMX enabled by default router2: Using config: /opt/kafka/zookeeper-3.4.9/conf/zoo.cfg router1: ZooKeeper JMX enabled by default router1: Using config: /opt/kafka/zookeeper-3.4.9/conf/zoo.cfg router3: Starting zookeeper ... STARTED router2: Starting zookeeper ... STARTED router1: Starting zookeeper ... STARTED 参看监听的端口 -bash-4.1# clush -gkafka lsof -i:2181 router3: COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NAME router3: Java 15172root 23u IPv6 111500 0t0 TCP *:eforward (LISTEN) router1: COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NAME router1: java 17708root 23u IPv6 139485 0t0 TCP *:eforward (LISTEN) router2: COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NAME router2: java 16866root 23u IPv6 119179 0t0 TCP *:eforward (LISTEN) -bash-4.1# clush -g kafka lsof -i:2888 router3: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME router3: java 15172 root 27u IPv6 111517 0t0 TCP router3:spcsdlobby (LISTEN) router3: java 15172 root 28u IPv6 111518 0t0 TCP router3:spcsdlobby->router1:49864 (ESTABLISHED) router3: java 15172 root 29u IPv6 111519 0t0 TCP router3:spcsdlobby->router2:60446 (ESTABLISHED) router2: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME router2: java 16866 root 26u IPv6 119190 0t0 TCP router2:60446->router3:spcsdlobby (ESTABLISHED) router1: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME router1: java 17708 root 27u IPv6 139496 0t0 TCP router1:49864->router3:spcsdlobby (ESTABLISHED) -bash-4.1#clush -g kafka lsof -i:3888 router3: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME router3: java 15172 root 24u IPv6 111509 0t0 TCP router3:ciphire-serv (LISTEN) router3: java 15172 root 25u IPv6 111513 0t0 TCP router3:40480->router1:ciphire-serv (ESTABLISHED) router3: java 15172 root 26u IPv6 111515 0t0 TCP router3:35494->router2:ciphire-serv (ESTABLISHED) router1: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME router1: java 17708 root 24u IPv6 139490 0t0 TCP router1:ciphire-serv (LISTEN) router1: java 17708 root 25u IPv6 139494 0t0 TCP router1:ciphire-serv->router2:49233 (ESTABLISHED) router1: java 17708 root 26u IPv6 139495 0t0 TCP router1:ciphire-serv->router3:40480 (ESTABLISHED) router2: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME router2: java 16866 root 24u IPv6 119183 0t0 TCP router2:ciphire-serv (LISTEN) router2: java 16866 root 25u IPv6 119186 0t0 TCP router2:49233->router1:ciphire-serv (ESTABLISHED) router2: java 16866 root 27u IPv6 119188 0t0 TCP router2:ciphire-serv->router3:35494 (ESTABLISHED) #连接第一个主机的zookeeper,建立测试键值进行测试 -bash-4.1# bin/zkCli.sh -server router1 Connecting to router1 [zk: router1(CONNECTED) 8] create/test_install hello Created /test_install [zk: router1(CONNECTED) 9] ls/ [test_install, zookeeper] #连接第二个主机的zookeeper,查看测试键值是否存在 -bash-4.1# bin/zkCli.sh -serverrouter2 Connecting to router2 ls / [test_install, zookeeper]