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]#
相关推荐
zookeeper linux 搭建流程,zookeeper linux 搭建流程zookeeper linux 搭建流程zookeeper linux 搭建流程。
linux下zookeeper集群环境搭建详细图文教程,简单易使用
Linux Centos7 环境搭建Docker部署Zookeeper服务实战
Linux下Zookeeper集群的安装
NULL 博文链接:https://mazhilin.iteye.com/blog/2415590
附件是Linux环境下搭建Zookeeper的分布式环境教程,文件绿色安全,请大家放心下载,仅供交流学习使用,无任何商业目的!
搭建zookeeper集群搭建zookeeper集群搭建zookeeper集群搭建zookeeper集群搭建zookeeper集群搭建zookeeper集群
Windows 环境 为zookeeper和kafka配置开机自启动服务。
Zookeeper环境搭建
ZooKeeper分布式环境搭建详解 ZooKeeper是一个分布式协调服务,主要用于维护配置信息、命名、提供分布式同步和提供组服务等。在分布式系统中,ZooKeeper常被用作服务发现、分布式锁、领导选举等场景。下面将详细...
zookeeper linux版本 windows版 通用 ,下载后解压直接运行bin中的zkServer
Zookeeper伪分布式集群搭建描述伪分布式集群就是在一台机器部署多个zk应用,部署之前服务器需要有jdk环境 java -version可以显示相关java
【Free】Linux Zookeeper 3.6.3
详解Zookeeper伪分布式集群环境搭建过程
本篇文章主要给大家详细分享了在Linux下搭建Zookeeper管理中心步骤以及相关软件的下载,需要的朋友参考下。
ZooKeeper 管理工具