linux练习题十六

目录

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

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


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

yum install ansible

vim /etc/ansible/hosts
[webservers]
192.168.44.17
192.168.44.27

vim /data/playbook/httpd.yml
---
- hosts: webservers
  remote_user: root
  tasks:
  - name: install
    yum: name=httpd
  - name: config
    copy: src=/tmp/httpd.conf dest=/etc/httpd/conf/
  - name: service
    service: name=httpd state=started enabled=yes

 检查yml文件:

 执行任务:

 

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

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

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

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

服务端:
vim /etc/httpd/conf.d/webs.conf
<VirtualHost *:80>  
ServerName www.X.com
DocumentRoot "/web/vhosts/x"    #页面目录
CustomLog "/var/log/httpd/x.access" combined    #访问日志
ErrorLog "/var/log/httpd/x.err"    #错误日志
<Directory "/web/vhosts/x">
    Require all granted
</Directory>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
DeflateCompressionLevel 9
</VirtualHost>

<VirtualHost *:80>
ServerName www.Y.com
DocumentRoot "/web/vhosts/y"    #页面目录
CustomLog "/var/log/httpd/y.access" combined    #访问日志
ErrorLog "/var/log/httpd/www2.err"    #错误日志
<Directory "/web/vhosts/y">
    Require all granted
</Directory>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
DeflateCompressionLevel 9
</VirtualHost>

mkdir -pv /web/vhosts/{x,y}
touch /web/vhosts/{x,y}/index.html
echo 'www.X.com' >/web/vhosts/x/index.html
echo 'www.Y.com' >/web/vhosts/y/index.html

客户端:
vim /etc/hosts
添加一行:
192.168.44.7 www.X.com www.Y.com

测试:
curl www.X.com
curl www.Y.com

测试结果:

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值