前言:一般部署lamp是用源码安装的方式部署,ansible实现源码安装lamp一般是写入xxx.yml,但是由于它喵的老睡不着,就准备多熟悉熟悉ansible模块,于是就有了下面的基于模块安装的lamp,虽然是yum方式安装的包,但是修改的配置文件内容都差不多

因此取名:<anible模块实现独立部署lamp>

1.环境准备
系统 ip地址 名字 安装服务
centos8 192.168.136.99 master ansible
centos8 192.168.136.100 slave01 httpd
centos8 192.168.136.101 slave02 mariadb
centos8 192.168.136.102 slave03 php

注意受管主机是最新环境。

2.安装ansible
#master主机
yum -y install epel-release
yum -y install ansible
#slave[01-03]主机
python3-libselinux
3.master主机进行anisble配置
#受管主机添加清单文件
[root@master ~]# cat /etc/ansible/ansible.cfg
inventory      = /etc/ansible/hosts
[root@master ~]# vim /etc/ansible/hosts
[web1]
192.168.136.100
[web2]
192.168.136.101
[web3]
192.168.136.102#进行免密登录(全部依次做)
[root@master ~]# ssh-copy-id root@192.168.136.101
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.136.101's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'root@192.168.136.101'"
and check to make sure that only the key(s) you wanted were added.
[root@master ~]# ssh-agent bash
[root@master ~]# ssh-add
Enter passphrase for /root/.ssh/id_rsa:
Identity added: /root/.ssh/id_rsa (root@master)
#其它俩个略 步骤一样
4.slave01安装httpd

确保每台机器上都有yum源仓库

利用shell模块进行安装,可以安装全部包

[root@master ~]# ansible web1 -m shell -a "yum -y install httpd*"
192.168.136.100 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"msg": "","rc": 0,"results": ["Installed: mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64","Installed: centos-logos-httpd-85.8-1.el8.noarch","Installed: httpd-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64","Installed: apr-1.6.3-11.el8.x86_64","Installed: httpd-filesystem-2.4.37-40.module_el8.5.0+852+0aafc63b.noarch","Installed: apr-util-1.6.1-6.el8.x86_64","Installed: apr-util-bdb-1.6.1-6.el8.x86_64","Installed: httpd-tools-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64","Installed: apr-util-openssl-1.6.1-6.el8.x86_64"]
}
5.slave02安装mariadb
[root@master ~]# ansible web2 -m shell -a "yum -y install mariadb*"
192.168.136.101 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"changes": {"installed": ["mariadb"]},"msg": "","rc": 0,"results": ["Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\nResolving Dependencies\n--> Running transaction check\n---> Package mariadb.x86_64 1:5.5.68-1.el7 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package          Arch            Version                   Repository     Size\n================================================================================\nInstalling:\n mariadb          x86_64          1:5.5.68-1.el7            RHCE          8.8 M\n\nTransaction Summary\n================================================================================\nInstall  1 Package\n\nTotal download size: 8.8 M\nInstalled size: 49 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : 1:mariadb-5.5.68-1.el7.x86_64                                1/1 \n  Verifying  : 1:mariadb-5.5.68-1.el7.x86_64                                1/1 \n\nInstalled:\n  mariadb.x86_64 1:5.5.68-1.el7                                                 \n\nComplete!\n"
6.slave03安装php
[root@master ~]# ansible web3 -m shell -a "yum -y install php*"
192.168.136.102 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true,"msg": "","rc": 0,"results": ["Installed: mod_http2-1.15.7-3.module_el8.4.0+778+c970deab.x86_64","Installed: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch","Installed: php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64","Installed: php-cli-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64","Installed: apr-1.6.3-11.el8.x86_64","Installed: httpd-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64","Installed: php-common-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64","Installed: apr-util-1.6.1-6.el8.x86_64","Installed: apr-util-bdb-1.6.1-6.el8.x86_64","Installed: httpd-filesystem-2.4.37-40.module_el8.5.0+852+0aafc63b.noarch","Installed: centos-logos-httpd-85.8-1.el8.noarch","Installed: apr-util-openssl-1.6.1-6.el8.x86_64","Installed: httpd-tools-2.4.37-40.module_el8.5.0+852+0aafc63b.x86_64","Installed: php-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64"
..
7.slave01主机(apache)创建用户改变属主(可做可不做)
[root@master ~]# ansible web1 -m user -a "name=apache system=yes create_home=no shell=/sbin/nologin"
192.168.136.100 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"append": false,"changed": false,"comment": "Apache","group": 48,"home": "/usr/share/httpd","move_home": false,"name": "apache","shell": "/sbin/nologin","state": "present","uid": 48
}
[root@slave01 ~]# id apache
uid=48(apache) gid=48(apache) 组=48(apache[root@master ~]# ansible web1 -m shell -a "chown -R apache.apache /var/www/html"
192.168.136.100 | CHANGED | rc=0 >>
[root@slave01 ~]# ll -d /var/www//html/
drwxr-xr-x. 2 apache apache 6 6月  30 04:11 /var/www//html/
8.slave02主机(mariadb)创建用户改变属主(可做可不做)
[root@master ~]# ansible web2 -m user -a "name=mysql system=yes create_home=no shell=/sbin/nologin"
192.168.136.101 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"comment": "","create_home": false,"group": 996,"home": "/home/mysql","name": "mysql","shell": "/sbin/nologin","state": "present","system": true,"uid": 998
}
#slave02改变属主
[root@master ~]# ansible web2 -m shell -a "chown -R mysql:mysql /opt/data"
192.168.136.101 | CHANGED | rc=0 >>
[root@slave02 ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 7月  17 10:52 /opt/data/
9.slave01主机(apache)修改相关配置文件
1.模块功能开启(一般yum安装是开启的)
[root@master ~]# ansible web1 -m shell -a "sed -i '/proxy_module/s/#//g' /etc/httpd/conf.modules.d/00-proxy.conf"
192.168.136.100 | CHANGED | rc=0 >>
LoadModule proxy_module modules/mod_proxy.so
[root@master ~]# ansible web1 -m shell -a "sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd/conf.modules.d/00-proxy.conf"
192.168.136.100 | CHANGED | rc=0 >>
2.取消监听端口注释以及域名注释
[root@master ~]# ansible web1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^#Listen 80" line="Listen 80"'
192.168.136.100 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line replaced"
}
[root@master ~]# ansible web1 -m shell -a "sed -i '/www.example/s/#//g' /etc/httpd/conf/httpd.conf"
192.168.136.100 | CHANGED | rc=0 >>
3.添加俩行内容(\n:换行)
[root@master ~]# ansible web1 -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf regexp="^AddType" line="AddType application/x-httpd-php .php\nAddType application/x-httpd-php-source .phps"'
192.168.136.100 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line added"
}
4.index.html前面加index.php(其它的模块都试了不行,只有这个方式,晕)
[root@master ~]# ansible web1 -m shell -a "sed -i '/index.html/s/index.html/index.php index.html/g' /etc/httpd/conf/httpd.conf"
5.找到vhosts.conf文件复制到/etc/httpd/conf.d/下
[root@master ~]# ansible web1 -m shell -a "find / -name *vhosts.conf"
192.168.136.100 | CHANGED | rc=0 >>
/usr/share/doc/httpd/httpd-vhosts.conf
[root@master ~]# ansible web1 -m shell -a "mv /usr/share/doc/httpd/httpd-vhosts.conf /etc/httpd/conf.d/"
192.168.136.100 | CHANGED | rc=0 >>
6.修改虚拟配置文件
[root@master ~]# ansible web1 -m shell -a ">  /etc/httpd/conf.d/httpd-vhosts.conf"
192.168.136.100 | CHANGED | rc=0 >>                                 (先清空默认的配置文件内容)
[root@master ~]# ansible web1 -m lineinfile -a 'path=/etc/httpd/conf.d/httpd-vhosts.conf line="<VirtualHost *:80>\n    DocumentRoot "/var/www/html"\n    ServerName clq.com\n    ProxyRequests Off\n    ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.136.102:9000/data/php/$1\n    <Directory "/data/php/">\n      Options none\n      AllowOverride none\n      Require all granted\n    </Directory>\n</VirtualHost>"'
192.168.136.100 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"backup": "","changed": true,"msg": "line added"
}
#slave01上查看
[root@slave01 ~]#  cat /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost *:80>DocumentRoot "/var/www/html"ServerName www.clq.comProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://192.168.136.102:9000/data/php/$1<Directory "/data/php/">Options noneAllowOverride noneRequire all granted</Directory>
</VirtualHost>
10.slave02mysql开机自启
#开启mariadb
[root@master ~]# ansible web2 -m service -a "name=mysql.service state=present enabled=yes"
11.slave03修改相关配置文件
#创建文件,并且输入如下内容
[root@master ~]# ansible web3-m lineinfile -a "path=/data/php/index.php line=<?php\n    phpinfo();\n?> create=yes"
#修改/etc/php-fpm.d/www.conf文件
[root@master ~]# ansible web3 -m shell -a "sed -i '/www.sock/s/listen/;listen/g' /etc/php-fpm.d/www.conf"
[root@master ~]# ansible web3 -m shell -a "sed -i '/clients/s/12.0.0.1/192.168.136.129/g' /etc/php-fpm.d/www.conf"
12.启动httpd和php
[root@master ~]# ansible web1 -m shell -a "systemctl start httpd.service"
[root@master ~]# ansible web3 -m shell -a "systemctl start php-fpm.service"
13.slave[1-3]关闭防火墙
[root@master ~]# ansible all -m shell -a "systemctl stop firewalld"
[root@master ~]# ansible all -m shell -a "systemctl disable firewalld"
[root@master ~]# ansible all -m shell -a "setenforce 0"
14.域名添加,查看效果



ansible模块独立部署LAMP相关推荐

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

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

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

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

  3. ansible部署LAMP架构

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

  4. ruoyi 多模块部署_大数据时代,独立部署的商城系统具有哪些优势?

    独立部署是把一个可部署软件包安装到一个指定IT环境上并让其按预定流程提供服务的过程. 现如今,越来越多的商家开始搭建网上商城系统,从而为自己积攒多年的客户群体提供更为便捷的购物模式,让购物变得更加智能 ...

  5. ansible角色部署lamp架构

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

  6. 通过Playbook部署LAMP(5)

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

  7. 部署LAMP论坛平台(Linux,Apache,MySQL,PHP)

    文章目录 部署LAMP论坛平台 apache(Web服务器) mySQL(关系型数据库管理系统) PHP(超文本预处理器) 环境准备 部署Apache平台 安装编译器和其他工具 configure配置 ...

  8. ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建

    文章目录 ansible自动化运维详解(一)ansible的安装部署.参数使用.清单管理.配置文件参数及用户级ansible操作环境构建 一.ansible的安装部署 1.1.ansible简介 1. ...

  9. Spark 独立部署模式

    2019独角兽企业重金招聘Python工程师标准>>> Spark 独立部署模式 博客分类: spark 除了在 Mesos 或 YARN 集群上运行之外, Spark 还提供一个简 ...

最新文章

  1. 如何在Android Studio中查看方法信息?
  2. WinForm 窗体圆角、平角(不规则窗体)实现的几种方法
  3. linux定时任务crontab
  4. jQuery的var let const
  5. React + fetch API + 百度地图api + 跨域 填坑
  6. 使用Chatkit构建Node.js命令行聊天应用程序
  7. bouncycastle NoSuchFieldError:xxx 版本冲突
  8. 速成pytorch学习——3天自动微分机制
  9. 【分享】小工具大智慧之Sql执行工具
  10. notepad++反向查找/向上查找
  11. 关于numpy的一些矩阵运算——tile函数
  12. Dxg——python MicroPython 开发笔记整理分类合集【所有的相关记录,都整理在此】
  13. NOI模拟(5.8) HNOID2T3 道路 (bzoj5290)
  14. bin文件夹下的roslyn文件夹
  15. java string 返回方法_Java语言中,String类的IndexOf()方法返回的类型是()_学小易找答案...
  16. 阿根廷探戈----中英文对照
  17. 我在windows10下,使用CMake gui 编译krita源码
  18. cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-1y7gm6kn\opencv\modul
  19. java输出中写html标签,java 输出html标签
  20. css设overflow:hiden行内元素会发生偏移的现象

热门文章

  1. 2022.3.7-3.13 AI行业周刊(第88期):离职与告别
  2. Android连接可用WIFI后显示“Connected, no Internet”原因以及解决方案
  3. 现代CMake高级教程
  4. MATLAB 神经网络预测工具箱
  5. HTML 基础知识——8月8日
  6. prometheus 添加 login 登录认证界面(nginx + flask 实现)
  7. MySQL之多表查询
  8. sharepoint页面嵌入_Part 1: 如何把Power BI 嵌入到sharepoint 网站
  9. 二进制二维码转换图片
  10. 哈希函数处理冲突的方法