ansible 编译安装nginx

1、准备安装包

nginx-1.22.0.tar.gz(地址:https://nginx.org/download/)

上传到 /data/nginx 下

 

2、编写剧本

vim nginx.yml

---
- hosts: 192.168.59.103
  remote_user: root

  tasks:
    - name: mkdir
      file: name=/data/nginx state=directory
    - name: copy file
      copy: src=/data/nginx/nginx-1.22.0.tar.gz dest=/data/nginx
    - name: tar
      unarchive: src=/data/nginx/nginx-1.22.0.tar.gz dest=/data/nginx copy=no
    - name: yum
      yum: name=gcc,pcre-devel,zlib-devel,openssl,openssl-devel
    - name: configure
      shell: cd /data/nginx/nginx-1.22.0/ && ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.22.0/ --with-http_stub_status_module --with-http_ssl_module && make &&make install
    - name: link
      shell: ln -s /usr/local/nginx-1.22.0 /usr/local/nginx
    - name: user
      user: shell=/sbin/nologin name=nginx
    - name: start
      shell: /usr/local/nginx/sbin/nginx

 

 3、验证

ansible-playbook  nginx.yml

有一个警告,link有专门的模块,但是不要紧,用shell也可以

或者修改nginx.yml下的

     - name: link
        file: src=usr/local/nginx-1.22.0 name=nginx state=link

 

posted @   leihongnu  阅读(323)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示