网海过客 www.chinasa.net
目录结构
├── hosts
├── roles
│ └── lnmp
│ ├── files
│ │ ├── lnmp.tar.gz
│ └── tasks
│ └── main.yaml
└── site.yaml
hosts配置
#cat hosts
[lnmp]
192.168.10.10 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=pass111
安装脚本忽过
PS:脚本内容太长,可自行写安装脚本
部份脚本内容:
#!/bin/sh export blue=`echo -e "\033[0;36;2m"` white=`echo -e "\033[40;37m"` basedir=`pwd` php_soft_dir=`pwd`/php_soft imagick_soft_dir=`pwd`/imagick_soft tengine_soft_dir=`pwd`/tengine_soft #------------------------------------------------------------ install_dir=/opt #soft install dir start_soft=0 #Start program,0 not start,1 start #------------------------------------------------------------ install_status(){ if [ $? -eq 0 ];then echo "$1 install Successful" >> $basedir/install_soft.log else echo "$1 install Failure!" >> $basedir/install_soft.log exit 0 fi } install_devtools(){ yum -y groupinstall "Development tools" yum -y install pcre pcre-devel gzip gzip-devel zlib zlib-devel cmake ncurses ncurses-devel openssl openssl-devel bzip2-devel curl-devel openldap-devel libevent-devel } # Install Nginx install_nginx(){ if [ -d $install_dir/nginx ] then echo 'nginx soft is exist' return 11 fi id -u www if [ $? -eq 0 ] then
mail.yaml配置文件
—
– shell: mkdir -p /root/soft/
– name: copy lnmp.tar.gz ……
copy: src=lnmp.tar.gz dest=/root/soft/lnmp.tar.gz owner=root group=root mode=644
– name: tar zxf lnmp.tar.gz
shell: cd /root/soft/ && tar zxf lnmp.tar.gz
– name: chmod 700 install_soft.sh
shell: chmod 700 /root/soft/lnmp/install_soft.sh
– name: Install MySQL 5.6.31 ……
shell: cd /root/soft/lnmp/ && ./install_soft.sh 2
– name: Install PHP 5.3.28 ……
shell: cd /root/soft/lnmp/ && ./install_soft.sh 3
– name: Install Redis 3.0 ……
shell: cd /root/soft/lnmp/ && ./install_soft.sh 4
– name: Install Imagick 3.4.1 ……
shell: cd /root/soft/lnmp/ && ./install_soft.sh 5
– name: Install Tengine 2.1.2 + LuaJIT 2.0 ……
shell: cd /root/soft/lnmp/ && ./install_soft.sh 6
site.yaml 入口配置文件
—
– name: lnmp install
hosts: lnmp
roles:
– lnmp
语法检查
[root@ansible-server]# ansible-playbook -i hosts site.yaml –syntax-check
playbook: site.yaml
PS:如有语法错误,请检查语法
lnmp 安装
[root@ansible-server]# ansible-playbook -i hosts site.yaml
PLAY [lnmp install] ********************************************************************
GATHERING FACTS *****************************************************************
ok: [192.168.10.10]
TASK:[lnmp | shell mkdir -p /root/soft/] ********************************************
changed: [192.168.10.10]
TASK:[lnmp | copy lnmp.tar.gz ……] ************************************************
changed: [192.168.10.10]
TASK:[lnmp | tar zxf lnmp.tar.gz ……] **********************************************
changed: [192.168.10.10]
TASK:[lnmp | chmod 700 install_soft.sh ……] *************************************
changed: [192.168.10.10]
TASK:[lnmp | Install MySQL 5.6.31 ……] *******************************************
changed: [192.168.10.10]
TASK:[lnmp | Install PHP 5.3.28 ……] **********************************************
changed: [192.168.10.10]
TASK:[lnmp | Install Redis 3.0 ……] *************************************************
changed: [192.168.10.10]
TASK:[lnmp | Install Imagick 3.4.1 ……] ********************************************
changed: [192.168.10.10]
TASK:[lnmp | Install Tengine 2.1.2 + LuaJIT 2.0 ……] **************************
changed: [192.168.10.10]
PLAY RECAP ********************************************************************
192.168.10.10 : ok=10 changed=9 unreachable=0 failed=0
脚本说明
Nginx PHP MySQL Redis Varnishd
——————————————-
1、Install Nginx1.10.1
2、Install MySQL5.6.31
3、Install PHP5.3.28
4、Install Redis3.0
5、Install Imagick3.4.1
6、Install Tengine2.1.2+LuaJIT2.0
7、Install Varnish3.0.6
——————————————-
Usage: install_soft.sh {1|2|3|4|5|6|7}
安装说明
#./install_soft.sh 1 安装Nginx1.10.1
#./install_soft.sh 2 安装MySQL5.6.31
#./install_soft.sh 3 安装PHP5.3.28
#./install_soft.sh 4 安装Redis3.0
#./install_soft.sh 5 安装Imagick3.4.1
#./install_soft.sh 6 安装Tengine2.1.2+LuaJIT2.0
#./install_soft.sh 7 安装Varnish3.0.6
程序默认安装目录
Nginx /opt/nginx
PHP /opt/php
MySQL /opt/mysql56
Redis /opt/redis
PS:可以修改install_soft.sh安装脚本,install_dir变量,自定义安装路径
原创文章,作者:wubin,如若转载,请注明出处:http://www.178linux.com/26601