• ansible利用playbook 部署lamp架构


    搭建参考:ansible批量运维管理-CSDN博客

    定义ansible主机清单

    1. [root@ansible-server ~]# vim /etc/hosts
    2. 192.168.200.129 host01
    3. 192.168.200.130 host02
    4. [root@ansible-server ~]# vim /etc/ansible/hosts
    5. [webserver]
    6. host01
    7. host02

    在ansible端编写index.html,index.php⽂件,及lamp.yml配置⽂件

    1. [root@ansible-server ~]# mkdir playbooklamp
    2. [root@ansible-server ~]# cd playbooklamp/
    3. [root@ansible-server playbooklamp]# vim index.html
    4. [root@ansible-server playbooklamp]# cat index.html
    5. <html>
    6. <head>
    7. <title> 这个一个测试页面</title>
    8. <meta charset="utf-8">
    9. <head>
    10. <body>
    11. 这是一个ansible测试页面!!!
    12. </body>
    13. </html>
    14. [root@ansible-server playbooklamp]# vim index.php
    15. [root@ansible-server playbooklamp]# cat index.php
    16. <?php
    17. phpinfo();
    18. ?>
    19. [root@ansible-server playbooklamp]# vim lamp.yml
    20. [root@ansible-server playbooklamp]# cat lamp.yml
    21. - hosts: 'webserver'
    22. tasks:
    23. - name: "安装lamp需要的软件包"
    24. yum:
    25. name: "{{item}}"
    26. state: installed
    27. with_items:
    28. - apr
    29. - apr-util
    30. - httpd
    31. - httpd-devel
    32. - mariadb
    33. - mariadb-server
    34. - php
    35. - php-mysqlnd
    36. - php-fpm
    37. - name: "传输index.html文件"
    38. copy:
    39. src: ./index.html
    40. dest: /var/www/html/index.html
    41. owner: root
    42. group: root
    43. mode: 0644
    44. - name: "传送index.php文件"
    45. copy:
    46. src: ./index.php
    47. dest: /var/www/html/index.php
    48. owner: root
    49. group: root
    50. mode: 0644
    51. - name: "重启httpd"
    52. service:
    53. name: httpd
    54. state: restarted
    55. - name: "重启mariadb"
    56. service:
    57. name: mariadb
    58. state: restarted
    59. - name: "重启php-fpm"
    60. service:
    61. name: php-fpm
    62. state: restarted
    63. - name: "关闭防火墙和selinux"
    64. block:
    65. - shell: systemctl stop firewalld
    66. ignore_errors: yes
    67. - name: "关闭Selinux"
    68. shell: setenforce 0
    69. ignore_errors: yes
    70. [root@ansible-server playbooklamp]# ansible-playbook lamp.yml --syntax-check
    71. playbook: lamp.yml
    72. [root@ansible-server playbooklamp]#

    运行剧本

    1. [root@ansible-server playbooklamp]# ansible-playbook lamp.yml
    2. PLAY [webserver] **************************************************************************************
    3. TASK [Gathering Facts] ********************************************************************************
    4. ok: [host02]
    5. ok: [host01]
    6. TASK [安装lamp需要的软件包] ***************************************************************************
    7. ok: [host01] => (item=apr)
    8. ok: [host02] => (item=apr)
    9. ok: [host01] => (item=apr-util)
    10. ok: [host02] => (item=apr-util)
    11. ok: [host01] => (item=httpd)
    12. ok: [host02] => (item=httpd)
    13. ok: [host01] => (item=httpd-devel)
    14. ok: [host02] => (item=httpd-devel)
    15. ok: [host01] => (item=mariadb)
    16. ok: [host02] => (item=mariadb)
    17. ok: [host01] => (item=mariadb-server)
    18. ok: [host02] => (item=mariadb-server)
    19. ok: [host01] => (item=php)
    20. ok: [host02] => (item=php)
    21. changed: [host01] => (item=php-mysqlnd)
    22. changed: [host02] => (item=php-mysqlnd)
    23. ok: [host01] => (item=php-fpm)
    24. ok: [host02] => (item=php-fpm)
    25. TASK [传输index.html文件] *****************************************************************************
    26. changed: [host01]
    27. changed: [host02]
    28. TASK [传送index.php文件] ******************************************************************************
    29. changed: [host02]
    30. changed: [host01]
    31. TASK [重启httpd] **************************************************************************************
    32. changed: [host02]
    33. changed: [host01]
    34. TASK [重启mariadb] ************************************************************************************
    35. changed: [host02]
    36. changed: [host01]
    37. TASK [重启php-fpm] ************************************************************************************
    38. changed: [host01]
    39. changed: [host02]
    40. TASK [shell] ******************************************************************************************
    41. changed: [host01]
    42. changed: [host02]
    43. TASK [关闭Selinux] ************************************************************************************
    44. changed: [host01]
    45. changed: [host02]
    46. PLAY RECAP ********************************************************************************************
    47. host01 : ok=9 changed=8 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    48. host02 : ok=9 changed=8 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    49. [root@ansible-server playbooklamp]#

    浏览器访问测试

  • 相关阅读:
    spark封神之路(3)-spark运行架构
    iview表单提交验证特殊组件时需要注意的问题
    R语言机器学习 趋势分析 SMA EMA
    中英文说明书丨艾美捷PEG化蛋白ELISA试剂盒
    Verilog入门学习笔记:Verilog基础语法梳理
    vscode装的一些好用的插件和设置
    如何招到适合自己店铺的淘宝主播
    ByteTrack 论文学习
    作业-11.15
    springboot项目作为静态文件服务器
  • 原文地址:https://blog.csdn.net/WWNY666/article/details/138671511