zoukankan      html  css  js  c++  java
  • 第十六周运维作业

    1、使用ansible的playbook实现自动化安装httpd

    环境主控端192.168.47.154 ,被控端192.168.47.{1,2}7

    安装ansible 软件包,关闭selinux;firewalld;date 时间同步

    [root@centos7 ~]# yum install ansible

    [root@centos7 ~]# mkdir /data/playbook/

    [root@centos7 ~]# vim /data/playbook/httpd.yml

    ---

     - hosts: websrvs

       remote_user: root

       tasks:

         - name: install

           yum: name=httpd

         - name: config

           shell: sed -i 's/Listen .*/^Listen 9527/' /etc/httpd/conf/httpd.conf

         - name: service

           service: name=httpd state=started enabled=yes

    :wq

    [root@centos7 ~]# ansible-playbook /data/playbook/httpd.yml --check –C 检查不操作

     

    [root@centos7 ~]# ansible-playbook /data/playbook/httpd.yml  执行

     

    成功

    [root@centos7 playbook]# ansible websrvs -m shell  -a "ss -nult "  验证

    [root@centos7 playbook]# ansible websrvs -m shell  -a "systemctl status httpd "

    [root@centos7 playbook]# ansible websrvs -m shell  -a "cat /etc/httpd/conf/httpd.conf|grep Listen " 查看结果

      

    2、建立httpd服务器,要求提供两个基于名称的虚拟主机: 

    (1)www.X.com,页面文件目录为/web/vhosts/x;错误日志为/var/log/httpd/x.err,访问日志为/var/log/httpd/x.acces 

    (2)www.Y.com,页面文件目录为/web/vhosts/y;错误日志为 /var/log/httpd/www2.err,访问日志为/var/log/httpd/y.access

    (3)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名

    服务端192.168.47.17 ,环境安装httpd

    [root@centos7 ~]# mkdir -pv /web/vhosts/{x,y}

    [root@centos7 ~]# echo www.X.com > /web/vhosts/x/index.html
    [root@centos7 ~]# echo www.Y.com > /web/vhosts/y/index.html

    [root@centos7 ~]# vim /etc/httpd/conf.d/test.conf

    <virtualhost *:80>
    documentroot /web/vhosts/x
    CustomLog "/var/log/httpd/x.access" combined
    ErrorLog "/var/log/httpd/x.err"
    servername www.X.com
    <Directory "/web/vhosts/x">
          Require all granted
          AllowOverride ALL
    </Directory>

    </virtualhost>


    <virtualhost *:80>
    documentroot /web/vhosts/y
    CustomLog "/var/log/httpd/y.access" combined
    ErrorLog "/var/log/httpd/www2.err"
    servername www.Y.com
    <Directory "/web/vhosts/y">
          Require all granted
    </Directory>
    </virtualhost>

    :wq  保存退出

    [root@centos7 /]# systemctl restart httpd   服务端重启httpd服务

    [root@centos7 ~]# vim /etc/hosts   在客户端配置hosts文件

    添加一条:

    192.168.47.17 www.X.com www.Y.com

    验证:

    [root@centos7 ~]# curl www.X.com

    [root@centos7 ~]# curl www.Y.com

     

  • 相关阅读:
    (转)一篇教会你写90%的shell脚本
    (转)printf命令详解
    (转)linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 )
    (转)Shell中read的选项及用法
    (转)linux中shell变量$#,$@,$0,$1,$2的含义解释/Shell中的${}、##和%%使用范例/export
    (转)linux运维人员必会的22道shell编程面试题及视频讲解
    (转)李文周的博客
    ROS报错“An error occurred during the signature verification”的解决办法
    RRT and RRT Variants
    ROS LocalPlanner 基于自行车模型的DWA
  • 原文地址:https://www.cnblogs.com/jing-yun/p/13906804.html
Copyright © 2011-2022 走看看