• 第七章 Ansible模块搭建作业平台


    一、上传包

    1.上传php.tar.gz
    2.上传代码包kaoshi.zip
    

    二、配置主机清单

    [root@m01 ~]# vim /etc/ansible/hosts
    [web_group]
    web01 ansible_ssh_password='1'
    [nfs_group]
    nfs ansible_ssh_password='1'
    
    #配置hosts
    [root@m01 ~]# vim /etc/hosts
    172.16.1.7 web01
    172.16.1.31 nfs
    

    三、编写配置文件

    [root@m01 ~]# vim /etc/httpd/conf/httpd.conf
    User www
    Group www
    
    [root@m01 ~]# cp /etc/httpd/conf/httpd.conf ./
    

    四、编写ansible脚本

    #1.安装httpd
    ansible 'web_group' -m yum -a 'name=httpd state=present' &&\
    #2.解压php.tar.gz
    ansible 'web_group' -m unarchive -a 'src=/root/php.tar.gz dest=/tmp/' &&\
    #3.安装php
    ansible 'web_group' -m shell -a 'yum localinstall -y /tmp/*.rpm' &&\
    #4.解压代码
    ansible 'web_group' -m unarchive -a 'src=/root/kaoshi.zip dest=/var/www/html' &&\
    #5.创建文件上传目录
    ansible 'web_group' -m file -a 'path=/var/www/html/upload state=directory' &&\
    #6.创建用户组
    ansible 'all' -m group -a 'name=www gid=666 state=present' &&\
    #7.创建用户
    ansible 'all' -m user -a 'name=www uid=666 group=www state=present' &&\
    #8.授权代码目录
    ansible 'web_group' -m file -a 'path=/var/www state=directory owner=www group=www recurse=yes' &&\
    #9.配置httpd
    ansible 'web_group' -m copy -a 'src=/root/httpd.conf dest=/etc/httpd/conf/' &&\
    #10.启动httpd
    ansible 'web_group' -m systemd -a 'name=httpd state=started enabled=yes' &&\
    #11.安装nfs服务端
    ansible 'nfs_group' -m yum -a 'name=nfs-utils state=present' &&\
    #12.配置nfs
    ansible 'nfs_group' -m copy -a 'content="/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" dest=/etc/exports' &&\
    #13.创建共享目录
    ansible 'nfs_group' -m file -a 'path=/data state=directory owner=www group=www' &&\
    #14.启动NFS
    ansible 'nfs_group' -m systemd -a 'name=nfs state=started' &&\
    #15.挂载
    ansible 'web_group' -m mount -a 'src=172.16.1.31:/data path=/var/www/html/upload fstype=nfs opts=defaults state=mounted'
    
  • 相关阅读:
    快速读取txt文档
    ASP.NET中缓存非SQLServer数据库数据
    查看linq to sql 生成的sql 语句
    跟树有关的数据结构学习系列之概览
    Linux安装软件包时的“依赖关系树”算法(C#)
    Go调度器介绍和容易忽视的问题
    搞懂Go垃圾回收
    Go“一个包含nil指针的接口不是nil接口”踩坑
    Go slice:切片的“陷阱”和本质
    C#调用ODBC连接SQL Server数据库的存储过程
  • 原文地址:https://www.cnblogs.com/jhno1/p/15723188.html
Copyright © 2020-2023  润新知