运维自动化之ansible playbook安装apache
生活随笔
收集整理的這篇文章主要介紹了
运维自动化之ansible playbook安装apache
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上次介紹了如何使用ansible安裝lnmp(地址是http://dl528888.blog.51cto.com/2382721/1440775),現在介紹如何使用ansible安裝apache。
下面是安裝apache的信息:
apr_version:?1.5.0 apr_util_version:?1.5.3 libiconv_version:?1.14 apache_version:?2.4.7 apache_web_dir:?/data/webroot/apache apache_log:?/data/webroot/apache/logs apache_vhost:?/data/webroot/apache/vhost apache_port:?80 apache_user:?www serveradmin:?denglei@chukong-inc.com可以看到apache的版本是2.4.7
備注:此playbook僅能對centos或者redhat的6.x版本進行安裝。
下面是安裝apache的playbook結構
apache_delete ├──?files ├──?handlers ├──?meta │???└──?main.yml ├──?tasks │???├──?delete.yml │???└──?main.yml ├──?templates └──?vars└──?main.yml apache_install ├──?files │???├──?httpd-2.4.7.tar.gz │???└──?libiconv.tar.gz ├──?handlers ├──?meta │???└──?main.yml ├──?tasks │???├──?copy.yml │???├──?delete.yml │???├──?install.yml │???└──?main.yml ├──?templates │???├──?httpd │???├──?httpd.conf │???├──?index.html │???├──?index.php │???└──?vhost.conf └──?vars└──?main.yml12?directories,?17?filesplaybook安裝apache的是:
playbook刪除apache的是:
09:09:56?#?cat?apache_delete.yml? --- -?hosts:?"`host`"remote_user:?"`user`"gather_facts:?Trueroles:-?apache_delete1、安裝apache
可以看到47秒就安裝完成(默認的common模塊是安裝基礎的yum依賴庫,這個我一般初始化安裝完成,所以這個地方沒有浪費時間,建議大家也都在系統默認安裝完成后,初始化依賴庫)
2、安裝后測試
[root@ip-10-10-240-20?tmp]#?ps?-ef|grep?httpd root??????8375?????1??0?21:08??????????00:00:00?/usr/local/httpd-2.4.7/bin/httpd?-k?start www???????8377??8375??0?21:08??????????00:00:00?/usr/local/httpd-2.4.7/bin/httpd?-k?start www???????8378??8375??0?21:08??????????00:00:00?/usr/local/httpd-2.4.7/bin/httpd?-k?start www???????8379??8375??0?21:08??????????00:00:00?/usr/local/httpd-2.4.7/bin/httpd?-k?start www???????8380??8375??0?21:08??????????00:00:00?/usr/local/httpd-2.4.7/bin/httpd?-k?start root??????8569??6666??0?21:11?pts/1????00:00:00?grep?httpd [root@ip-10-10-240-20?tmp]#?ll?/usr/local/ total?56 drwxr-xr-x.??2?root?root?4096?Sep?23??2011?bin drwxr-xr-x.??2?root?root?4096?Sep?23??2011?etc drwxr-xr-x.??2?root?root?4096?Sep?23??2011?games drwxr-xr-x??15?root?root?4096?Jul??1?05:18?httpd-2.4.7 drwxr-xr-x.??2?root?root?4096?Sep?23??2011?include drwxr-xr-x.??2?root?root?4096?Jul?27?21:07?lib drwxr-xr-x.??2?root?root?4096?Sep?23??2011?lib64 drwxr-xr-x.??2?root?root?4096?Sep?23??2011?libexec drwxr-xr-x???6?root?root?4096?Jun?23?05:38?pcre-8.33 drwxr-xr-x??10?root?root?4096?Jul?22?23:33?proftpd-1.3.4d drwxr-xr-x.??2?root?root?4096?Sep?23??2011?sbin drwxr-xr-x.??5?root?root?4096?May?12??2013?share drwxr-xr-x.??3?root?root?4096?May?12??2013?src drwxr-xr-x???6?root?root?4096?Jul?24?05:41?vpsmate [root@ip-10-10-240-20?tmp]#?curl?10.10.240.20 Apache?2.4.7?in?10.10.240.20??is?success! [root@ip-10-10-240-20?tmp]#?curl?10.10.240.20/index.php <!DOCTYPE?HTML?PUBLIC?"-//IETF//DTD?HTML?2.0//EN"> <html><head> <title>503?Service?Unavailable</title> </head><body> <h1>Service?Unavailable</h1> <p>The?server?is?temporarily?unable?to?service?your request?due?to?maintenance?downtime?or?capacity problems.?Please?try?again?later.</p> </body></html> [root@ip-10-10-240-20?tmp]#?curl?-I?10.10.240.20 HTTP/1.1?200?OK Date:?Mon,?28?Jul?2014?01:13:13?GMT Server:?Tengine/1.5.2 Last-Modified:?Mon,?28?Jul?2014?01:08:01?GMT ETag:?"2a-4ff368df22a0b" Accept-Ranges:?bytes Content-Length:?42 Content-Type:?text/html如果打開php界面的原因是沒有安裝php,安裝的話都成功了并運行正常。
3、刪除apache
09:16:38?#?time?ansible-playbook?apache_delete.yml?--extra-vars?"host=192.168.240.13?user=root"?--private-key=/root/test.pemPLAY?[192.168.240.13]?*********************************************************?GATHERING?FACTS?***************************************************************? ok:?[192.168.240.13]TASK:?[apache_delete?|?Stop?Httpd?Service?In?RedHat?Client]?*******************? changed:?[192.168.240.13]TASK:?[apache_delete?|?Delete?Boot?Start?In?RedHat?Client]?********************? changed:?[192.168.240.13]TASK:?[apache_delete?|?Delete?Apache?Dir?In?RedHat?Client]?********************? changed:?[192.168.240.13]TASK:?[apache_delete?|?Delete?Apache?Service?Script?In?RedHat?Client]?*********? changed:?[192.168.240.13]TASK:?[apache_delete?|?Delete?Apache?User]?************************************? changed:?[192.168.240.13]PLAY?RECAP?********************************************************************? 192.168.240.13?????????????:?ok=6????changed=5????unreachable=0????failed=0???real 0m19.803s user 0m0.665s sys 0m0.104s4、刪除后測試
[root@ip-10-10-240-20?tmp]#?ps?-ef|grep?http root?????11353??6666??0?21:17?pts/1????00:00:00?grep?http [root@ip-10-10-240-20?tmp]#?ll?/usr/local/ total?52 drwxr-xr-x.??2?root?root?4096?Sep?23??2011?bin drwxr-xr-x.??2?root?root?4096?Sep?23??2011?etc drwxr-xr-x.??2?root?root?4096?Sep?23??2011?games drwxr-xr-x.??2?root?root?4096?Sep?23??2011?include drwxr-xr-x.??2?root?root?4096?Jul?27?21:16?lib drwxr-xr-x.??2?root?root?4096?Sep?23??2011?lib64 drwxr-xr-x.??2?root?root?4096?Sep?23??2011?libexec drwxr-xr-x???6?root?root?4096?Jun?23?05:38?pcre-8.33 drwxr-xr-x??10?root?root?4096?Jul?22?23:33?proftpd-1.3.4d drwxr-xr-x.??2?root?root?4096?Sep?23??2011?sbin drwxr-xr-x.??5?root?root?4096?May?12??2013?share drwxr-xr-x.??3?root?root?4096?May?12??2013?src drwxr-xr-x???6?root?root?4096?Jul?24?05:41?vpsmate [root@ip-10-10-240-20?tmp]#?id?www id:?www:?No?such?user [root@ip-10-10-240-20?tmp]#?curl?10.10.240.20?-I curl:?(7)?couldn't?connect?to?host如果大家想使用我的例子,可以從github里下載(地址是https://github.com/dl528888/ansible-examples/tree/master/apache_install),然后放到/etc/ansible目錄里,下面是內容
如果覺得好,給個贊并多評論,謝謝。
轉載于:https://blog.51cto.com/dl528888/1531104
總結
以上是生活随笔為你收集整理的运维自动化之ansible playbook安装apache的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: web网站无法启动报错
- 下一篇: Azure Remoteapp 使用指南