美文网首页
[ansible]yum之安装服务

[ansible]yum之安装服务

作者: Franckisses | 来源:发表于2018-12-26 15:16 被阅读2次

ansible批量装服务

我们在维护服务器的时候,有的时候为了部署新的项目,要去给主机装一些软件,就像apache。我们怎么能够很快的实现呢?

在ansible中有一个模块叫做yum。我们可以通过这个模块来实现对主机进行批量操作。

我们先看看ansible-doc 的文档:

state
Whether to install (`present' or `installed', `latest'), 
or remove (`absent' or `removed') a package.
(Choices: present, installed, latest, absent, removed)[Default: present]

yum 模块:
删除软件包:

ansible db -m  yum -a “name=‘httpd’ state=‘removed’”

安装软件包:

anible db -m yum -a “name=‘httpd’ state='installed'”

这样就可安装好服务了。

在我们安装好之后呢,就要开始启动服务。

启动服务:

 ansible db -m service -a ‘name=“httpd” state=“started”’

暂停服务

ansible db -m service -a ‘name=“httpd” state=“stopped”’

重启服务:

ansible db -m service -a ‘name=“httpd” state=“restarted”’

好了,到这我们要去验证一下。
装一个apache:

[root@ansible ansible]# ansible web1 -m yum -a 'name="httpd" state=installed'

启动服务:

[root@ansible ansible]# ansible web1 -m service -a 'name="httpd" state="started"'

写入网页:

  [root@ansible ansible]# echo "hello" >> index.html
  [root@ansible ansible]# ansible web1 -m copy -a "src='/etc/ansible/index.html' dest='/var/www/html/'"

验证:

  [root@ansible ansible]# curl web1
  hello

这样就完成了配置。

相关文章

网友评论

      本文标题:[ansible]yum之安装服务

      本文链接:https://www.haomeiwen.com/subject/qluhlqtx.html