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 伪集群或集群主要涉及安装、配置以及启动服务。在配置过程中,理解并正确设置 Zookeeper 的核心参数至关重要,这将直接影响集群的稳定性和性能。同时,确保集群内的通信畅通无阻也是成功...
本文档主要介绍如何在Ubuntu 16.04.7环境下搭建Zookeeper 3.7.2服务。Zookeeper是一款开源的分布式协调服务,用于解决分布式系统中的各种基础问题,如配置管理、域名服务、分布式同步、组服务等。它提供了简单易用的...
本文将详细介绍如何在分布式环境中搭建Apache ZooKeeper集群,包括环境准备、ZooKeeper下载、安装步骤、配置ZooKeeper、数据初始化、服务启动、集群配置、安全性和维护等内容。 #### 二、环境准备 **硬件要求:** -...
在生产环境中,通常会搭建Zookeeper集群以提高可用性和容错性。配置集群需要在每个节点的`zoo.cfg`中设置`server.{id}`,如`server.1=ip1:2888:3888`,表示ID为1的服务器的选举端口(2888)和通信端口(3888)。 六...
### ZooKeeper分布式环境搭建知识点详解 #### 一、准备工作 1. **JDK安装确认**: - **目的**:由于ZooKeeper是基于Java语言编写的,因此必须确保每台服务器或虚拟机上都已经安装了Java Development Kit (JDK)。 ...
本主题将深入探讨如何在Linux环境下整合Dubbo和Zookeeper,这两个都是Java生态系统中的关键组件。Dubbo是一个高性能、轻量级的Java服务治理框架,而Zookeeper则是一个分布式协调服务,用于管理分布式应用的配置信息...
kafka 和 Zookeeper 集群部署技术手册 ...通过阅读本文档,读者可以快速搭建起一个功能齐全的 Kafka 和 Zookeeper 集群,并了解 Kafka 和 Zookeeper 集群的配置、启动和注册服务等方面的详细信息。
在Windows 7环境下,用户可以通过执行解压目录下的`bin/zkServer.cmd`脚本来启动ZooKeeper服务器,而在Linux环境下,应执行`bin/zkServer.sh`脚本。这说明ZooKeeper提供了跨平台的支持,并且它的启动脚本位于`bin`...
##### 5、设置tomcat开机自启动 - 创建一个脚本`auto-startup.sh`,用于启动Tomcat服务。 - 设置此脚本具有执行权限。 - 在`/etc/rc.d/rc.local`中添加启动脚本的执行命令。 完成以上步骤后,web服务器的配置即告...
当需要搭建Zookeeper集群时,需要在`zoo.cfg`中添加以下集群配置: 1. `server.1=`、`server.2=`、`server.3=`等,指定集群中每台服务器的IP地址和通信端口(如2888和3888)。 2. 各个服务器的`dataDir`下创建`myid`...
【CentOS7安装与配置Zookeeper】是针对Linux系统中常用的服务发现和分布式协调框架Zookeeper进行的基础操作。Zookeeper是Apache Hadoop项目的一部分,它为分布式应用提供了一个高效、可靠的分布式协调服务。 首先,...
总结一下,ZooKeeper单机集群配置主要包括下载与解压、环境变量配置、ZooKeeper配置文件修改、初始化数据目录、启动ZooKeeper服务以及测试服务。在Java Dubbo项目中,ZooKeeper发挥着关键的协调作用,使得服务之间的...
本文档指导您搭建了 Hadoop 分布式环境,包括安装和配置 Hadoop、ZooKeeper 和 HBase,同时也介绍了相关的网络配置和 Linux 系统安装。希望本文档能够帮助您更好地理解 Hadoop 分布式环境的搭建和配置。
6. **集群部署**:在Windows上搭建Zookeeper集群,需要在每个节点的`zoo.cfg`中配置其他节点的IP和端口,形成互相连接的网络。同时,确保各节点间的时间同步,以避免因时间差异引发的问题。 7. **数据模型**:...
描述中提到的"搭建dubbo+zookeeper+kafka+redis+mq分布式大数据所需要的zookeeper环境",这涉及到几个关键的分布式组件: 1. **Dubbo**:Dubbo是一个高性能、轻量级的Java RPC框架,它依赖于ZooKeeper来实现服务...
总结来说,"zookeeper和dubbo搭建所需软件"涉及到的技术栈包括:Zookeeper作为分布式协调器,Dubbo作为服务框架,Apache Tomcat作为Web容器,以及JDK作为Java运行环境。通过这些组件的组合,可以构建出一个可扩展、...
Apache ZooKeeper 是一个分布式...通过以上步骤和知识点,你可以成功地在Linux环境下搭建和管理ZooKeeper集群,实现高效的分布式协调服务。记得在实际操作中,根据具体需求和环境调整配置,确保系统的稳定性和性能。
总结,搭建 Zookeeper 集群并在 Dubbo 中使用,能够为分布式应用提供稳定可靠的服务协调,实现配置管理、服务发现等功能,确保系统的高可用性和扩展性。通过正确配置和维护,可以有效地支持大规模分布式系统的运行。