第十六週

一、使用ansible的playbook實現自動化安裝httpd

一、ansible和各主機之間作免密登陸
html

二、配置ansible的host主機web

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

第十六週

三、準備配置文件模板:vim

centos6 和centos7 各一個配置文件模板
第十六週centos

四、準備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

第十六週

五、執行腳本安裝:服務器

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

第十六週

六、結果驗證
第十六週
第十六週
第十六週ide

二、創建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,內容分別爲其對應的主機名
ui

一、確保配置文件中有此配置:
[root@ka1 conf.d]#cat /etc/httpd/conf/httpd.conf
IncludeOptional conf.d/*.conf
第十六週centos7

二、建立獨立的配置文件:

[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>
第十六週

二、建立虛擬主機目錄:
[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

四、重啓httpd
[root@ka1 conf.d]#systemctl restart httpd

五、PC機修改hosts文件:C:\Windows\System32\drivers\etc\hosts
第十六週

六、瀏覽器訪問:

www.X.com

第十六週

www.Y.com

第十六週

七、查看日誌文件:
[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

第十六週

架構的小夥伴看這裏哦:

一、總結描述kubectl經常使用命令並用實例說明。

二、總結k8s的常見的volume使用。

相關文章
相關標籤/搜索