欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux下 安装zookeeper,设置开机自启动

程序员文章站 2024-03-18 10:55:58
...

话不多说,直接上步骤

1、下载安装包


cd /usr/local

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1-bin.tar.gz

这是清华大学的开源软件镜像网站,如果3.6.1的镜像不在了,直接去这个网站看看别的镜像,换个镜像下载

2、解压安装包

  tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz

3、进去,修改配置文件

linux下 安装zookeeper,设置开机自启动

执行 
cp  zoo_sample.cfg zoo.cfg 

修改zoo.cfg

# The number of milliseconds of each tick
    # zookeeper 定义的基准时间间隔,单位:毫秒
  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=/tmp/zookeeper
   # 数据文件夹
    dataDir=/tmp/zookeeper/data
   # 日志文件夹
    dataLogDir=/tmp/zookeeper/log
   # the port at which the clients will connect
   # 客户端访问 zookeeper 的端口号
  clientPort=2181
   # the maximum number of client connections.
   # increase this if you need to handle more clients
   #maxClientCnxns=60
    #自定义启动端口,防止冲突
    admin.serverPort=8888

   #
   # 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 

dataDir=/tmp/zookeeper/data
dataLogDir=/tmp/zookeeper/log
这2个目录需要手动去创建

mkdir /tmp/zookeeper/data

mkdir /tmp/zookeeper/log

4、测试启动

linux下 安装zookeeper,设置开机自启动

到bin 目录下,启动程序。

linux下 安装zookeeper,设置开机自启动

5、设置服务器开机自启动

执行
cd /etc/rc.d/init.d/
vi zookeeper
在文件中输入,注意不要复制少了


#chkconfig:2345 20 90

#description:zookeeper

#processname:zookeeper
#jdk的路径,根据服务器情况自己修改
export JAVA_HOME=/usr/java/jdk1.8.0_231
#zk路径,根据情况修改
case $1 in
          start) su root /usr/local/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start;;
          stop) su root /usr/local/apache-zookeeper-3.6.1-bin/bin/zkServer.sh stop;;
          status) su root /usr/local/apache-zookeeper-3.6.1-bin/bin/zkServer.sh status;;
          restart) su root /usr/local/apache-zookeeper-3.6.1-bin/bin/zkServer.sh restart;;
     *)  echo "require start|stop|status|restart"  ;;
esac
      

设置执行权限 

chmod 777 zookeeper

添加到启动项

chkconfig --add zookeeper


查看状态

chkconfig --list zookeeper

linux下 安装zookeeper,设置开机自启动

测试一下脚本

service zookeeper start
service zookeeper stop
service zookeeper restart
service zookeeper status

 

 

 

相关标签: zookeeper linux