1.使用ansible的playbook实现自动化安装httpd
太长了 单独写了个文章放在我ansible的文集里面了
使用ansible的playbook实现自动化安装httpd
2.建立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,内容分别为其对应的主机名
#建立documentroot目录即站点页面存放目录
mkdir -p /data/web{1..3}
#准备站点日志
#准备站点页面
echo this is web1 > /data/web1/index.html
echo this is web2 > /data/web2/index.html
echo this is web3 > /data/web3/index.html
#编辑httpd的主配置文件httpd.conf
ServerRoot "httpd的软件目录"
includeoptional conf.d/*.conf #includeoptional 即使*.conf文件不存在也不会报错
#主配置文件定义了日志的格式
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %{%F %T}t \"%r\" %>s %b %{User-agent}i" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
ErrorLog "logs/error_log"
LogLevel warn
#编辑虚拟主机配置文件
<virtualhost *:80>
servername web1.wangcloud.top
documentroot "/data/web1"
<directory "/data/web1">
require all granted
Options None
AllowOverride None
</directory>
ErrorLog "logs/web1_error.log"
CustomLog "logs/web1_access.log" common
</virtualhost>
<virtualhost *:80>
servername web2.wangcloud.top
documentroot "/data/web2"
<directory "/data/web2">
require all granted
Options None
AllowOverride None
</directory>
ErrorLog "logs/web2_error.log"
CustomLog "logs/web2_access.log" common
</virtualhost>
<virtualhost *:80>
servername web3.wangcloud.top
documentroot "/data/web3"
<directory "/data/web3">
require all granted
Options None
AllowOverride None
</directory>
ErrorLog "logs/web3_error.log"
CustomLog "logs/web3_access.log" common
</virtualhost>
#编辑主机/etc/hosts文件 模拟DNS解析
#多虚拟主机技术一个IP相同端口根据FQDN不同区分站点访问
vim /etc/hosts
10.0.0.7 web1.wangcloud.top web2.wangcloud.top web3.wangcloud.top
#检测httpd配置文件语法
httpd -t
#重启httpd服务
systemctl restart httpd
#测试访问
root@7 conf.d]# curl web1.wangcloud.top
this is web1
root@7 conf.d]# curl web2.wangcloud.top
this is web2
root@7 conf.d]# curl web3.wangcloud.top
this is web3