kafka是制作消息队列的,与redis相似,但是优于redis,支持消息并列与通知,
实验:部署zookeeper集群:
安装思路及环境:先安装Java环境,再安装zookeeper,后安装kafka,:安装思路及环境:先安装Java环境,再安装zookeeper,后安装kafka,
zookeeper版本下载网址: http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
http://zookeeper.apache.org/doc/current/zookeeperStarted.html中有:
server.1=172.18.9.203:2888:3888 server.2=172.18.9.204:2888:3888 server.3=172.18.9.205:2888:3888
制作zookeeper集群需三台服务器:172.18.9.203,172.18.9.204,172.18.9.205
三台服务器分别配置hosts文件:
#cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.18.9.203 linux-host1.exmaple.com
172.18.9.204 linux-host2.exmaple.com
172.18.9.205 linux-host3.exmaple.com
一、安装Java环境:[[email protected]/204/205 src]#yum -y install jdk-8u191-linux-x64.rpm
二、安装zookeeper:[[email protected]/204/205 src]#wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
[[email protected]/204/205 src]#tar xf zookeeper-3.4.14.tar.gz
三、制作zookeeper配置文件:
[[email protected]/204/205 src]#cd zookeeper-3.4.14/conf
[[email protected]/204/205 conf]#ll
total 12
-rw-rw-r--. 1 2002 2002 535 Mar 7 00:50 configuration.xsl
-rw-rw-r--. 1 2002 2002 2161 Mar 7 00:50 log4j.properties
-rw-rw-r--. 1 2002 2002 922 Mar 7 00:50 zoo_sample.cfg
[[email protected]/204/205 conf]#cp zoo_sample.cfg zoo.cfg #把模板cp成配置文件
四、修改配置文件并做软连接并创建数据存放目录:
[[email protected]/204/205 conf]#vim zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/data
clientPort=2181
maxClientCnxns=4096
server.1=172.18.9.203:2888:3888
server.2=172.18.9.204:2888:3888
server.3=172.18.9.205:2888:3888
[[email protected]/204/205 conf]#mkdir /usr/local/zookeeper/data
[[email protected]/204/205 conf]#ln -s /usr/local/src/zookeeper-3.4.14 /usr/local/zookeeper
五、开启并查看状态:[[email protected] conf]#/usr/local/zookeeper/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[[email protected] conf]#/usr/local/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
出现此错的原因是zookeeper的pid没有生成!
六、将server的编号写入myid文件:
[[email protected]/204/205 zookeeper-3.4.14]#echo 1 2 3 > /usr/local/zookeeper/data/myid
[[email protected]/204/205 zookeeper-3.4.14]#
七、重新开启服务并查看端口:
[[email protected]/204/205 zookeeper-3.4.14]#/usr/local/zookeeper/bin/zkServer.sh start
[[email protected]/204/205 zookeeper-3.4.14]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 :::2181 :::*
八、查看集群状态:leader/follower 一目了然:
[[email protected] zookeeper-3.4.14]#/usr/local/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[[email protected] conf]#/usr/local/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[[email protected] conf]#/usr/local/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
九、将开启服务命令写入脚本、令其开机自启:
[[email protected]/204/205 zookeeper-3.4.14]#vim /etc/rc.d/rc.local
/usr/local/zookeeper/bin/zkServer.sh start
此时,zookeeper已完成安装,它没有账号认证,任何普户都能用!
原文地址:https://blog.51cto.com/14128387/2385777