Hadoop生态圈相关组件服务启动、关闭和查看脚本

目录

1.查看进程

2.hadoop集群

3.zookeeper

4.hbase

5.kafka

1.查看进程

[[email protected] ~]# cd /usr/bin/
[[email protected] bin]# vi jps.sh

        切换到/usr/bin目录下,创建脚本文件jps.sh,并输入以下内容:

#!/bin/bash

for i in master slave1 slave2
    do
        echo "**********$i**********"
        ssh $i "/export/servers/jdk/bin/jps"
    done

        注意:master slave1 slave2 为主机名

               /export/servers/jdk/bin/jps 为jps命令的绝对路径 

[[email protected] bin]# chmod 777 jps.sh
[[email protected] bin]# ll jps.sh 
-rwxrwxrwx. 1 root root 124 Dec 13 16:00 jps.sh

        更改jps.sh脚本权限为777,并查看权限。

       运行jps命令脚本结果如下。

[[email protected] bin]# jps.sh 
**********master**********
3971 Jps
**********slave1**********
3264 Jps
**********slave2**********
3385 Jps
[[email protected] bin]#

2.hadoop集群

         切换到/usr/bin目录下,创建脚本文件ha.sh,并输入以下内容:

#!/bin/bash

case $1 in
"start"){
    echo "**********启动集群**********"
    ssh master "/export/servers/hadoop-2.6.4/sbin/start-dfs.sh"
    ssh slave2 "/export/servers/hadoop-2.6.4/sbin/start-yarn.sh"
};;    
"stop"){
    echo "**********关闭集群**********"
    ssh slave2 "/export/servers/hadoop-2.6.4/sbin/stop-yarn.sh"
    ssh master "/export/servers/hadoop-2.6.4/sbin/stop-dfs.sh"
};;    
esac

        注意:master slave1 slave2 为主机名

               /export/servers/hadoop-2.6.4 为hadoop组件安装目录

       更改ha.sh脚本权限为777,参考jps.sh脚本设置。

        启动hadoop集群示例,并查看进程

[[email protected] bin]# ha.sh start
**********启动集群**********
Starting namenodes on [master]
master: starting namenode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-namenode-master.out
slave2: starting datanode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-datanode-slave2.out
slave1: starting datanode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-datanode-slave1.out
Starting secondary namenodes [slave1]
slave1: starting secondarynamenode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-secondarynamenode-slave1.out
starting yarn daemons
starting resourcemanager, logging to /export/servers/hadoop-2.6.4/logs/yarn-root-resourcemanager-slave2.out
slave1: starting nodemanager, logging to /export/servers/hadoop-2.6.4/logs/yarn-root-nodemanager-slave1.out
slave2: starting nodemanager, logging to /export/servers/hadoop-2.6.4/logs/yarn-root-nodemanager-slave2.out
[[email protected] bin]# jps.sh
**********master**********
4166 NameNode
4396 Jps
**********slave1**********
3383 DataNode
3564 NodeManager
3486 SecondaryNameNode
3694 Jps
**********slave2**********
4048 Jps
3505 DataNode
3731 NodeManager
3628 ResourceManager
[[email protected] bin]#

        关闭hadoop集群示例,并查看进程

[[email protected] bin]# ha.sh stop
**********关闭集群**********
stopping yarn daemons
stopping resourcemanager
slave2: stopping nodemanager
slave1: stopping nodemanager
no proxyserver to stop
Stopping namenodes on [master]
master: stopping namenode
slave2: stopping datanode
slave1: stopping datanode
Stopping secondary namenodes [slave1]
slave1: stopping secondarynamenode
[[email protected] bin]# jps.sh
**********master**********
4710 Jps
**********slave1**********
3853 Jps
**********slave2**********
4278 Jps
[[email protected] bin]# 

3.zookeeper

        切换到/usr/bin目录下,创建脚本文件zk.sh,并输入以下内容:

#!/bin/bash

case $1 in
"start"){
    for i in master slave1 slave2
    do
        echo "**********$i**********"
        ssh $i "/export/servers/zookeeper/bin/zkServer.sh start"
    done
};;    
"stop"){
    for i in master slave1 slave2
    do
        echo "**********$i**********"
        ssh $i "/export/servers/zookeeper/bin/zkServer.sh stop"
    done
};;    
"status"){
    for i in master slave1 slave2
    do
        echo "**********$i**********"
        ssh $i "/export/servers/zookeeper/bin/zkServer.sh status"
    done
};;    

        注意:master slave1 slave2 为主机名

               /export/servers/zookeeper为zookeeper组件安装目录

       更改zk.sh脚本权限为777,参考jps.sh脚本设置。

        启动、查看和关闭zookeeper服务示例。

[[email protected] bin]# zk.sh start
**********master**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
**********slave1**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
**********slave2**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[[email protected] bin]# zk.sh status
**********master**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
**********slave1**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
**********slave2**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[[email protected] bin]# zk.sh stop
**********master**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
**********slave1**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
**********slave2**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[[email protected] bin]#

4.hbase

         切换到/usr/bin目录下,创建脚本文件hb.sh,并输入以下内容:

#!/bin/bash

case $1 in
"start"){
    echo "**********启动hbase**********"
    ssh master "/export/servers/hbase/bin/start-hbase.sh"
};;    
"stop"){
    echo "**********关闭hbase**********"
    ssh master "/export/servers/hbase/bin/stop-hbase.sh"
};;    
esac

        注意:master  为主机名

               /export/servers/hbase 为hbase组件安装目录

        更改hb.sh脚本权限为777,参考jps.sh脚本设置。

       启动和关闭hbase服务,并查看进程。(启动hbase服务之前,需启动hadoop集群和zookeeper)

[[email protected] bin]# ha.sh start
**********启动集群**********
Starting namenodes on [master]
master: starting namenode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-namenode-master.out
slave1: starting datanode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-datanode-slave1.out
slave2: starting datanode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-datanode-slave2.out
Starting secondary namenodes [slave1]
slave1: starting secondarynamenode, logging to /export/servers/hadoop-2.6.4/logs/hadoop-root-secondarynamenode-slave1.out
starting yarn daemons
starting resourcemanager, logging to /export/servers/hadoop-2.6.4/logs/yarn-root-resourcemanager-slave2.out
slave1: starting nodemanager, logging to /export/servers/hadoop-2.6.4/logs/yarn-root-nodemanager-slave1.out
slave2: starting nodemanager, logging to /export/servers/hadoop-2.6.4/logs/yarn-root-nodemanager-slave2.out
[[email protected] bin]# zk.sh start
**********master**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
**********slave1**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
**********slave2**********
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[[email protected] bin]# hb.sh start
**********启动hbase**********
starting master, logging to /export/servers/hbase/bin/../logs/hbase-root-master-master.out
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
slave1: starting regionserver, logging to /export/servers/hbase/bin/../logs/hbase-root-regionserver-slave1.out
slave1: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
slave1: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
slave2: starting regionserver, logging to /export/servers/hbase/bin/../logs/hbase-root-regionserver-slave2.out
slave2: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
slave2: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
master: starting regionserver, logging to /export/servers/hbase/bin/../logs/hbase-root-regionserver-master.out
master: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
master: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
master: master running as process 2198. Stop it first.
slave1: starting master, logging to /export/servers/hbase/bin/../logs/hbase-root-master-slave1.out
slave1: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
slave1: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
slave2: starting master, logging to /export/servers/hbase/bin/../logs/hbase-root-master-slave2.out
slave2: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
slave2: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
[[email protected] bin]# jps.sh
**********master**********
2049 QuorumPeerMain
2674 Jps
2198 HMaster
2311 HRegionServer
1789 NameNode
**********slave1**********
1856 QuorumPeerMain
2049 HMaster
1954 HRegionServer
1699 NodeManager
1621 SecondaryNameNode
1516 DataNode
2334 Jps
**********slave2**********
1649 ResourceManager
2097 QuorumPeerMain
1524 DataNode
1753 NodeManager
2618 Jps
2283 HMaster
2188 HRegionServer
[[email protected] bin]# hb.sh stop
**********关闭hbase**********
stopping hbase.................
[[email protected] bin]#

5.kafka

         切换到/usr/bin目录下,创建脚本文件kk.sh,并输入以下内容:

#!/bin/bash

case $1 in
"start"){
    for i in master slave1 slave2
    do
        echo "**********$1 $i**********"
        ssh $i "/export/servers/kafka/bin/kafka-server-start.sh -daemon /export/servers/kafka/config/server.properties"
    done
};;    
"stop"){
    for i in master slave1 slave2
    do
        echo "**********$1 $i**********"
        ssh $i "/export/servers/kafka/bin/kafka-server-stop.sh"
    done
};;    
esac

        注意:master slave1 slave2 为主机名

               /export/servers/kafka 为kafka组件安装目录

        更改kk.sh脚本权限为777,参考jps.sh脚本设置。

       启动和关闭kafka服务,并查看进程。

[[email protected] bin]# kk.sh start
**********start master**********
**********start slave1**********
**********start slave2**********
[[email protected] bin]# jps.sh
**********master**********
3797 Kafka
3830 Jps
**********slave1**********
3206 Jps
3177 Kafka
**********slave2**********
3568 Jps
3539 Kafka
[[email protected] bin]# kk.sh stop
**********stop master**********
No kafka server to stop
**********stop slave1**********
No kafka server to stop
**********stop slave2**********
No kafka server to stop
[[email protected] bin]# jps.sh 
**********master**********
3891 Jps
**********slave1**********
3268 Jps
**********slave2**********
3634 Jps
[[email protected] bin]#

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>