目录
一、使用ansible的playbook实现自动化安装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
测试结果: