《架构之路zookeeper系列》zookeeper安装与配置
今天跟大家分享下单机环境下zookeeper安装与配置,希望能给初学者带来帮助。
二.实验环境
1.操作系统:CentOS7
IP:192.168.1.106
2.zookeeper-3.4.11
下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
三.实战演练
$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
$ chmod -R 755 ./zookeeper-3.4.11.tar.gz
$ tar -zxvf ./zookeeper-3.4.11.tar.gz
$ cd /opt/zookeeper-3.4.11/
$ mkdir data
$ mkdir logs
$ cp ./conf/zoo_sample.cfg ./conf/zoo.cfg
$ vi ./conf/zoo.cfg
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=/tmp/zookeeper
dataDir=/opt/zookeeper-3.4.11/data
dataLogDir=/opt/zookeeper-3.4.11/logs
# 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.1.106:2888:3888备注:2888端口是zookeeper服务之间通信的端口,3888端口是zookeeper与其他应用程序通信的端口。
$ vi /root/.bash_profile
$ export ZOOKEEPER_HOME=/opt/zookeeper-3.4.11
$ export PATH=$ZOOKEEPER_HOME/bin:$PATH
$ source /root/.bash_profile
$ firewall-cmd --state
$ firewall-cmd --zone=public --add-port=2181/tcp --permanent
$ firewall-cmd --zone=public --add-port=2888/tcp --permanent
$ firewall-cmd --zone=public --add-port=3888/tcp --permanent
$ firewall-cmd --reload
$ vi /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
$ service iptables restart
$ ./zkServer.sh start
[root@localhost bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.11/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
$ su - root -c '/opt/zookeeper-3.4.11/bin/zkServer.sh start'
四.总结
经过以上的简单步骤,我们的单机版的zookeeper运行环境就搭建好了,接下来就可以进行zookeeper学习之旅了。