加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux中zookeeper开机自启动和注册为服务

发布时间:2020-12-13 23:30:24 所属栏目:Linux 来源:网络整理
导读:1.安装jdk,zookeeper就不说啦,自己搜索下。 2.开机自启动和注册为服务。 (1)开机自启动:编辑/etc/rc.d/rc.local文件,添加zkServer.sh路径。 vi /etc/rc.d/rc.local #!/bin/sh # This script will be executed *after* all the other init scripts. # You

1.安装jdk,zookeeper就不说啦,自己搜索下。

2.开机自启动和注册为服务。

(1)开机自启动:编辑/etc/rc.d/rc.local文件,添加zkServer.sh路径。

  vi /etc/rc.d/rc.local

  #!/bin/sh

 # This script will be executed *after* all the other init scripts.
 # You can put your own initialization stuff in here if you don‘t
 # want to do the full Sys V style init stuff.

 touch /var/lock/subsys/local
 export JAVA_HOME=/usr/java/jdk1.8.0_221        --jdk的路径,自己安装的目录
 /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh start   --zookeeper的zkServer.sh的路径

(2)注册为服务:到/etc/rc.d/init.d目录下添加,zookeeper脚本

  cd /etc/rc.d/init.d

  touch zookeeper

  ls -al? ? ? ? ? ? ? ? ? ? ? ? --查看到没有执行权限,修改权限

  chmod +x zookeeper

  vi zookeeper   ? -- 打开zookeeper编辑脚本,下面为要 编辑的内容

  #! /bin/bash

  export JAVA_HOME=/usr/java/jdk1.8.0_221

  case $1 in
    start) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh start;;
    stop) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh stop;;
    status) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh status;;
    restart) su /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh restart;;
    *) echo "require start|stop|status|restart" ;;
  esac

添加好后保存。测试:

  service?zookeeper start

启动成功后则添加服务成功了。

(3)将服务添加为开机启动。

  chkconfig --add zookeeper? ? ? ? ? ? ? ? --zookeeper为刚才注册的服务

  chkconfig --list? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--查看刚才添加的zookeeper是否成功。有显示为成功。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读