使用ansible控制Hadoop服务的启动和停止
一、环境:
服务器一台,已安装centos7.5系统,做ansible服务器;
客户机三台:hadoop-master(192.168.1.18)、hadoop-slave1(192.168.1.19)、hadoop-slave2(192.168.1.20)
二、ansible软件安装:
[root@centos75 ~]# yum install ansible
三、ansible配置过程:
1、服务器与客户机之间的免密配置:
(1)生成密钥: ssh-keygen -t rsa
(2)传递密钥:
[root@centos75 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.18
[root@centos75 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.19
[root@centos75 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.20
2、ansible配置
(1)Inventory主机清单配置:
[root@centos75 ~]# vi /etc/ansible/hosts
...
[hadoop]
192.168.1.[18:20] #这是一种IP地址段表示方式,也可单列每个IP地址。
(2)配置ansible.cfg:
[root@centos75 ~]# vi /etc/ansible/ansible.cfg
...
host_key_checking = False #禁用每次执行ansbile命令检查ssh key host
...
log_path = /var/log/ansible.log #开启日志记录
...
[accelerate] #ansible连接加速配置
#accelerate_port = 5099
accelerate_port = 10000
...
accelerate_multi_key = yes
...
deprecation_warnings = False #屏蔽弃用告警提示,减少不必要的信息显示
...
四、测试
[root@centos75 ~]# ansible all -m ping
192.168.1.20 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.1.18 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.1.19 | SUCCESS => {
"changed": false,
"ping": "pong"
}
上述信息表明ansible管理对象已全部ping通,ansible配置正常。
五、使用示例
(1) Ad-Hoc模式:
修改Hadoop三台集群服务器的/etc/hosts文件:
[root@centos75 ~]# vi hosts
#127.0.1.1 hadoop-master
192.168.1.18 hadoop-master
192.168.1.19 hadoop-slave1
192.168.1.20 hadoop-slave2
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
~
[root@centos75 ~]# ansible hadoop -m copy -a "src=/root/hosts dest=/etc/hosts"
192.168.1.20 | SUCCESS => {
"changed": true,
"checksum": "214f72ce3329805c07748997e11313fffb03f667",
"dest": "/etc/hosts",
"gid": 0,
"group": "root",
"md5sum": "127193e1ec4773ce0195636c5ac2bf3a",
"mode": "0644",
"owner": "root",
"size": 298,
"src": "/root/.ansible/tmp/ansible-tmp-1536384515.76-109467000571031/source",
"state": "file",
"uid": 0
}
192.168.1.18 | SUCCESS => {
"changed": true,
"checksum": "214f72ce3329805c07748997e11313fffb03f667",
"dest": "/etc/hosts",
"gid": 0,
"group": "root",
"md5sum": "127193e1ec4773ce0195636c5ac2bf3a",
"mode": "0644",
"owner": "root",
"size": 298,
"src": "/root/.ansible/tmp/ansible-tmp-1536384515.74-269105082907411/source",
"state": "file",
"uid": 0
}
192.168.1.19 | SUCCESS => {
"changed": true,
"checksum": "214f72ce3329805c07748997e11313fffb03f667",
"dest": "/etc/hosts",
"gid": 0,
"group": "root",
"md5sum": "127193e1ec4773ce0195636c5ac2bf3a",
"mode": "0644",
"owner": "root",
"size": 298,
"src": "/root/.ansible/tmp/ansible-tmp-1536384515.75-259083114686776/source",
"state": "file",
"uid": 0
}
还可使用命令查看各客户机hosts文件内容:
ansible hadoop -m shell -a 'cat /etc/hosts'
ansible hadoop -m shell -a 'ls -lhat /etc/hosts'
(2) playbook剧本模式:
启动Hadoop集群服务:
[root@centos75 ~]# vi hadoop-start.yml
---
#“---”符号在yml文件中只能在开头出现一次,多次出现会报错;另外,此符号省略也可,不知为何,待继续研究...
- hosts: hadoop
#注意:“-”符号后必须有空格;“:”后面也必须有空格。
tasks:
#注意:缩进按两个空格规范,不能使用TAB!
- name: startup hadoop datanode services
shell: /root/hadoop-2.7.3/sbin/hadoop-daemon.sh start datanode #尽管集群服务器上已配置hadoop-2.7.3/sbin的环境变量,但这里必须使用绝对路径
- hosts: 192.168.1.18
tasks:
- name: startup hadoop namenode services
shell: /root/hadoop-2.7.3/sbin/hadoop-daemon.sh start namenode
~
[root@centos75 ~]# ansible-playbook hadoop-start.yml
PLAY [hadoop] ******************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.1.20]
ok: [192.168.1.19]
ok: [192.168.1.18]
TASK [startup hadoop datanode services] ****************************************
changed: [192.168.1.19]
changed: [192.168.1.18]
changed: [192.168.1.20]
PLAY [192.168.1.18] ************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.1.18]
TASK [startup hadoop namenode services] ****************************************
changed: [192.168.1.18]
PLAY RECAP *********************************************************************
192.168.1.18 : ok=4 changed=2 unreachable=0 failed=0
192.168.1.19 : ok=2 changed=1 unreachable=0 failed=0
192.168.1.20 : ok=2 changed=1 unreachable=0 failed=0
可在集群服务器上观察服务启动情况:
root@hadoop-master:~# jps
8976 DataNode
9231 Jps
9093 NameNode
root@hadoop-slave1:~# jps
7058 Jps
6972 DataNode
停止hadoop集群服务:
[root@centos75 ~]# vi hadoop-stop.yml
---
- hosts: hadoop
tasks:
- name: stop hadoop datanode services
shell: /root/hadoop-2.7.3/sbin/hadoop-daemon.sh stop datanode
- hosts: 192.168.1.18
tasks:
- name: stop hadoop namenode services
shell: /root/hadoop-2.7.3/sbin/hadoop-daemon.sh stop namenode
~
[root@centos75 ~]# ansible-playbook hadoop-stop.yml
PLAY [hadoop] ******************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.1.20]
ok: [192.168.1.19]
ok: [192.168.1.18]
TASK [stop hadoop datanode services] *******************************************
changed: [192.168.1.20]
changed: [192.168.1.19]
changed: [192.168.1.18]
PLAY [192.168.1.18] ************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.1.18]
TASK [stop hadoop namenode services] *******************************************
changed: [192.168.1.18]
PLAY RECAP *********************************************************************
192.168.1.18 : ok=4 changed=2 unreachable=0 failed=0
192.168.1.19 : ok=2 changed=1 unreachable=0 failed=0
192.168.1.20 : ok=2 changed=1 unreachable=0 failed=0
上述过程可看出,ansible已实现了对集群服务启停作业的集中控制。
使用ansible控制Hadoop服务的启动和停止的更多相关文章
- 通过命令窗口控制mysql服务的启动与停止
mysql服务的启动: 以管理员的身份运行cmd命令窗口,输入命名 net start mysql 如果不是以管理员的身份运行cmd,会提示如下错误 mysql服务的停止: 以管理员的身份运行cmd命 ...
- Centos7.3_x86_64通过systemctl控制tomcat8.0.46启动和停止
Centos7.3_x86_64通过systemctl控制tomcat8..46启动和停止 之前在centos 6上通过脚本控制tomcat 启动和停止的脚本,虽然在centos 7也可以使用,但ce ...
- Linux上服务的启动,停止和重启
(1)查看所有的服务 [berry@berry:practice] service Usage: service < option > | --status-all | [ service ...
- mysql服务的启动和停止 net stop mysql net start mysql
第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名-p用户密码 键入命令mysql -uroo ...
- Windows服务之启动、停止、暂停、继续
原文:Windows服务之启动.停止.暂停.继续 Windows服务之启动.停止.暂停.继续 2011-11-09 15:07:37 我来说两句 收藏 我要投稿 [字体:小 大] ...
- Jenkins关闭、重启,Jenkins服务的启动、停止方法。
一.Jenkins关闭.重启 1.关闭Jenkins 只需要在访问jenkins服务器的网址url地址后加上exit,关闭Jenkins服务. 例如:http://localhost:8081/ex ...
- 管理weblogic服务的启动和停止
2012-11-10 12:58 26036人阅读 评论(4) 收藏 举报 分类: WebLogic(10) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 介绍 Weblog ...
- linux系统下apache服务的启动、停止、重启命令
本文章简单的介绍了关于linux下在利用命令来操作apache的基本操作如启动.停止.重启等操作,对入门者不错的选择.本文假设你的apahce安装目录为 usr local apache2,这些方法适 ...
- hadoop历史服务的启动与停止
a.配置项(在分布式环境中配置) 1.RPC访问地址 mapreduce.jobhistory.address 2.HTTP访问地址 mapreduce.jobhistory.webapp.addre ...
随机推荐
- 送你一份Redis书单,以后使用缓存的问题不用再问我啦!
点击蓝色"程序员书单"关注我哟 加个"星标",每天带你读好书!
- 【Scala】代码实现Actor多种需求
文章目录 简单实现Actor并发编程 使用Actor实现发送没有返回值的异步消息 使用Actor实现不间断消息发送 用react方法替代receive方法接收消息 结合case class,通过匹配不 ...
- Qt 操作sql server数据库
添加qtsql的库 连接数据库 QSqlDatabase_db = QSqlDatabase::addDatabase("QODBC"); _db.setHostName(); _ ...
- C:__attribute__ weak 的作用
关于 weak weak经常出现在各种c代码中,其作用是将当前文件的对应函数声明为弱函数符号,如果外部文件出现相同的函数名,最终编译出来的 文件会优先指向外部文件的函数符号: 通常需要使用__attr ...
- Linux内核驱动学习(九)GPIO外部输入的处理
文章目录 前言 设备树 两个结构体 gpio_platform_data gpio_demo_device 两种方式 轮询 外部中断 总结 附录 前言 前面是如何操作GPIO进行输出,这里我重新实现了 ...
- Java中Error和Exception的异同以及运行时异常(Runtime exception)与检查型异常(checked exception)的区别
一:Error和Exception的基本概念: 首先Exception和Error都是继承于Throwable 类,在 Java 中只有 Throwable 类型的实例才可以被抛出(throw)或者捕 ...
- 初探Redis-基础类型Hash
Redis存在五种基础类型:字符串(String).队列(List).哈希(Hash).集合(Set).有序集合(Sorted Set).本次列举出Hash的常用操作. Redis官网:https:/ ...
- SpringCloud Netflix (五) : Hystrix 服务熔断和服务降级
什么是Hystrix 在分布式环境中,许多服务依赖项中的一些服务依赖不可避免地会失败.Hystrix是一个库,通过添加延迟容忍和容错逻辑,帮助您控制这些分布式服务之间的交互.Hystrix通过隔离服务 ...
- AJAX一
一.http协议 1.URL http://www.baidu.com/md/index.html 结构:协议+主机名称+目录结构+文件名称 URL完整的结构 <scheme>://< ...
- EF Join连接查询的坑
最近做项目的时候遇到一个需要级联查询的数据,表中又没有定义相关的外键约束,所以限定了咱们只能使用Join方式的关联而不是Include的方式关联,关于Include和Join的详细用法,本屌就不再此处 ...