ansible-playbook进阶之nginx部署及优化

本文介绍了如何使用Ansible 2.4.2.0版本的playbook进行Nginx的部署,并提供了具体的配置文件示例,通过实际测试验证了部署与优化的效果。
摘要由CSDN通过智能技术生成

ansible-playbook进阶之nginx部署及优化

环境说明

ansible版本:
[root@ansible ~]# ansible --version
ansible 2.4.2.0

Playbook 示范:

[root@ansible ~]# cat  nginx.yml                                                          ★ --Virtual Machine--★ 
---
- hosts: web
  remote_user: root
  tasks: 
    - yum: 
        name: "{{item}}"
      with_items: ["gcc" ,"make" ,"openssl-devel" ,"pcre-devel" ,"zlib-devel","wget","mariadb-server","php-mysql"]
    - shell: 
        wget https://github.com/TANRONGSheng/openstack/blob/master/lnmp_soft/nginx-1.12.2.tar.gz
    - shell: 
        wget https://github.com/TANRONGSheng/openstack/blob/master/lnmp_soft/php-fpm-5.4.16-42.el7.x86_64.rpm
    - yum: 
        name: php-fpm-5.4.16-42.el7.x86_64.rpm
    - service: 
        name: mariadb
        state: started 
        enabled: yes
    - service: 
        name: php-fpm
        state: started
        enabled: yes
    - shell: 
        tar xf  /root/nginx-1.12.2.tar.gz
    - user:
        name: nginx
        shell: /sbin/nologin
    - script: /root/nginx.sh
    - copy:
        src: /root/nginx.conf
        dest: /usr/local/nginx/conf/nginx.conf
        owner: nginx
        group: nginx
        mode: 0644
    - shell: 
        nginx

这里面引用的nginx的相应配置文件自备

测试结果:

[root@ansible ~]#  curl -i   http://web1/
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 19 Apr 2019 12:56:00 GMT
Content-Type: text/html; charset=koi8-r
Content-Length: 72
Last-Modified: Fri, 19 Apr 2019 12:55:54 GMT
Connection: keep-alive
ETag: "5cb9c55a-48"
Accept-Ranges: bytes

O_o  --->  Ansible -playbook advanced nginx deployment and optimization
[root@ansible ~]#  curl -i   http://web2/
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 19 Apr 2019 12:56:12 GMT
Content-Type: text/html; charset=koi8-r
Content-Length: 72
Last-Modified: Fri, 19 Apr 2019 12:55:54 GMT
Connection: keep-alive
ETag: "5cb9c55a-48"
Accept-Ranges: bytes

O_o  --->  Ansible -playbook advanced nginx deployment and optimization

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值