之前介绍了使用ansible playbok安装zabbix客户端、mysql服务端、nginx,现在介绍一下安装lnmp环境。

下面▲是安装nginx的信息:

nginx_user:?www????????????????????????nginx用户
nginx_port:?80?????????????????????????nginx监听端口
nginx_web_dir:?/data/webroot/nginx?????nginx的目录
nginx_version:?1.4.3???????????????????nginx的版本
pcre_version:?8.33?????????????????????pcre的版本
pretended_name:?Tengine????????????????为了安全起见,把nginx名字改为tengine
pretended_version:?1.5.2???????????????隐藏版本,换个tengine的版本

下〓面是安装php的信息:

php_user:?www????????????????????????????php?fpm模式的启动用户
php_port:?9000???????????????????????????php?fpm使用tcp的端口
php_dir:?/usr/local??????????????????????php的安装目录
php_version:?5.3.10??????????????????????php的版本
mysql_basedir:?/data/mysql/basedir???????mysql的目录

下面是安装mysql的信息:

mysql_basedir:?/data/mysql/basedir????????????????????源码目录
mysql_datadir:?/data/mysql/datadir????????????????????数据目录
mysql_user:?mysql?????????????????????????????????????mysql用户
mysql_database_user:?root?????????????????????????????数据库用户
mysql_passwd:?'E4yR3WnoluSFTCBAI'?????????????????????数据库密码
mysql_port:?3306??????????????????????????????????????mysql监听端口
mysql_sock:?/data/mysql/datadir/mysql.sock????????????mysql的sock
mysql_charset:?utf8???????????????????????????????????mysql字符集
mysql_collation:?utf8_general_ci??????????????????????mysql排序方式
mysql_version:?Percona-Server-5.5.21-rel25.1.tar.gz???mysql版本

备注:此playbook仅能对centos或者redhat的6.x版本进行安装。

下面是安装lnmp的playbook结构

09:28:50?#?tree?nginx*?mysql*?php*
nginx_delete
├──?files
├──?handlers
├──?meta
│???└──?main.yml
├──?tasks
│???├──?delete.yml
│???└──?main.yml
├──?templates
└──?vars
????└──?main.yml
nginx_install
├──?files
│???└──?nginx-1.4.3.tar.gz
├──?handlers
├──?meta
│???└──?main.yml
├──?tasks
│???├──?copy.yml
│???├──?delete.yml
│???├──?install.yml
│???└──?main.yml
├──?templates
│???├──?index.html
│???├──?index.php
│???├──?install_nginx.sh
│???├──?nginx
│???├──?nginx.conf
│???└──?vhost.conf
└──?vars
????└──?main.yml
mysql_delete
├──?files
├──?handlers
├──?meta
│???└──?main.yml
├──?tasks
│???├──?delete.yml
│???└──?main.yml
├──?templates
└──?vars
????└──?main.yml
mysql_install
├──?files
│???└──?mysql.tar.gz
├──?handlers
├──?meta
│???└──?main.yml
├──?tasks
│???├──?copy.yml
│???├──?delete.yml
│???├──?install.yml
│???└──?main.yml
├──?templates
│???├──?install_mysql.sh
│???├──?my.cnf
│???├──?mysqld
│???└──?mysql_security.sh
└──?vars
????└──?main.yml
php_delete
├──?files
├──?handlers
├──?meta
│???└──?main.yml
├──?tasks
│???├──?delete.yml
│???└──?main.yml
├──?templates
│???└──?delete_php.sh
└──?vars
????└──?main.yml
php_install
├──?files
│???└──?php.tar.gz
├──?handlers
├──?meta
│???└──?main.yml
├──?tasks
│???├──?copy.yml
│???├──?delete.yml
│???├──?install.yml
│???└──?main.yml
├──?templates
│???├──?install_php.sh
│???├──?php-fpm
│???└──?php-fpm.conf
└──?vars
????└──?main.yml

36?directories,?47?files

playbook的lnmp安装是

09:29:59?#?cat?lnmp_install.yml?
---
-?hosts:?"`host`"
??remote_user:?"`user`"
??gather_facts:?True
??roles:
????-?common
????-?pcre_install
????-?nginx_install
????-?mysql_install
????-?php_install

playbook的lnmp删除

09:30:33?#?cat?lnmp_delete.yml?
---
-?hosts:?"`host`"
??remote_user:?"`user`"
??gather_facts:?True
??roles:
????-?pcre_delete
????-?php_delete
????-?nginx_delete
????-?mysql_delete

1、安装lnmp

09:35:55?#??time?ansible-playbook?lnmp_install.yml?--extra-vars?"host=192.168.240.13?user=root"?--private-key=/root/test.pem?

PLAY?[192.168.240.13]?*********************************************************?

GATHERING?FACTS?***************************************************************?
ok:?[192.168.240.13]

TASK:?[common?|?Install?initializtion?require?software]?***********************?
changed:?[192.168.240.13]

TASK:?[pcre_install?|?Copy?Pcre?Software?To?Redhat?Client]?********************?
changed:?[192.168.240.13]

TASK:?[pcre_install?|?Uncompression?Pcre?Software?In?Redhat?Client]?***********?
changed:?[192.168.240.13]

TASK:?[pcre_install?|?Delete?Pcre?Software?In?Redhat?Client]?******************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Copy?Nginx?Software?To?Redhat?Client]?******************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Uncompression?Nginx?Software?To?Redhat?Client]?*********?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Copy?Nginx?Start?Script?To?Redhat?Client]?**************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Copy?Nginx?Config?To?Redhat?Client]?********************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Copy?Nginx?Vhost?Config?to?RedHat?Client]?**************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Create?Nginx?User?In?Redhat?Client]?********************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Create?Nginx??Dir]?*************************************?
changed:?[192.168.240.13]?=>?(item=vhost)
changed:?[192.168.240.13]?=>?(item=logs)

TASK:?[nginx_install?|?Modify?Nginx?Dir?Permission?In?Redhat?Client]?**********?
changed:?[192.168.240.13]?=>?(item=/data/webroot/nginx)
changed:?[192.168.240.13]?=>?(item=/usr/local/nginx-1.4.3)

TASK:?[nginx_install?|?Create?Index?Html?To?Redhat?Client]?********************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Install?Check?Script?In?Redhat?Client]?*****************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Start?Nginx?Service?In?Redhat?Client]?******************?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Add?Boot?Start?Nginx?Service?In?Redhat?Client]?*********?
changed:?[192.168.240.13]

TASK:?[nginx_install?|?Delete?Nginx?compression?Software?In?Redhat?Client]?****?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Copy?Mysql?Software?To?Redhat?Client]?******************?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Create?Mysql?User?In?Redhat?Client]?********************?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Copy?Mysql?Start?Script?To?Redhat?Client]?**************?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Copy?Install?Mysql?Script??To?Redhat?Client]?***********?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Copy?Mysql?Config?To?Redhat?Client]?********************?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Copy?Mysql?Security?Script?To?Redhat?Client]?***********?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Create?Mysql?Install?Dir]?******************************?
ok:?[192.168.240.13]

TASK:?[mysql_install?|?Uncompression?Mysql?Software?To?Redhat?Client]?*********?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Modify?Mysql?Dir?Permission?In?Redhat?Client]?**********?
ok:?[192.168.240.13]?=>?(item=/data/mysql/datadir)
ok:?[192.168.240.13]?=>?(item=/data/mysql/basedir)

TASK:?[mysql_install?|?Install?Mysql?Script?In?Redhat?Client]?*****************?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Start?Myql?Security?Script?In?Redhat?Client]?***********?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Add?Boot?Start?Mysql?Service?In?Redhat?Client]?*********?
changed:?[192.168.240.13]

TASK:?[mysql_install?|?Delete?Mysql?compression?Software?In?Redhat?Client]?****?
changed:?[192.168.240.13]

TASK:?[php_install?|?Copy?Php?Software?To?Redhat?Client]?**********************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Uncompression?Php?Software?To?Redhat?Client]?*************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Copy?Php?Start?Script?To?Redhat?Client]?******************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Copy?Php?Config?To?Redhat?Client]?************************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Copy?Php?Install?Script?To?Redhat?Client]?****************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Create?Php?User?In?Redhat?Client]?************************?
ok:?[192.168.240.13]

TASK:?[php_install?|?Install?Php?Script?In?Redhat?Client]?*********************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Start?Php?Service?In?Redhat?Client]?**********************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Add?Boot?Start?Php?Service?In?Redhat?Client]?*************?
changed:?[192.168.240.13]

TASK:?[php_install?|?Delete?Php?compression?Software?In?Redhat?Client]?********?
changed:?[192.168.240.13]

PLAY?RECAP?********************************************************************?
192.168.240.13?????????????:?ok=41???changed=37???unreachable=0????failed=0???


real	2m16.803s
user	0m14.753s
sys	0m1.468s

可以看到2分16秒↑就安装成功,一般比较费时的是使用yum安装软件与☉从本地负责包到客户端,所以yum源最后使用自己做的yum源或者找个速度快的yum源。

2、安装后测试

[root@ip-10-10-240-20?tmp]#?ps?-ef|grep?nginx|wc?-l
10
[root@ip-10-10-240-20?tmp]#?ps?-ef|grep?mysql|wc?-l
3
[root@ip-10-10-240-20?tmp]#?ps?-ef|grep?php|wc?-l
130
[root@ip-10-10-240-20?tmp]#?cd?/data/webroot/nginx/
logs/??vhost/?
[root@ip-10-10-240-20?tmp]#?cd?/data/webroot/nginx/vhost/
[root@ip-10-10-240-20?vhost]#?cat?index.html?
Nginx?1.4.3?in?10.10.240.20??is?success!
[root@ip-10-10-240-20?vhost]#?cat?index.php?
<?php
$link?=?mysql_connect('10.10.240.20','zabbix','zabbix');
if?($link)
echo?"Successs!!!Php?install?success!\n";
else
echo?"Fail!!!Php?install?fail!\n";
mysql_close();
?>
[root@ip-10-10-240-20?vhost]#?curl?10.10.240.20/index.html
Nginx?1.4.3?in?10.10.240.20??is?success!
[root@ip-10-10-240-20?vhost]#?curl?10.10.240.20/index.php
Successs!!!Php?install?success!
[root@ip-10-10-240-20?vhost]#?curl?-I?10.10.240.20/index.php
HTTP/1.1?200?OK
Server:?Tengine/1.5.2
Date:?Mon,?21?Jul?2014?02:12:24?GMT
Content-Type:?text/html
Connection:?keep-alive
Vary:?Accept-Encoding

3、删除lnmp

09:38:36?#??time?ansible-playbook?lnmp_delete.yml?--extra-vars?"host=192.168.240.13?user=root"?--private-key=/root/test.pem?

PLAY?[192.168.240.13]?*********************************************************?

GATHERING?FACTS?***************************************************************?
ok:?[192.168.240.13]

TASK:?[pcre_delete?|?Delete?Pcre]?*********************************************?
changed:?[192.168.240.13]

TASK:?[php_delete?|?Copy?Delete?Php?Script?To?RedHat?Client]?******************?
changed:?[192.168.240.13]

TASK:?[php_delete?|?Run?Delete?Php?Script?In?RedHat?Client]?*******************?
changed:?[192.168.240.13]

TASK:?[php_delete?|?Delete?Php?User?In?Redhat?Client]?*************************?
failed:?[192.168.240.13]?=>?{"failed":?true,?"item":?"",?"name":?"www",?"rc":?8}
msg:?userdel:?user?www?is?currently?logged?in

...ignoring

TASK:?[php_delete?|?Delete?Php?Script]?****************************************?
changed:?[192.168.240.13]

TASK:?[nginx_delete?|?stop?nginx?service]?*************************************?
changed:?[192.168.240.13]

TASK:?[nginx_delete?|?Delete?Nginx?Boot?Start?Script]?*************************?
changed:?[192.168.240.13]

TASK:?[nginx_delete?|?Delete?Nginx?Dir]?***************************************?
changed:?[192.168.240.13]

TASK:?[nginx_delete?|?Delete?Nginx?User]?**************************************?
changed:?[192.168.240.13]

TASK:?[nginx_delete?|?Delete?Nginx?Service?Start?Script]?**********************?
changed:?[192.168.240.13]

TASK:?[mysql_delete?|?Stop?Mysql?Service]?*************************************?
changed:?[192.168.240.13]

TASK:?[mysql_delete?|?Delete?Mysql?Boot?Start?Script]?*************************?
changed:?[192.168.240.13]

TASK:?[mysql_delete?|?Delete?Mysql?Dir?And?Socket]?****************************?
changed:?[192.168.240.13]

TASK:?[mysql_delete?|?Delete?Mysql?User]?**************************************?
changed:?[192.168.240.13]

TASK:?[mysql_delete?|?Delete?Mysql?Service?Start?Script]?**********************?
changed:?[192.168.240.13]

PLAY?RECAP?********************************************************************?
192.168.240.13?????????????:?ok=16???changed=14???unreachable=0????failed=0???


real	0m31.511s
user	0m1.470s
sys	0m0.232s

4、删除后测〒试

[root@ip-10-10-240-20?vhost]#?ll?/usr/local/
total?40
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?Sep?23??2011?lib64
drwxr-xr-x.?2?root???root???4096?Sep?23??2011?libexec
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??5?zabbix?zabbix?4096?Jul??8?02:17?zabbix
[root@ip-10-10-240-20?vhost]#?ps?-ef|grep?php
root?????10016??3527??0?22:13?pts/0????00:00:00?grep?php
[root@ip-10-10-240-20?vhost]#?ps?-ef|grep?mysql
root?????10018??3527??0?22:13?pts/0????00:00:00?grep?mysql
[root@ip-10-10-240-20?vhost]#?ps?-ef|grep?nginx
root?????10020??3527??0?22:13?pts/0????00:00:00?grep?nginx
[root@ip-10-10-240-20?vhost]#?id?www
id:?www:?No?such?user
[root@ip-10-10-240-20?vhost]#?id?mysql
id:?mysql:?No?such?user

可与看到都删除了。

如果大家想使用我的例子♂,可以从github里下载(地址是https://github.com/dl528888/ansible-examples/tree/master/lnmp_install),然后放到/etc/ansible目录

运维自动化之ansible playbook安装lnmp环境 content 数据 安装 目录 排序 删除 cc 速度快 change lnmp 服务器教程  第1张

热搜词

cl洛杉矶之旅记录〖片删除lnmp建站之星代理平台建站之星微营销虚拟主机系统安装以后程序怎么安装vps如何安装花⌒ 生壳龙之谷防高攻击高自助建站之星vps安装织梦域名之名重装之后d盘不见了asp网站∑安装到空间申请了域名之后求生之路ddos攻击windows2008安装php不同vps之间传输数据web服务器网络环境虚拟主机ssl证书安装d525安装2003windows2008安装mysql域名解析了之后呢高铁桥梁防抛网安装技术交底idc机房运维前景lnmp查看mysql密码sql 2000安装图解linux主机 安装wordpress运维管家机柜间安装时有哪些工程量要计算塔防之光地下城高攻击攻略流放之路什么盾牌高防conoha vpn一键安装网站的运行∞环境万网远程安装centosphp虚拟主机环境配置云主机如何安装tomcatwd面板安装服务器 安装 证书asp 安装ssl证书开求生之路2服务器就被ddos求生之路2如何防ddos云托管 运维健康之路关注三高夏季防中风vps安装xp网卡驱动webmin安装后外界服务器无法访问vps安装easypanel安装教程iis不联网能安装吗linux 全能空间安装脚本虚拟空间安装mysqlphp虚拟环境kimsufi安装费挂机宝怎么安装显卡vps安装sqlphplinux云面板全能环境建站之星怎么上传自己的模板建站之星 加密建站之星 授权linux 安装cpanel北京网之商directadmin 一键安装慢速ddos环境搭建sql 2005 sp4 安装失败云主机操作系统如何安装win2003 iis 安装云锁安装失败ddos环境建站之星是免费的吗域名注册好之后window下安装apache流放之地高防ddos 破坏之王 pdf托管环境描绘一台电脑可以建立多个php环境吗五菱之光高防中间车门价格建站之星好吗建站之星 500shopex安装500conoha 安装lnmp 卸载 mysql云点之控万网安装织梦远程站点服¤务器主机上必须安装win2008 安装动易高7安装防倾杆服务器上安装web服务 指向一个二级域名cuteftp安装教程win2008服务器系统安装教程虚拟主机安装织梦vps安装杀毒软件会安全点吗server 2008 安装iis建站之星pc版功能虚拟主机安装ecshop建站之星php服务器 防ddos 安装什么四七层ddos攻击测试环境phpwind安装向导美国在独立之时虽然科技建站之星加代码cpanel 一键安装中国环境邮政局订购一年价格