Linux搭建Zookeeper环境之服务自启动

Linux搭建Zookeeper环境之服务开机自启动
Zookeeper Serverk开机自启动,这里依然分为单机模式和集群模式配置,这里选择采用把Zookeeper做成服务的方式配置开机自启动:
1.单机模式配置Zookeeper Server开机自启动:
 [1].Xshell5工具登录服务器,进入/etc/init.d/目录,输入:cd /etc/init.d/
  [root@marklin ~]# cd /etc/init.d/
  [root@marklin init.d]# ll
total 44
-rw-r--r--. 1 root root 17500 May  3  2017 functions
-rwxr-xr-x. 1 root root  4334 May  3  2017 netconsole
-rwxr-xr-x. 1 root root  7293 May  3  2017 network
-rw-r--r--. 1 root root  1160 Aug  5  2017 README
-rwxr-xr-x. 1 root root  1600 Mar 25 09:31 redis
[root@marklin init.d]#
 
[2].新建单机模式的服务脚本,输入:touch zookeeperStandalone
[root@marklin init.d]# touch zookeeperStandalone
[root@marklin init.d]# ll
total 44
-rw-r--r--. 1 root root 17500 May  3  2017 functions
-rwxr-xr-x. 1 root root  4334 May  3  2017 netconsole
-rwxr-xr-x. 1 root root  7293 May  3  2017 network
-rw-r--r--. 1 root root  1160 Aug  5  2017 README
-rwxr-xr-x. 1 root root  1600 Mar 25 09:31 redis
-rw-r--r--. 1 root root     0 Apr  4 15:32 zookeeperStandalone
[root@marklin init.d]#
 
[3]授权给脚本添加执行权限,输入:chmod +x zookeeperStandalone
[root@marklin init.d]# chmod +x zookeeperStandalone
[root@marklin init.d]# ll
total 44
-rw-r--r--. 1 root root 17500 May  3  2017 functions
-rwxr-xr-x. 1 root root  4334 May  3  2017 netconsole
-rwxr-xr-x. 1 root root  7293 May  3  2017 network
-rw-r--r--. 1 root root  1160 Aug  5  2017 README
-rwxr-xr-x. 1 root root  1600 Mar 25 09:31 redis
-rwxr-xr-x. 1 root root     0 Apr  4 15:32 zookeeperStandalone
[root@marklin init.d]#
 
[4]编辑服务脚本文件并输入配置脚本内容:vim zookeeperStandalone
#!/bin/bash  
#chkconfig:2345 20 90  
#description:zookeeperStandalone
#processname:zookeeperStandalone
export JAVA_HOME=/usr/local/java/jdk1.8.0_162
case $1 in  
        start) su root /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/zkServer.sh start;;  
        stop) su root /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/zkServer.sh stop;;  
        status) su root /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/zkServer.sh status;;  
        restart) su /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/zkServer.sh restart;;  
        *) echo "require start|stop|status|restart" ;;  
esac  
 
【5】添加到开始自启动,输入:chkconfig --add zookeeperStandalone
[root@marklin init.d]# chkconfig --add zookeeperStandalone
[root@marklin init.d]#
 
查看开机自启的服务中是否已经有我们的zookeeperStandalone,输入:chkconfig --list
[root@marklin init.d]# chkconfig --list
 
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
 
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
 
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
redis              0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperStandalone    0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@marklin init.d]#
 
 
【6】测试单机模式的zookeeperStandalone的服务:
启动单机模式配置Zookeeper Server的zookeeperStandalone服务,输入: service zookeeperStandalone start
停止单机模式配置Zookeeper Server的zookeeperStandalone服务,输入: service zookeeperStandalone stop
设置开机自启动单机模式配置Zookeeper Server的zookeeperStandalone服务,输入: chkconfig zookeeperStandalone on
关闭开机自启动单机模式配置Zookeeper Server的zookeeperStandalone服务,输入: chkconfig zookeeperStandalone off
 
[root@marklin ~]# service zookeeperStandalone start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Starting zookeeper ... already running as process 9359.
[root@marklin ~]# service zookeeperStandalone status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-standalone/zookeeper-3.5.3/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone
[root@marklin ~]# chkconfig zookeeperStandalone on
[root@marklin ~]# chkconfig --list
 
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
 
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
 
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
redis              0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperStandalone    0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@marklin ~]#
 
 
2.集群模式配置Zookeeper Server开机自启动:
 [1].Xshell5工具登录服务器,进入/etc/init.d/目录,输入:cd /etc/init.d/
[root@marklin init.d]# cd /etc/init.d/
[root@marklin init.d]# ll
total 48
-rw-r--r--. 1 root root 17500 May  3  2017 functions
-rwxr-xr-x. 1 root root  4334 May  3  2017 netconsole
-rwxr-xr-x. 1 root root  7293 May  3  2017 network
-rw-r--r--. 1 root root  1160 Aug  5  2017 README
-rwxr-xr-x. 1 root root  1600 Mar 25 09:31 redis
-rwxr-xr-x. 1 root root   659 Apr  4 15:41 zookeeperStandalone
[root@marklin init.d]#
 
 
[2].新建集群模式的服务脚本【zookeeperMaster,zookeeperSlave1,zookeeperSlave2】,输入: touch  zookeeperMaster, touch zookeeperSlave1, touch zookeeperSlave2
[root@marklin init.d]# touch  zookeeperMaster
[root@marklin init.d]# touch zookeeperSlave1
[root@marklin init.d]# touch zookeeperSlave2
[root@marklin init.d]# ll
total 48
-rw-r--r--. 1 root root 17500 May  3  2017 functions
-rwxr-xr-x. 1 root root  4334 May  3  2017 netconsole
-rwxr-xr-x. 1 root root  7293 May  3  2017 network
-rw-r--r--. 1 root root  1160 Aug  5  2017 README
-rwxr-xr-x. 1 root root  1600 Mar 25 09:31 redis
-rw-r--r--. 1 root root     0 Apr  4 16:02 zookeeperMaster
-rw-r--r--. 1 root root     0 Apr  4 16:02 zookeeperSlave1
-rw-r--r--. 1 root root     0 Apr  4 16:02 zookeeperSlave2
-rwxr-xr-x. 1 root root   659 Apr  4 15:41 zookeeperStandalone
[root@marklin init.d]#
 
 
 
[3]授权给脚本添加执行权限【zookeeperMaster,zookeeperSlave1,zookeeperSlave2】,输入:chmod +x  zookeeperMaster,chmod +x zookeeperSlave1,chmod +x zookeeperSlave2
[root@marklin init.d]# chmod +x  zookeeperMaster
[root@marklin init.d]# chmod +x  zookeeperS
zookeeperSlave1      zookeeperSlave2      zookeeperStandalone  
[root@marklin init.d]# chmod +x  zookeeperSlave1
[root@marklin init.d]# chmod +x  zookeeperSlave2
[root@marklin init.d]# ll
total 48
-rw-r--r--. 1 root root 17500 May  3  2017 functions
-rwxr-xr-x. 1 root root  4334 May  3  2017 netconsole
-rwxr-xr-x. 1 root root  7293 May  3  2017 network
-rw-r--r--. 1 root root  1160 Aug  5  2017 README
-rwxr-xr-x. 1 root root  1600 Mar 25 09:31 redis
-rwxr-xr-x. 1 root root     0 Apr  4 16:02 zookeeperMaster
-rwxr-xr-x. 1 root root     0 Apr  4 16:02 zookeeperSlave1
-rwxr-xr-x. 1 root root     0 Apr  4 16:02 zookeeperSlave2
-rwxr-xr-x. 1 root root   659 Apr  4 15:41 zookeeperStandalone
[root@marklin init.d]#
 
 
[4]编辑服务脚本文件【zookeeperMaster,zookeeperSlave1,zookeeperSlave2】并输入配置脚本内容:
[root@marklin init.d]# vim zookeeperMaster
[root@marklin init.d]# vim zookeeperSlave1
[root@marklin init.d]# vim zookeeperSlave2
zookeeperMaster:
#!/bin/bash  
#chkconfig:2345 20 90  
#description:zookeeperMaster  
#processname:zookeeperMaster  
export JAVA_HOME=/usr/local/java/jdk1.8.0_162
case $1 in  
        start) su root /usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3/bin/zkServer.sh start;;  
        stop) su root /usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3/bin/zkServer.sh stop;;  
        status) su root /usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3/bin/zkServer.sh status;;  
        restart) su /usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3/bin/zkServer.sh restart;;  
        *) echo "require start|stop|status|restart" ;;  
esac  
 
 
zookeeperSlave1:
#!/bin/bash  
#chkconfig:2345 20 90  
#description:zookeeperSlave1  
#processname:zookeeperSlave1
export JAVA_HOME=/usr/local/java/jdk1.8.0_162
case $1 in  
        start) su root /usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3/bin/zkServer.sh start;;  
        stop) su root /usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3/bin/zkServer.sh stop;;  
        status) su root /usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3/bin/zkServer.sh status;;  
        restart) su /usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3/bin/zkServer.sh restart;;  
        *) echo "require start|stop|status|restart" ;;  
esac  
 
 
zookeeperSlave2:
#!/bin/bash  
#chkconfig:2345 20 90  
#description:zookeeperSlave2  
#processname:zookeeperSlave2
export JAVA_HOME=/usr/local/java/jdk1.8.0_162
case $1 in  
        start) su root /usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3/bin/zkServer.sh start;;  
        stop) su root /usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3/bin/zkServer.sh stop;;  
        status) su root /usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3/bin/zkServer.sh status;;  
        restart) su /usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3/bin/zkServer.sh restart;;  
        *) echo "require start|stop|status|restart" ;;  
esac  
 
 
【5】添加到开始自启动【zookeeperMaster,zookeeperSlave1,zookeeperSlave2】,输入:chkconfig --add zookeeperMaster,chkconfig --add zookeeperSlave1,,chkconfig --add zookeeperSlave2
[root@marklin init.d]# chkconfig --add zookeeperMaster
[root@marklin init.d]# chkconfig --add zookeeperSlave1
[root@marklin init.d]# chkconfig --add zookeeperSlave2
[root@marklin init.d]# chkconfig --list
 
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
 
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
 
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
redis              0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperMaster    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave1    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave2    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperStandalone    0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@marklin init.d]#
 
 
 
【6】测试集群模式的【zookeeperMaster,zookeeperSlave1,zookeeperSlave2】的服务:
zookeeperMaster:
启动单机模式配置Zookeeper Server的zookeeperMaster服务,输入: service zookeeperMaster start
停止单机模式配置Zookeeper Server的zookeeperMaster服务,输入: service zookeeperMaster stop
设置开机自启动单机模式配置Zookeeper Server的zookeeperMaster服务,输入: chkconfig zookeeperMaster on
关闭开机自启动单机模式配置Zookeeper Server的zookeeperMaster服务,输入: chkconfig zookeeperMaster off
[root@marklin init.d]# service zookeeperMaster start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@marklin init.d]# service zookeeperMaster status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-cluster/cluster-master/zookeeper-3.5.3/bin/../conf/zoo.cfg
Client port found: 2182. Client address: localhost.
Mode: follower
[root@marklin init.d]# jps
7576 QuorumPeerMain
10427 Jps
10318 QuorumPeerMain
9359 QuorumPeerMain
[root@marklin init.d]# chkconfig zookeeperMaster on
[root@marklin init.d]# chkconfig --list
 
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
 
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
 
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
redis              0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperMaster    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave1    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave2    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperStandalone    0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@marklin init.d]#
 
 
zookeeperSlave1
启动单机模式配置Zookeeper Server的zookeeperSlave1服务,输入: service zookeeperSlave1 start
停止单机模式配置Zookeeper Server的zookeeperSlave1服务,输入: service zookeeperSlave1 stop
设置开机自启动单机模式配置Zookeeper Server的zookeeperSlave1服务,输入: chkconfig zookeeperSlave1 on
关闭开机自启动单机模式配置Zookeeper Server的zookeeperSlave1服务,输入: chkconfig zookeeperSlave1 off
 
[root@marklin init.d]# service zookeeperSlave1 start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@marklin init.d]# service zookeeperSlave1 status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-cluster/cluster-slave1/zookeeper-3.5.3/bin/../conf/zoo.cfg
Client port found: 2183. Client address: localhost.
Error contacting service. It is probably not running.
[root@marklin init.d]# chkconfig zookeeperSlave1 on
[root@marklin init.d]# chkconfig --list
 
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
 
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
 
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
redis              0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperMaster    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave1    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave2    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperStandalone    0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@marklin init.d]#
 
 
zookeeperSlave2
启动单机模式配置Zookeeper Server的zookeeperSlave2服务,输入: service zookeeperSlave2 start
停止单机模式配置Zookeeper Server的zookeeperSlave2服务,输入: service zookeeperSlave2 stop
设置开机自启动单机模式配置Zookeeper Server的zookeeperSlave2服务,输入: chkconfig zookeeperSlave2 on
关闭开机自启动单机模式配置Zookeeper Server的zookeeperSlave2服务,输入: chkconfig zookeeperSlave2 off
 
[root@marklin init.d]# service zookeeperSlave2 start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@marklin init.d]# service zookeeperSlave2 status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-cluster/cluster-slave2/zookeeper-3.5.3/bin/../conf/zoo.cfg
Client port found: 2184. Client address: localhost.
Mode: leader
[root@marklin init.d]# chkconfig zookeeperSlave2 on
[root@marklin init.d]# chkconfig --list
 
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
 
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
 
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
redis              0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperMaster    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave1    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperSlave2    0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeperStandalone    0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@marklin init.d]#
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值