第十六周

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

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

2、配置ansible的host主机

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

第十六周

3、准备配置文件模板:

centos6 和centos7 各一个配置文件模板
第十六周

4、准备playbook脚本

[ 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、执行脚本安装:

[ 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、确保配置文件中有此配置:
[ conf.d]#cat /etc/httpd/conf/httpd.conf
IncludeOptional conf.d/*.conf
第十六周

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

[ 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、创建虚拟主机目录:
[ conf.d]#tree /web/vhosts/
/web/vhosts/
├── x
│?? └── index.html
└── y
└── index.html
[ conf.d]#cat /web/vhosts/{x,y}/index.html
www.X.com
www.Y.com

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

5、PC机修改hosts文件:C:\Windows\System32\drivers\etc\hosts
第十六周

6、浏览器访问:

www.X.com

第十六周

www.Y.com

第十六周

7、查看日志文件:
[ conf.d]#ll /var/log/httpd/
[ 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使用。

相关推荐