1.什么是zookeeper
Apache ZooKeeper is an effort to develop and maintain an open-source server which enables highly reliable distributed coordination.
Zookeeper是Hadoop的一个子项目,它是分布式系统中的协调系统,可提供的服务主要有:配置服务、名字服务、分布式同步、组服务等
2.安装zookeeper
# 下载
wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
# 解压
tar -zxvf zookeeper-3.4.14.tar.gz
# 新建data和log两个目录
cd zookeeper-3.4.14
mkdir data
mkdir log
3.将zookeeper-3.4.14/conf目录下将zoo_sample.cfg文件拷贝一份,命名为zoo.cfg
cd /usr/soft/zookeeper/zookeeper-3.4.14/conf
cp zoo_sample.cfg zoo.cfg
4.修改zoo.cfg文件
修改dataDir目录,增加dataLogDir目录,增加服务器列表
dataDir=/usr/soft/zookeeper/zookeeper-3.4.14/data
dataLogDir=/usr/soft/zookeeper/zookeeper-3.4.14/log
#配置server
# 192.168.192.130 当前机器的ip
# 2888端口号是zookeeper服务之间通信的端口
# 3888是zookeeper与其他应用程序通信的端口
server.0=39.107.119.49:2888:3888
注意:dataDir目录和dataLogDir目录就是步骤2中创建的data和log目录
完整配置信息如下:
# 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/soft/zookeeper/zookeeper-3.4.14/data
dataLogDir=/usr/soft/zookeeper/zookeeper-3.4.14/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.0=39.107.119.49:2888:3888
5.在/usr/soft/zookeeper/zookeeper-3.4.14/data目录下创建myid文件
里面的内容和步骤4里的server.0的序号相对应,所以这里的内容填写0
6.配置zookeeper环境变量
export ZOOKEEPER_HOME=/usr/soft/zookeeper/zookeeper-3.4.14
# 修改完之后执行如下命令是配置文件生效
source /etc/profile
7.配置防火墙
vim /etc/sysconfig/iptables
在配置文件中增加如下信息
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-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
重启防火墙
centos7:
systemctl restart firewalld.service
# 查看防火墙状态
firewall-cmd --state
centos6:
service iptables restart
# 查看防火墙状态
service iptables status
8.启动
cd /usr/soft/zookeeper/zookeeper-3.4.14/bin
# 开启
./zkServer.sh start
# 关闭
./zkServer.sh stop
# 查看状态
./zkServer.sh status
输入jps查看进程