此次安装是在CentOS6.5上进行安装
1、在系统的/etc/hosts文件中添加ip、主机名
# zookeeper servers
192.168.42.128 dreyer-vm-01
2、在http://apache.fayea.com/zookeeper/下载zookeeper3.4.6版本并将压缩文件放到/home/dreyer下(目录自定义)
3、解压文件
$ tar zxvf zookeeper-3.4.6.tar.gz
4、在/home/dreyer/zookeeper-3.4.6中创建两个文件夹(一个为数据文件夹,一个为日志文件夹)
$ mkdir data
$ mkdir logs
5、将zookeeper-3.4.6/conf目录下将zoo_samaple.cfg文件拷贝一份并命名为zoo.cfg
$ cp zoo_sample.cfg zoo.cfg
6、修改zoo.cfg文件
6.1、指定zookeeper的日志和数据目录:找到文件中的dataDir=/tmp/zookeeper,删除将其替换为(之前我们创建过的data和logs目录)
dataDir=/home/dreyer/zookeeper-3.4.6/data
dataLogDir=/home/dreyer/zookeeper-3.4.6/logs
6.2、为zookeeper添加服务,在文件的最后面加上server.1=dreyer-vm-01:2888:3888,其中dreyer-vm-01是我们之前添加的主机名,也可以写成server.1=192.168.42.128:2888:3888
最后的文件是这样的
# 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=/home/dreyer/zookeeper-3.4.6/data
dataLogDir=/home/dreyer/zookeeper-3.4.6/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=dreyer-vm-01:2888:3888
7、在dataDir=/home/dreyer/zookeeper-3.4.6/data目录下创建myid文件
编辑myid文件,并在对应的IP的机器上输入对应的编号。如在zookeeper-3.4.6上,myid的文件内容就是1。如果只在单节点上配置,那么就只有一个server.1
$ vi myid并在里面输入1后保存退出
8、给zookeeper配置环境变量
$ vi /etc/profile
在最后面添加
# zookeeper env
export ZOOKEEPER_HOME=/home/dreyer/zookeeper-3.4.6
export PATH=$ZOOKEEPER_HOME/bin:$PATH
然后使用$ source /etc/profile命令让修改立即生效
9、在防火墙中开启zookeeper用到的端口2181、2888、3888
1.$ chkconfig iptables on(设置防火墙开机启动)
2.$ service iptables start(启动防火墙)
3.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
上面的三行其实是复制系统默认的22端口的信息,即将其中的22改为对应的2181、2888、3888即可
4. $ service iptables restart(重启防火墙)
5.$ service iptables status,查看查看防火墙信息,现在就能看到我们刚刚配置的端口信息了
10、启动zookeeper(用普通用户启动)
在bin目录启动,cd /home/dreyer/zookeeper-3.4.6/bin
$ ./zkServer.sh start(启动)
查看zookeeper是否启动成功
输入jps,看是否会出现下面的进程信息
35835 Jps
35818 QuorumPeerMain
或者输入zkServer.sh status,看是否会有下面的信息
JMX enabled by default
Using config: /home/dreyer/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
其中Mode: standalone代表的是这个zookeeper是单节点模式
停止zookeeper服务$ ./zkServer.sh stop
重启zookeeper服务$ ./zkServer.sh restart
11、过程中遇到的问题
1.用普通用户无法启动,提示
JMX enabled by default
Using config: /home/dreyer/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... ./zkServer.sh: line 113: /home/dreyer/zookeeper-3.4.6/data/zookeeper_server.pid: Permission denied
FAILED TO WRITE PID
[dreyer@localhost bin]$ ./zkServer.sh: line 109: ./zookeeper.out: Permission denied
解决方法正如提示的那样,/home/dreyer/zookeeper-3.4.6/data/zookeeper_server.pid和./zookeeper.out这两个文件的权限不够,因为他们是root权限的,所以我们要将这两个文件的权限改为全部的用户都可读写执行
$ chmod 777 zookeeper_server.pid
$ chmod 777 zookeeper.out
2.顺便提一下的问题就是启动的时候会有类似下面的错误,这是就回想下你是否防火墙没有启动或者环境变量有没有配置对,又或者环境配置配置对了,最后有没有使用source /etc/profile命令使它立即生效
bash: zkServer.sh: command not found