栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Ansible 自动化部署openresty

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Ansible 自动化部署openresty

当你拿到几十台服务器都要安装openresty的时候是不是懵了,不要怕,下面教你一键部署,前提是,你得安装Ansible,如果不会Ansible,关注我,带你从入门到放弃。

安装前需准备文件:

openresty-1.17.8.2.tar.gz

openssl-1.1.1h.tar.gz

pcre-8.44.tar.gz

perl-5.32.0.tar.gz

zlib-1.2.11.tar.gz

openresty.service

以下是ansible-playbook的剧本文件,保存为:install_openresty.yml

---
- name: install openresty
  gather_facts: False
  hosts: "{{ ip }}"
  user: root
  tasks:
    - name: Create the dir
      file: path={{ item }} state=directory
      with_items:
        - /opt/openresty/
    - name:  copy package
      copy: src={{ item.src }} dest={{ item.dest }} mode='0755'
      with_items:
      - {src: "openresty-1.17.8.2.tar.gz",dest: "/opt/openresty/"}
      - {src: "openssl-1.1.1h.tar.gz",dest: "/opt/openresty/"}
      - {src: "perl-5.32.0.tar.gz",dest: "/opt/openresty/"}
      - {src: "pcre-8.44.tar.gz",dest: "/opt/openresty/"}
      - {src: "zlib-1.2.11.tar.gz",dest: "/opt/openresty/"}
      - {src: "openresty.service",dest: "/usr/lib/systemd/system/"}
    - name: unarchive openresty
      unarchive: src=/opt/openresty/openresty-1.17.8.2.tar.gz dest=/opt/openresty/ copy=no
    - name: unarchive openssl
      unarchive: src=/opt/openresty/openssl-1.1.1h.tar.gz dest=/opt/openresty/ copy=no
    - name: unarchive pcre
      unarchive: src=/opt/openresty/pcre-8.44.tar.gz dest=/opt/openresty/ copy=no
    - name: unarchive zlib
      unarchive: src=/opt/openresty/zlib-1.2.11.tar.gz dest=/opt/openresty/ copy=no
    - name: unarchive perl
      unarchive: src=/opt/openresty/perl-5.32.0.tar.gz dest=/opt/openresty/ copy=no
    - name: install gcc
      shell: yum -y install gcc gcc-c++ zlib
    - name: install perl
      shell: cd /opt/openresty/perl-5.32.0 && ./Configure -de && make && make install
      ignore_errors: yes
    - name: install openresty
      shell: cd /opt/openresty/openresty-1.17.8.2 && ./configure --prefix=/usr/local/openresty --with-zlib=/opt/openresty/zlib-1.2.11 --with-pcre=/opt/openresty/pcre-8.44 --with-stream  --with-openssl=/opt/openresty/openssl-1.1.1h && make && make install
      ignore_errors: yes
    - name: start service 
      shell: systemctl start openresty

将openresty配置为服务,以下是openresty.service内容

[Unit] 
Description=Openrestry daemon

[Service] 
Type=forking 
ExecStart=/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
ExecStop=/usr/local/openresty/nginx/sbin/nginx -s stop
ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload 
KillMode=process 
Restart=on-failure 
RestartSec=42s

[Install] 
WantedBy=multi-user.target

准备好脚本后,执行命令

ansible-playbook install_openresty.yml -e "ip"=""

注:参数 ip 所带的内容为ansible配置的hosts中的主机分组或者ip

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/746733.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号