linux 上面 zookeeper 集群(最少3个节点192.168.204.128、192.168.204.129、192.168.204.130)安装
1、创建文件夹/usr/local/zookeeper,并下载zookeeper-3.4.13.tar.gz 至/usr/local/zookeeper中,然后解压,
将解压后的zookeeper-3.4.13文件夹改名为zookeeper
2、在/usr/local/zookeeper/zookeeper/中创建文件夹data和data-log
3、进去文件夹/usr/local/zookeeper/zookeeper/conf中,将文件zoo-sample.cfg文件名统一修改为zoo.cfg。
4、编辑上述文件zoo.cfg,如下,注意其中的dataDir和dataLogDir:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/zookeeper/data
# 事务日志
dataLogDir=/usr/local/zookeeper/zookeeper/data-log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.204.128:2888:3888
server.2=192.168.204.129:2888:3888
server.3=192.168.204.130:2888:3888
5、在data文件夹中创建文件myid,并且编辑myid【命令可使用:创建文件touch myid,编辑文件vim myid】,
不同节点上面的myid中输入的内容应该与zoo.cfg文件中的server.*一致。 如:
在192.168.204.128节点上面的myid文件中输入的内容是1,
192.168.204.129节点上面的myid文件中输入的内容是2,
192.168.204.130节点上面的myid文件中输入的内容是3
6、修改/etc/sysconfig下的iptables配置
在防火墙中增加端口项vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
然后重启防火墙 service iptables restart
7、配置环境变量:
vi etc/profile 在最后添加如下两个。
export ZOOKEEPER_HOME=/usr/local/zookeeper/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf
保存后进入cd /etc目录下,输入source profile命令使修改生效。
8、启动zookeeper:
分别在3台机器上/usr/local/zookeeper/zookeeper/bin目录下启动;
[root@zk1 bin]# zkServer.sh start来启动。
zkServer.sh restart (重启)
zkServer.sh status (查看状态)
zkServer.sh stop (关闭)
zkServer.sh start-foreground (以打印日志方式启动)
启动成功后,通过zkServer.sh status查看节点状态,不同节点显示的zookeeper角色不一样,只有一个节点是leader,
其它的节点都是follower。
9、连接到ZooKeeper:
进入/usr/local/zookeeper/zookeeper/bin
在命令行中输入:./zkCli.sh -server 192.168.1.30:2181(任意一个节点都可以),
功连接后,系统会输出ZooKeeper的相关配置信息和相关环境,并在屏幕上输出Welcome to ZooKeeper!等信息。
10、之后就可以创建节点了。