用ansible剧本搭建lnmp

首先在主服务器上搭建ansible直接用云yum装就可以,

yum -y install ansible

如果copy报错一下的语句 "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren‘t installed!"

需要在被分发的服务器上安装支持包

[[email protected] ~]# mount /dev/sr0 /media/cdrom/
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# yum -y install libselinux-python

然后建立roles的标准化模块相应的目录

[[email protected] myroles]# tree /myroles/
/myroles/
├── nginx.yaml  #nginx模组入口配置文件
└── roles
    └── nginx   #nginx原型模组目录
        ├── files
        ├── handlers
        ├── tasks
        │   └── main.yaml   #nginx模组的tasks任务配置文件
        ├── templates
        └── vars
7 directories, 2 files

Nginx的剧本书写,在myroles里,跟roles同级

---
- hosts: all
  gather_facts: True
  roles:
  - nginx   

然后在Nginx目录下files目录里放置安装包和,安装脚本文件

nginx的搭建脚本

#!/bin/bash
mkdir -p /media/cdrom
umount /dev/sr0 &>/dev/null
mount /dev/sr0 /media/cdrom &>/dev/null
dir=/etc/yum.repos.d
[ -d $dir ] || mkdir -p $dir
cd $dir
mv * /tmp/
cat >/etc/yum.repos.d/local.repo << KOF
[local]
name=localrepo
baseurl=file:///media/cdrom/
KOF
yum -y clean all &>/dev/null
[ $? -eq 0 ] || echo "clean erro"
yum makecache &>/dev/null || echo "erro cache"

which "wget"
[ $? -eq 0 ] || /usr/bin/yum -y install wget &>/dev/null
/usr/bin/wget http://mirrors.aliyun.com/repo/epel-6.repo
[ $? -eq 0 ] || (/bin/echo "yun源出错" && exit)
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ $? -eq 0 ] || (/bin/echo "yun缓存错误" && exit)
/usr/bin/yum -y install pcre-deved openssl-devel &>/dev/null
[ $? -eq 0 ] || /bin/echo "pcre error"
useradd -M -s /sbin/nologin nginx &>dev/null
cd ~
tar xf nginx-1.10.2.tar.gz -C /usr/src/
cd /usr/src/nginx-1.10.2/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.10.2/ --with-http_stub_status_module --with-http_ssl_module && make && make install &>/dev/null

在tasks里创建个main.yaml主要任务剧本

- name: t1
  copy: src=nginx-1.10.2.tar.gz dest=/root/
  register: ttt
- debug: var=ttt
- name: t2
  script: nginx.sh
  register: rrr
- debug: var=rrr
           

回到mysoles里执行nginx.yaml剧本

[[email protected] myroles]# ansible-playbook nginx.yaml 

PLAY [all] *************************************************************************************************

TASK [Gathering Facts] *************************************************************************************
ok: [web1]
ok: [web2]

TASK [nginx : t1] ******************************************************************************************
ok: [web2]
ok: [web1]

TASK [nginx : debug] ***************************************************************************************
ok: [web1] => {
    "ttt": {
        "changed": false,
        "checksum": "1bafb1557b8d5f992714c0dcbde77036bde98547",
        "dest": "/root/nginx-1.10.2.tar.gz",
        "diff": {
            "after": {
                "path": "/root/nginx-1.10.2.tar.gz"
            },
            "before": {
                "path": "/root/nginx-1.10.2.tar.gz"
            }
        },
        "failed": false,
        "gid": 0,
        "group": "root",
        "mode": "0644",
        "owner": "root",
        "path": "/root/nginx-1.10.2.tar.gz",
        "secontext": "unconfined_u:object_r:admin_home_t:s0",
        "size": 910812,
        "state": "file",
        "uid": 0
    }
}
ok: [web2] => {
    "ttt": {
        "changed": false,
        "checksum": "1bafb1557b8d5f992714c0dcbde77036bde98547",
        "dest": "/root/nginx-1.10.2.tar.gz",
        "diff": {
            "after": {
                "path": "/root/nginx-1.10.2.tar.gz"
            },
            "before": {
                "path": "/root/nginx-1.10.2.tar.gz"
            }
        },
        "failed": false,
        "gid": 0,
        "group": "root",
        "mode": "0644",
        "owner": "root",
        "path": "/root/nginx-1.10.2.tar.gz",
        "secontext": "unconfined_u:object_r:admin_home_t:s0",
        "size": 910812,
        "state": "file",
        "uid": 0
    }
}

TASK [nginx : t2] ******************************************************************************************
changed: [web2]
changed: [web1]

TASK [nginx : debug] ***************************************************************************************
ok: [web1] => {
    "rrr": {
        "changed": true,
        "failed": false,
        "rc": 0,
        "stderr": "Shared connection to 192.168.200.131 closed.\r\n",
        "stderr_lines": [
            "Shared connection to 192.168.200.131 closed."
        ],
        "stdout": "/usr/bin/wget\r\n--2018-11-12 19:02:03--  http://mirrors.aliyun.com/repo/epel-6.repo\r\nResolving mirrors.aliyun.com... failed: Name or service not known.\r\nwget: unable to resolve host address “mirrors.aliyun.com”\r\nyun源出错\r\n",
        "stdout_lines": [
            "/usr/bin/wget",
            "--2018-11-12 19:02:03--  http://mirrors.aliyun.com/repo/epel-6.repo",
            "Resolving mirrors.aliyun.com... failed: Name or service not known.",
            "wget: unable to resolve host address “mirrors.aliyun.com”",
            "yun源出错"
        ]
    }
}
ok: [web2] => {
    "rrr": {
        "changed": true,
        "failed": false,
        "rc": 0,
        "stderr": "Shared connection to 192.168.200.133 closed.\r\n",
        "stderr_lines": [
            "Shared connection to 192.168.200.133 closed."
        ],
        "stdout": "/usr/bin/wget\r\n--2018-11-12 16:03:20--  http://mirrors.aliyun.com/repo/epel-6.repo\r\nResolving mirrors.aliyun.com... 122.72.3.220, 122.72.3.219, 122.72.3.221, ...\r\nConnecting to mirrors.aliyun.com|122.72.3.220|:80... connected.\r\nHTTP request sent, awaiting response... 200 OK\r\nLength: 664 [application/octet-stream]\r\nSaving to: “epel-6.repo”\r\n\r\n\r 0% [                                       ] 0           --.-K/s              \r100%[======================================>] 664         --.-K/s   in 0s      \r\n\r\n2018-11-12 16:03:21 (62.4 MB/s) - “epel-6.repo” saved [664/664]\r\n\r\n",
        "stdout_lines": [
            "/usr/bin/wget",
            "--2018-11-12 16:03:20--  http://mirrors.aliyun.com/repo/epel-6.repo",
            "Resolving mirrors.aliyun.com... 122.72.3.220, 122.72.3.219, 122.72.3.221, ...",
            "Connecting to mirrors.aliyun.com|122.72.3.220|:80... connected.",
            "HTTP request sent, awaiting response... 200 OK",
            "Length: 664 [application/octet-stream]",
            "Saving to: “epel-6.repo”",
            "",
            "",
            " 0% [                                       ] 0           --.-K/s              ",
            "100%[======================================>] 664         --.-K/s   in 0s      ",
            "",
            "2018-11-12 16:03:21 (62.4 MB/s) - “epel-6.repo” saved [664/664]",
            ""
        ]
    }
}

PLAY RECAP *************************************************************************************************
web1                       : ok=5    changed=1    unreachable=0    failed=0
web2                       : ok=5    changed=1    unreachable=0    failed=0 

这样Nginx服务就先简单的搭建成功,需要主要目前没有任何的配置文件和启动服务

接下来我搭建mysql

原文地址:https://www.cnblogs.com/cash-su/p/9988129.html

时间: 2024-08-30 17:53:51

用ansible剧本搭建lnmp的相关文章

ansible自动化安装lnmp

今天尝试用ansible自动化编译安装了lnmp环境,是以把自己的见解和大家分享,不足之处还望大家指正. lnmp的构成 lnmp = linux + nginx + mysql + php/python/perl 下面给大家介绍下我的安装步骤 系统:linux7 首先下载lnmp环境所需模块,创建ansible角色 # mkdir -pv /tmp/roles/{mysql,php,nginx}/{files,vars,templates,tasks,handlers,meta} # cd /

搭建lnmp环境,部署php动态网站

搭建LNMP 前言:"N"代表Nginx与apache的作用一样,都是为了搭建网站服务器,由俄罗斯人lgor sysoev开发,其特点是占有内存少,并发能力强,单台物理服务器可支持3万-5万个并发请求,中国使用nginx网站用户有:百度.京东.新浪.网易.腾讯.淘宝等. 通过下面的实验搭建LNMP环境,部署天空影城的php动态网站 本实验在虚拟机中运行,使用Redhat6.5系统部署! 一.安装及运行 1.搭建yum仓库,安装支持软件 nginx的配置及运行需要pcre,zlib等软件

puppet 搭建lnmp架构

pupppet 搭建lnmp架构: [[email protected] puppet]# tree modules/ modules/ |-- httpd |   |-- files |   |   `-- httpd.conf |   `-- manifests |       |-- config.pp |       |-- init.pp |       |-- install.pp |       `-- service.pp |-- mysqld |   |-- files |  

搭建LNMP+CI环境

首先搭建 LNMP 的服务器环境 安装 Nginx, MySQL 和 PHP 软件包,执行以下命令 yum install -y nginx mariadb-server mariadb php php-fpm php-mysql 启动并检查 Nginx 和 PHP 的安装情况 修改 /etc/nginx/nginx.conf,可参考下面的配置示例: nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/er

搭建LNMP中遇到PHP只能下载无法打开的处理

搭建LNMP中nginx能正常访问,但PHP文件只能下载无法打开的问题处理方法 首先,我们先了解下安装nginx后的目录: |--nginx |-conf.d |-default.conf |-fastcgi_params.default |-nginx.conf |-uwsgi_params.default |-default.d     |-koi-utf |-nginx.conf.default |-win-utf |-fastcgi.conf |-koi-win |-scgi_param

CentOS源码安装搭建LNMP全过程(包括nginx,mysql,php,svn)

服务器环境为:CentOS6.5 64位 目标:搭建LNMP(Linux + Nginx + MySQL + PHP +SVN),其中svn是用来代替ftp,方便开发中调试同步代码 相关目录:所有软件都安装到/www/目录下,在www目录下新建web文件夹作为网站的根路径,www目录下新建wwwsvn作为svn的仓库地址./www/software用来放nginx,mysql,php的安装包和源码.nginx运行分组和账户www:www 一,安装前的准备 yum -y install ntp m

源码搭建LNMP

源码安装LNMP 作者:尹正杰 前言:非常简单的一个平台LNMP,在生产实际环节中我们也经常用到! 二话不说,开始享受我们的搭建过程吧! 一.源码安装nginx 1.安装依赖包 [[email protected] yinzhengjie]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-deve

puppet补充--搭建lnmp &#160; 以及dashboard,passenger

puppet搭建lnmp server4 #cd /etc/puppet/modules #cp -r httpd nginx #cd files #rm -fr httpd.conf #rm -fr * ../templates 编写puppet执行脚本 nginx-install.sh #touch nginx-install.sh #chmod +x nginx-install.sh 脚本内容如下 #!/bin/bash yum install -y openssl-devel pcre-

搭建lnmp环境

本次实验中搭建lnmp环境所使用的软件下载http://链接:http://pan.baidu.com/s/1hsCqI5u 密码:ndsy 1:首先要安装的mysql:一般我们把下载的安装包放在/usr/local/src下面: 首先解压安装包: [[email protected] src]# tar zvxf mysql-5.1.73-linux-i686-glibc23.tar.gz 把解压后的文件移至/usr/local/下: [[email protected] src]# mv m