zoukankan      html  css  js  c++  java
  • ansible-playbook 编译安装nginx

    mkdir /etc/ansible/roles/nginx/{files,templates,tasks,handlers,vars,default,meta} -pv

    └── nginx

        ├── default

        ├── files

        │ └── nginx-1.12.2.tar.gz

        ├── handlers

        │ └── main.yml

        ├── meta

        ├── tasks

        │ └── main.yml

        ├── templates

        │ ├── index.html.j2

        │ └── nginx.conf.j2

        └── vars

    cat nginx/tasks/main.yml

    - name: copy nginx

      copy: src=nginx-1.12.2.tar.gz dest=/usr/local/src/

    - name: yum pcre pcre-devel openssl openssl-devel zlib zlib-devel gcc-c++

      yum: name={{ item }} state=present

      with_items:

      - pcre

      - pcre-devel

      - openssl

      - openssl-devel

      - zlib

      - zlib-devel

      - gcc-c++

    - name: tar nginx

      shell: chdir=/usr/local/src tar -zxf nginx-1.12.2.tar.gz

    - name: install nginx

      shell: chdir=/usr/local/src/nginx-1.12.2 ./configure && make && make install

    - name: copy nginx.conf

      template: src=nginx.conf.j2 dest=/usr/local/nginx/conf/nginx.conf

    - name: copy index.html

      template: src=index.html.j2 dest=/usr/local/nginx/html/index.html

    - name: open 80

      shell: firewall-cmd --zone=public --add-port=80/tcp --permanent

      notify:

      - restart firewall

    - name: open nginx

      shell: /usr/local/nginx/sbin/nginx

    cat nginx/handlers/main.yml

    - name: restart firewall

      service: name=firewalld state=restarted

    cat nginx/templates/index.html.j2

    <!DOCTYPE html>

    <html>

    <head>

    <title>{{ ansible_all_ipv4_addresses }}</title>

    </style>

    </head>

    <body>

    <h1>This is {{ ansible_fqdn }} index page IP is {{ ansible_all_ipv4_addresses }}</h1>

    </body>

    </html>

     cat nginx/templates/nginx.conf.j2

    #user  nobody;

    worker_processes  {{ ansible_processor_vcpus }}; //其余的没有变

    cat nginx.yml

    - hosts: nginx

     remote_user: root

     roles:

       - nginx

  • 相关阅读:
    设计模式的六大原则 ---- 理论知识
    动手编写TCP服务器系列之一:日志文件
    Shell语言系列之一:文件处理
    给Amazon ec2 增加卷(Volume)并挂载到系统
    Java打包问题之一:打包出现java.io.IOException: invalid header field
    struct中长度为0的数组用途与原理
    child和childNodes的区别
    学习es6 setter/getter研究
    tabIndex-bootstrap中Get到的
    tml兼容性
  • 原文地址:https://www.cnblogs.com/xuyingzhong/p/8450249.html
Copyright © 2011-2022 走看看