使用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 ...
随机推荐
- 使用 vi 命令创建一个cpp文件
mkdir text //创建一个text的文件夹 cd text //打开text的文件夹 vi text.cpp //创建text.cpp 按住 i 键输入程序 输入后按esc,再按wq退出 ls ...
- CC2530应用——按键控制灯光状态变化
独立新建工程并编写.编译代码,实现按键控制灯光闪烁状态的变换,实现以下任务要求:[1]程序开始运行:D4灯闪烁,D3.D5.D6灯熄灭.[2]按下模块上的SW1按键松开后,实现D5.D6灯轮流闪烁.[ ...
- http协议跟tcp协议的简单理解
在说明这两个协议之前,我们先简单说一下网络的分层. 1)应用层 支持网络应用,应用协议仅仅是网络应用的一个组成部分,运行在不同主机上的进程则使用应用层协议进行通信.主要的协议有:http.ftp.te ...
- linux下在用python向文件写入数据时'\n'不起作用
网上翻看一圈,大家都说利用write写数据换行,在linux下用'\n',windows下利用'\r\n',可是尝试了一下,'\n'在windows底下可换行,在linux底下居然不起作用,最后利用' ...
- layui里面的layer模块弹窗,强制居中的方法!!!
每次调用layer弹窗做动态展示的时候,只要内容不固定或者需要二次渲染 比如layui.form.render()进行渲染的时候 由于弹窗已经出来了,只是content部分的结构改变了宽度或者高度,l ...
- 【漫画】JAVA并发编程 如何解决原子性问题
原创声明:本文转载自公众号[胖滚猪学编程],转载务必注明出处! 在并发编程BUG源头文章中,我们初识了并发编程的三个bug源头:可见性.原子性.有序性.在如何解决可见性和原子性文章中我们大致了解了可见 ...
- 谈谈R语言的缺点和优点
编码不友好,对中文不友好,逼着你用RStudio.Jupyter Notebook/Jupyter Lab.图标丑,每次点击感觉辣眼睛. 为节省内存,R语言计算默认有效数字为7位,比Excel的15位 ...
- java ->Date、DateFormat、Calendar类
Date类概述 类 Date 表示特定的瞬间,精确到毫秒. 毫秒概念:1000毫秒=1秒 毫秒的0点: System.currentTimeMillis() 相当于Date d = new Date ...
- C# Sign In With Apple苹果登陆后端验证
苹果App授权登录 苹果官方的授权文档: 生成Token:https://developer.apple.com/documentation/sign_in_with_apple/generate_a ...
- 【雕爷学编程】Arduino动手做(47)---七段LED数码管模块
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践(动手试试)出真知的理念,以学习和交流为目的,这里准备 ...