Zookeeper安装使用--单机模式

1.version package准备

zookeeper-3.4.5.tar.gz

2.mkdir zookeeper folder.tar the package 

mkdir zookeeper
tar xvf zookeeper-3.4.5.tar.gz
[root@localhost zookeeper]# pwd
/root/zookeeper
[root@localhost zookeeper]# ll
total 16024
drwxr-xr-x. 12 501 games 4096 Jan 30 07:30 zookeeper-3.4.5
-rw-r--r--. 1 root root 16402010 Apr 29 2018 zookeeper-3.4.5.tar.gz
[root@localhost zookeeper]#

3.将zookeeper-3.4.10/conf目录下的zoo_sample.cfg文件拷贝一份,命名为zoo.cfg.然后修改zoo.cfg文件

# 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=/root/zookeeper/zookeeper-3.4.5/data
dataLogsDir=/root/zookeeper/zookeeper-3.4.5/logs
# the port at which the clients will connect
clientPort=2181
#
# 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
#
server.1=192.168.106.133:2888:3888
# 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

4.配置myid文件

path:dataDir=/root/zookeeper/zookeeper-3.4.5/data  创建myid文件(编辑myid文件,并在对应的IP的机器上输入对应的编号。如在zookeeper上,myid 文件内容就是1。如果只在单点上进行安装配置,那么只有一个server.1)

5.修改.bash_profile,增加zookeeper配置:path =etc/profile,编辑完成使profile文件夹生效:source etc/profile

# zookeeper env export   
ZOOKEEPER_HOME=/root/zookeeper/zookeeper-3.4.5 export   
PATH=$ZOOKEEPER_HOME/bin:$PATH 

6.关闭防火墙

systemctl stop firewalld.service

7.测试Zookeeper

切换至/root/zookeeper/zookeeper-3.4.5/bin目录中执行

./zkServer.sh start  

#查看进程
jps
 
其中,QuorumPeerMain是zookeeper进程,启动正常。
  
#查看状态  
./zkServer.sh status  
  
#服务器输出信息  
tail -500f zookeeper.out  
  
#停止zookeeper进程  
./zkServer.sh stop 

8.设置zookeeper服务开机启动

# 切换至/etc/rc.d/init.d/目录下  
cd /etc/rc.d/init.d  
[root@localhost init.d]# pwd
-rwxr-xr-x. 1 root root   565 Jan 30 07:36 zookeeper

/etc/rc.d/init.d
# 创建zookeeper文件  
touch zookeeper  
  
#更新权限  
chmod +x zookeeper  
  
#编辑文件,在zookeeper里面输入如下内容

# chkconfig: 2345 10 90
# description: zookeeper
#processname:zookeeper
export JAVA_HOME=/root/jdk/jdk1.8.0_171
export PATH=$JAVA_HOME/bin:$PATH
case $1 in
start)su root /root/zookeeper/zookeeper-3.4.5/bin/zkServer.sh start;;
stop)su root /root/zookeeper/zookeeper-3.4.5/bin/zkServer.sh stop;;
status)su root /root/zookeeper/zookeeper-3.4.5/bin/zkServer.sh status;;
restart)su root /root/zookeeper/zookeeper-3.4.5/bin/zkServer.sh restart;;
*) echo "require start|stop|status|restart" ;;
esac

 

chkconfig --list验证zookeeper是否添加开机启动

[root@localhost init.d]# chkconfig --list
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
zookeeper       0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost init.d]# 

猜你喜欢

转载自www.cnblogs.com/wongandy/p/10336432.html