-
热评好文
-
最新评论
-
51cto_blog:Hi~大大这篇文章写得很优秀,可以尝试参加一下【2021年度技术博客大赛】,丰厚超值奖品!参加成功,百分百中奖!>> https://blog.51cto.com/contest/index
-
目录
-
1、使用ansible的playbook实现自动化安装httpd
1.安装ansible[192.168.47.100]
yum install ansible
2.修改/etc/asnsible/hosts配置文件;设置需要管理的电脑
[websrvs]
192.168.47.101
192.168.47.102
[appsrvs]
192.168.47.102
192.168.47.103
3.安装httpd
yum install httpd -y
修改配置文件端口
cp /etc/httpd/conf/httpd.conf /data/
sed -i 's/Listen 80/Listen 8080/' httpd.conf
4.编写httpd.yml文件
---
- hosts: websrvs
remote_user: root
tasks:
- name: Install httpd
yum: name=httpd
- name: Install configure
copy: src=/data/httpd.conf dest=/etc/httpd/conf/
- name: Start service
service: name=httpd state=started enabled=yes
5.检查错误
ansible-playbook -C httpd.yml
6.运行
ansible-playbook httpd.yml
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,内容分别为其对应的主机名
1.配置文件/etc/httpd/conf.d/text.conf
<virtualhost 192.168.47.100>
documentroot /web/vhosts/x
servername www.x.com
<Directory "/web/vhosts/x">
Require all granted
</Directory>
errorlog /var/log/httpd/x.err.log
customlog /var/log/httpd/x.access.log combined
</virtualhost>
<virtualhost 192.168.47.50>
documentroot /web/vhosts/y
servername www.y.com
<Directory "/web/vhosts/y">
Require all granted
</Directory>
errorlog /var/log/httpd/www2.err.log
customlog /var/log/httpd/y.access.log combined
</virtualhost>
2.创建目录
mkdir /web/vhosts/{x,y} -p
3.创建index.html
vim /web/vhosts/x/index.html
<h1>
This is www.X.com</br>
hostname : www.X.com</br>
IP : 192.168.47.100</br>
port : 80
</h1>
vim /web/vhosts/y/index.html
<h1>
This is www.y.com</br>
hostname : www.y.com</br>
IP : 192.168.47.50</br>
port : 80
</h1>
4.重启服务
systemctl restart httpd
5.前台显示
0
收藏
Ctrl+Enter 发布
发布
取消