码迷,mamicode.com
首页 > 其他好文 > 详细

第十六周

时间:2020-04-10 10:29:27      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:inf   config   http   安装   virt   之间   not   emc   mic   

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

1、ansible和各主机之间做免密登录

2、配置ansible的host主机

[root@centos7a playbook]#cat /etc/ansible/hosts 
[wang]
192.168.43.106
192.168.43.147
192.168.43.137

技术图片

3、准备配置文件模板:

centos6 和centos7 各一个配置文件模板
技术图片

4、准备playbook脚本

[root@centos7a playbook]#cat httpd.yml 
- hosts: wang
    remote_user: root

    tasks:
        - name: install
            yum: name=httpd
        - name: config
            template: src=httpd6.conf.j2 dest=/etc/httpd/conf/httpd.conf
            when: ansible_distribution_major_version == "6"
            notify: httpd restart
        - name: config
            template: src=httpd7.conf.j2 dest=/etc/httpd/conf/httpd.conf
            when: ansible_distribution_major_version == "7"
            notify: httpd restart
        - name: service
            service: name=httpd state=started enabled=yes

    handlers:
        - name: httpd restart
            service: name=httpd state=restarted

技术图片

5、执行脚本安装:

[root@centos7a playbook]#ansible-playbook httpd.yml

技术图片

6、结果验证
技术图片
技术图片
技术图片

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、确保配置文件中有此配置:
[root@ka1 conf.d]#cat /etc/httpd/conf/httpd.conf
IncludeOptional conf.d/*.conf
技术图片

2、创建独立的配置文件:

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

<directory "/var/www/html/">
Require all granted
ALLowOverride All
</directory>

<VirtualHost *:80>
ErrorLog "/var/log/httpd/x.err"
CustomLog "/var/log/httpd/x.access" combined
DocumentRoot "/web/vhosts/x"
ServerName www.X.com
<Directory "/web/vhosts/x">
require all granted
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/web/vhosts/y"
ServerName www.Y.com
ErrorLog "/var/log/httpd/www2.err"
CustomLog "/var/log/httpd/y.access" combined
<Directory "/web/vhosts/y">
require all granted
</Directory>
</VirtualHost>
技术图片

2、创建虚拟主机目录:
[root@ka1 conf.d]#tree /web/vhosts/
/web/vhosts/
├── x
│?? └── index.html
└── y
└── index.html
[root@ka1 conf.d]#cat /web/vhosts/{x,y}/index.html
www.X.com
www.Y.com

4、重启httpd
[root@ka1 conf.d]#systemctl restart httpd

5、PC机修改hosts文件:C:\Windows\System32\drivers\etc\hosts
技术图片

6、浏览器访问:

www.X.com

技术图片

www.Y.com

技术图片

7、查看日志文件:
[root@ka1 conf.d]#ll /var/log/httpd/
[root@ka1 httpd]#ll
total 32
-rw-r--r-- 1 root root 8412 Apr 9 15:02 access_log
-rw-r--r-- 1 root root 11300 Apr 9 15:13 error_log
-rw-r--r-- 1 root root 0 Apr 9 15:03 www2.err
-rw-r--r-- 1 root root 192 Apr 9 15:13 x.access
-rw-r--r-- 1 root root 0 Apr 9 15:03 x.err
-rw-r--r-- 1 root root 3788 Apr 9 15:13 y.access

技术图片

架构的小伙伴看这里哦:

1、总结描述kubectl常用命令并用实例说明。

2、总结k8s的常见的volume使用。

第十六周

标签:inf   config   http   安装   virt   之间   not   emc   mic   

原文地址:https://blog.51cto.com/5440126/2486091

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!