• 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

  • 相关阅读:
    SQL Server 用户管理:用 SQL 语句创建数据库用户(SQL Server 2005)
    主题:[Android API学习]AppWidget
    Android UriMatcher ContentUris
    Python的startswith和endswith
    Android编写测试数据库类时对AndroidMainfest文件进行配置
    Oracle数据库设置默认表空间问题
    Android 设置部分的字体的颜色
    Oralce函数经典 日期函数日期加减法
    PKU2593给出一串数字使得其中两个子段和最大
    边框小合集
  • 原文地址:https://www.cnblogs.com/xuyingzhong/p/8450249.html
Copyright © 2020-2023  润新知