Ansible部署lanm

添加受管主机

[root@localhost ansible]# cat cctv
[http]
192.168.100.42 ansible_user=root ansible_password=1
[php]
192.168.100.43 ansible_user=root ansible_password=1
[mysql]
192.168.100.44ansible_user=root ansible_password=1 

测试能否ping通

[root@localhost ansible]# ansible all -m ping
192.168.100.42 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"
}
192.168.100.43 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"
}
192.168.100.44 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"
}

下载和配置httpd、php、mysql

[root@localhost ansible]# ansible 192.168.100.42 -m yum -a 'name=httpd state=present'   #下载http服务
192.168.100.42 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"msg": "","rc": 0,"results": ["Installed: httpd-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64","Installed: mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64"]
}[root@localhost ansible]# ansible 192.168.100.43-m yum -a 'name=php* state=present'   #下载php服务
192.168.100.43| CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"msg": "","rc": 0,"results": ["Installed: php-intl-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64","Installed: php-json-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64",
········"Installed: glibc-headers-2.28-161.el8.x86_64","Installed: php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64","Installed: pcre-utf32-8.42-6.el8.x86_64","Installed: php-gd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64","Installed: php-gmp-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64","Removed: pcre-8.42-4.el8.x86_64","Removed: glibc-2.28-141.el8.x86_64","Removed: glibc-common-2.28-141.el8.x86_64","Removed: glibc-langpack-zh-2.28-141.el8.x86_64","Removed: libxcrypt-4.1.1-4.el8.x86_64"]
}[root@localhost ansible]# ansible 192.168.100.44 -m yum -a 'name=mysql state=present' #安装mysql
192.168.100.44 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"msg": "","rc": 0,"results": ["Installed: mariadb-connector-c-config-3.1.11-2.el8_3.noarch","Installed: mysql-8.0.21-1.module_el8.4.0+589+11e12751.x86_64","Installed: mysql-common-8.0.21-1.module_el8.4.0+589+11e12751.x86_64"]
[root@localhost ansible]# ansible 192.168.100.44-m yum -a 'name=mysql-server state=present'
192.168.100.44 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"msg": "","rc": 0,"results": ["Installed: protobuf-lite-3.5.0-13.el8.x86_64","Installed: python3-policycoreutils-2.9-14.el8.noarch","Installed: python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64","Installed: mysql-errmsg-8.0.21-1.module_el8.4.0+589+11e12751.x86_64","Installed: mysql-server-8.0.21-1.module_el8.4.0+589+11e12751.x86_64","Installed: mecab-0.996-1.module_el8.4.0+589+11e12751.9.x86_64","Installed: python3-setools-4.3.0-2.el8.x86_64","Installed: policycoreutils-2.9-14.el8.x86_64","Installed: libsemanage-2.9-6.el8.x86_64","Installed: checkpolicy-2.9-1.el8.x86_64","Installed: policycoreutils-python-utils-2.9-14.el8.noarch","Installed: python3-libsemanage-2.9-6.el8.x86_64","Removed: libsemanage-2.9-4.el8.x86_64","Removed: policycoreutils-2.9-9.el8.x86_64"]
}
[root@localhost ansible]#

配置httpd服务

[root@localhost ansible]# ansible 192.168.100.42 -m lineinfile -a   'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-gzip" line="AddType application/x-httpd-php .php"'
192.168.100.42 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line added"
}
[root@localhost ansible]# ansible 192.168.100.42 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-httpd-php .php" line="AddType application/x-httpd-php-source .phps "'
192.168.100.42 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line added"
}[root@localhost ansible]# ansible 192.168.100.42 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf line="<VirtualHost *:80>\nDocumentRoot "/usr/local/apache/htdocs"\nServerName www.scl.com\nProxyRequests Off\nProxyPassMatch ^/(.*\.php)$ fcgi://192.168.100.43:9000/www/abc/$1\n<Directory "/www/abc/">\nOptions none\nAllowOverride none\nRequire all granted\n</Directory>\n</VirtualHost>"'
192.168.100.42 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line added"
}

配置php服务

[root@localhost ansible]# ansible 192.168.240.50 -m command -a 'touch www/abc/index.php'
[WARNING]: Consider using the file module with state=touch rather than running 'touch'.  If you need to use command because file is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.
192.168.240.50 | CHANGED | rc=0 >>[root@localhost ansible]# ansible 192.168.100.43 -m lineinfile -a 'path=www/abc/index.php line="<?php phpinfo(); ?>"'
192.168.100.43 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line added"
}[root@localhost ansible]# ansible 192.168.100.43 -m lineinfile -a 'path=/etc/php-fpm.d/www.conf insertafter=" Note: This value is mandatory." line=192.168.100.43:9000'
192.168.100.43 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line added"
}

关闭防火墙跟selinux

[root@localhost ansible]# ansible all -m service -a 'name=firewalld  state=stopped'
192.168.100.42 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"name": "firewalld","state": "stopped","status": {
·······
192.168.100.43 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,
·······
192.168.100.44 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"name": "firewalld","state": "stopped","status": {"ActiveState": "active","UMask": "0022","WatchdogTimestamp": "Sat 2021-07-17 07:15:33 EDT","WatchdogTimestampMonotonic": "5128397","WatchdogUSec": "0"}
}[root@localhost ansible]# ansible all -m service -a 'name=selinux state=stopped'
192.168.100.44 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"name": "selinux","state": "stopped","status": {"ActiveState": "inactive","AllowedCPUs": "",
·····
192.168.100.43 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"name": "selinux","state": "stopped","status": {"ActiveState": "inactive","AllowedCPUs": "","AllowedMemoryNodes": "","BlockIOAccounting": "no",
······
192.168.100.42 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"name": "selinux","state": "stopped","status": {"ActiveState": "inactive","AllowedCPUs": "","AllowedMemoryNodes": "",
·······
"TimeoutStartUSec": "1min 30s","TimeoutStopUSec": "1min 30s","TimerSlackNSec": "50000","UID": "[not set]","UMask": "0022","WatchdogTimestampMonotonic": "0","WatchdogUSec": "0"}
}

启动服务

[root@localhost ansible]# ansible 192.168.100.42 -m service -a 'name=httpd state=restarted'
192.168.100.43 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"name": "httpd","state": "started","status": {"ActiveState": "active","AllowedCPUs": "","AllowedMemoryNodes": "",
······"TimerSlackNSec": "50000","Type": "notify","UID": "[not set]","UMask": "0022","WatchdogTimestamp": "Sun 2021-07-17 07:50:43 EDT","WatchdogTimestampMonotonic": "20867005813","WatchdogUSec": "0"}
}[root@localhost ansible]# ansible 192.168.100.43 -m service -a 'name=php-fpm.service state=restarted
> '
192.168.100.43 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"name": "php-fpm.service","state": "started","status": {"ActiveState": "inactive","AllowedCPUs": "","AllowedMemoryNodes": "","BlockIOAccounting": "no","BlockIOWeight": "[not set]",
······"TasksCurrent": "[not set]","TasksMax": "4743","TimeoutStartUSec": "1min 30s","TimeoutStopUSec": "1min 30s","TimerSlackNSec": "50000","Type": "notify","UID": "[not set]","UMask": "0022","WatchdogTimestampMonotonic": "0","WatchdogUSec": "0"}
}

ansible分离部署lamp相关推荐

  1. ansible角色部署lamp架构

    使用ansible角色部署lamp架构 文章目录 使用ansible角色部署lamp架构 一.部署Apache 1.配置主机并创建角色 2.编写task任务 3.编写脚本 4.调用角色 二.部署mys ...

  2. 通过Playbook部署LAMP(5)

    title: 通过Playbook部署LAMP(5) date: 2018-12-03 13:24:07 tags: Ansible categories: Ansible copyright: tr ...

  3. 基于ansible Role实现批量部署lamp平台

    一.ansible Role介绍 # ansilbe自1.2版本引入的新特性,用于层次性.结构化地组织playbook. # roles能够根据层次型结构自动装载变量文件.tasks以及handler ...

  4. CentOS 7.3:LAMP 动静分离部署

    前言 之前写过一篇部署LAMP平台的博文:基于centos 7搭建LNMP架构,只是那个是基于同一台服务器部署的,用来做测试网站或者访问量不大的情况下,是可以应付的,那么?如果该web网站访问量特别大 ...

  5. ansible部署LAMP架构

    简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量 ...

  6. centos 怎么退出init 3_CentOS 7.3:LAMP 动静分离部署

    之前写过一篇部署LAMP平台的博文:基于centos 7搭建LNMP架构,只是那个是基于同一台服务器部署的,用来做测试网站或者访问量不大的情况下,是可以应付的,那么?如果该web网站访问量特别大呢? ...

  7. Ansible使用角色部署LAMP架构

    文章目录 使用角色部署lamp架构 部署apache 编写任务 编写脚本 配置变量 配置模板 编写playbook执行 部署mysql 编写任务 配置变量 编写脚本 编写模板 编写playbook执行 ...

  8. 基于ansible role实现LAMP平台批量部署 - 推酷

    基于ansible role实现LAMP平台批量部署 - 推酷 基于ansible role实现LAMP平台批量部署 - 推酷 posted on 2016-04-07 17:17 lexus 阅读( ...

  9. ansible模块独立部署LAMP

    前言:一般部署lamp是用源码安装的方式部署,ansible实现源码安装lamp一般是写入xxx.yml,但是由于它喵的老睡不着,就准备多熟悉熟悉ansible模块,于是就有了下面的基于模块安装的la ...

最新文章

  1. MindMotion MM32F3277 SoftI2C功能测试
  2. 简单module_深入理解JavaScript之全面解析Module模式
  3. boost::uuid::nil_generator相关的测试程序
  4. cd协议属于计算机网络的应用层,计算机网络 题库 必考 期末 期终 考试 复习 考研 必备...
  5. [MySQL] - 返回影响行数
  6. 【爬虫】爬取带有cookie才能获取网页内容的新闻网站
  7. python382怎么用_教你如何使用Python快速生成验证码
  8. linux部署redis集群遇到的问题
  9. Android编程 不显示菜单,网易MuMu模拟器不显示Menu(菜单)键的解决办法
  10. Go-加密学(四) - 证书/SSL/TLS/https单向认证/思维导图
  11. NFT数字艺术品热潮下,IPFS或成为其最佳的存储解决方案
  12. 关于逆向工程,解决mysql数据库遇到的1406问题,ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'
  13. ResNeXt代码复现+超详细注释(PyTorch)
  14. BootStrap一页通(样式+组件+插件)(全)
  15. QT简单实验——计算器
  16. Adobe Flash player 过期
  17. PLSQL 14.0.6 下载使用教程
  18. 雄迈信息联合华为海思发布H.265AI技术,安防视频更智能
  19. 宝塔Linux面板——用正确的入口登录面板
  20. 合泰 HT66F2390 uart0与uart1 串口代码相互通信

热门文章

  1. 你真的会TVS二极管选型吗
  2. LaTex使用技巧14:插入eps图片
  3. Android AOSP基础(四)Source Insight和Android Studio导入系统源码
  4. STM32物联网项目-DAC输出模拟量以及正弦波
  5. 免费实用的语音朗读软件:朗读女 5.0发布
  6. 远程维护电脑设备,最好用的三款软件评测
  7. ArcSDE常见问题总结(三)
  8. 使用EasyExcel在同一单元格内添加图片和文字,并作格式排版
  9. H5编写Audio音乐播放器——李帅醒博客
  10. 单身、脱发、直男?程序员招黑体质?