ansible编译安装nginx

---
- hosts: 10.0.0.171
  vars:
     nginxver: 1.18.0
     nginxsrc: "http://nginx.org/download/nginx-{{nginxver}}.tar.gz"
     srcdir: "/usr/local/src/nginx-{{nginxver}}"
     appdir: "/apps/nginx-{{nginxver}}"
  tasks:
      - name: get cpus
        shell: lscpu | awk '/^CPU\(s\)/{print $2}'
        register: cpus
      - name: install necessary packs
        yum: 
          name: 
            - gcc 
            - pcre-devel 
            - openssl-devel 
            - zlib-devel
      - name: download nginx and unarchive
        unarchive: remote_src=yes src={{nginxsrc}} dest=/usr/local/src
        register: var1
        until: var1 is succeeded
        retries: 5
      - name: create user nginx
        user: name=nginx state=present shell=/sbin/nologin system=yes
      - name: create dir
        file: path={{appdir}} state=directory owner=nginx group=nginx
      - name: configure
        shell: |
           chdir={{srcdir}}
           ./configure --prefix={{appdir}} \
           --user=nginx \
           --group=nginx \
           --with-http_ssl_module \
           --with-http_v2_module \
           --with-http_realip_module \
           --with-http_stub_status_module \
           --with-http_gzip_static_module \
           --with-pcre \
           --with-stream \
           --with-stream_ssl_module \ 
           --with-stream_realip_module
           make -j {{cpus.stdout}} && make install
      - name: chown
        file: path={{appdir}} state=directory owner=nginx group=nginx recurse=yes
      - name: create soft link
        file: src={{appdir}}/sbin/nginx path=/usr/bin/nginx state=link
      - name: create service
        copy: 
           content: | 
              [Unit]
              Description=nginx - high performance web server
              Documentation=http://nginx.org/en/docs/
              After=network-online.target remote-fs.target nss-lookup.target
              Wants=network-online.target
              [Service]
              Type=forking
              PIDFile={{appdir}}/run/nginx.pid
              ExecStart={{appdir}}/sbin/nginx -c {{appdir}}/conf/nginx.conf
              ExecReload=/bin/kill -s HUP $MAINPID
              ExecStop=/bin/kill -s TERM $MAINPID
              [Install]
              WantedBy=multi-user.target
           dest: /usr/lib/systemd/system/nginx.service
      - name: create pid dir
        file: path={{appdir}}/run/ state=directory owner=nginx group=nginx
      - name: change config file1
        lineinfile: path={{appdir}}/conf/nginx.conf regexp="^#pid" line="pid   {{appdir}}/run/nginx.pid;"
      - name: change config file2
        lineinfile: path={{appdir}}/conf/nginx.conf regexp="^#user" line="user nginx nginx;"
      - name: change config file3
        lineinfile: path={{appdir}}/conf/nginx.conf regexp="^worker_processes" line="worker_processes {{cpus.stdout}};"
      - name: start nginx
        service: name=nginx state=started enabled=yes  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值