用三台机器 做ansible+playbook 搭建lnmp环境

IP分配

ansible 主机192.168.202.132

lnmp第一台主机 192.168.202.131

lnmp第一台主机 192.168.202.133

1.1 ansible主机安装ansible

[root@localhost ~]# yum -y install ansible
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.jdcloud.com
* extras: mirror.bit.edu.cn 

1.2 ansible主机生成密钥设置免密码登录

[root@localhost ~]# ssh -keygen
Bad escape character 'ygen'.
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_r
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_
Your public key has been saved in /root/.ssh/id_rsa.
The key fingerprint is:
SHA256:snafmBirD5A4bkRNfs/yraWQ7BqJf4SKpLd0UO5yZyA rhost
The key's randomart image is:
+---[RSA 2048]----+
| . |
| + |
| . o.. |
|.. +. o |
|o.E +..oS |
|oo.*oo+o. |
|+++o*+*..o |
|+oo+o*.=++ . |
| ..++++oo o |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id root@192.168.202.131
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be i "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.202.131 (192.168.2can't be established.
ECDSA key fingerprint is SHA256:+YOuMKydPwvlPwXHq3Cgj6X6jdlupF1W3A.
ECDSA key fingerprint is MD5:33:f9:54:0f:ce:1e:53:96:96:29:e3:04:7c.
Are you sure you want to continue connecting (yes/no
/usr/bin/ssh-copy-id: INFO: attempting to log in wit key(s), to filter out any that are already installe
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be in- if you are prompted now it is to install the new k
root@192.168.202.131's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root202.131'"
and check to make sure that only the key(s) you wantdded.
[root@localhost ~]# ssh-copy-id root@192.168.202.133

  

1.3 ansible主机配置

[root@localhost ~]# vim /etc/ansible/hosts 

[lnmp]
192.168.202.131
192.168.202.133

 如图:

1.4 编写ansible的playbook

---
- hosts: lnmp
tasks:
- name: "安装需要的环境"
yum: name=gcc,gcc-c++,make,php,php-gd,php-mysql,php-fpm,pcre-devel,zlib-devel,mariadb,mariadb-server state=latest
- name: "导入nginx包"
unarchive: src=nginx-1.16.1.tar.gz dest=/root
- name: "编译安装"
shell: cd /root/nginx-1.16.1 && ./configure && make && make install
- name: "分发配置文件"
copy: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf
- name: "分发主界面"
copy: src=info.php dest=/var/www/html/info.php
- name: 启动nginx
shell: /usr/local/nginx/sbin/nginx
- name: "启动mysql"
shell: systemctl restart mariadb
- name: "启动php-fpm"
shell: systemctl restart php-fpm
- name : "关闭防火墙"
shell: systemctl stop firewalld
- name: "关闭selinux"
shell: setenforce 0
~

1.4.2 更改nginx的配置文件

1.4.3 分发一个php的测试界面

1.4.4 执行ansible-playbook

1.4.5 展示效果看看lnmp是否搭建成功

ansible+playbook 搭建lnmp环境的更多相关文章

  1. CentOS6.6搭建LNMP环境

    CentOS6.6搭建LNMP环境 1.设置yum源,本地安装依赖包 1 yum -y install gcc gcc-c++ automake autoconf libtool make 2.下载依 ...

  2. Yum搭建LNMP环境(动、静、库分离)(week4_day5)--技术流ken

    前言 本篇博客使用yum来搭建lnmp环境,将采用动态,静态以及数据库分开安装的方式即nginx,php,mysql.会被分开安装在不同的服务器之上,搭建出来一套lnmp环境,并部署wordpress ...

  3. [Linux] deepin15.8搭建LNMP环境

    LAMP和LNMP LAMP==Linux+Apache+Mysql+PHP LNMP==Linux+Nginx+Mysql+PHP 安装nginx sudo apt install nginx 安装 ...

  4. CentOS 7 源码搭建LNMP环境

    搭建 LNMP 环境 源码包版本 :  CentOS Linux  7 nginx-1.15.1.tar.gz  mysql-boost-5.7.21.tar.gz  php-7.2.7.tar.gz ...

  5. Vmware搭建LNMP环境(Centos7+Nginx+Mysql+PHP7.1.8)

    参考:1.Linux学习之CentOS(一)----在VMware虚拟机中安装CentOS 7(图文教程) 2.Centos7搭建LNMP环境 3.MySQL5.7修改默认root密码 4.CentO ...

  6. ubuntu通过apt-get方式搭建lnmp环境以及php扩展安装

    v 一直是在用的lnmp的集成安装包搭建lnmp环境,因为工作需要需要安装ldap扩展,在网上怎么都找不到源码安装包,只能卸载掉原来的lnmp环境,用ubuntu的php5-ldap扩展, 在安装中遇 ...

  7. Mac下docker搭建lnmp环境 + redis + elasticsearch

    之前在windows下一直使用vagrant做开发, 团队里面也是各种开发环境,几个人也没有统一环境,各种上线都是人肉,偶尔还会有因为开发.测试.生产环境由于软件版本或者配置不一致产生的问题, 今年准 ...

  8. WIN10 vagrant和virtualbox虚拟机和一键搭建lnmp环境配置thinkphp虚拟主机

    版本:win10系统 virtualbox:5.1.26 vagrant :1.9.7 centos 7.0 xshell/git 首先下载好对应版本的软件 配置vagrant和virtualbox ...

  9. docker搭建lnmp环境(问题,资料,命令)

    入门参考 http://www.runoob.com/docker/docker-install-nginx.html 十大常用命令玩转docker 1. #从官网拉取镜像 docker pull & ...

随机推荐

  1. 如何用css画一个文件上传图案?

    如下图,如果是你,你会怎么实现: 通常我们会通过字体图标来显示中间的加号,外层用一个div包裹即可:或者使用伪元素来模拟中间的一横一竖,这都比较麻烦. 其实我们可以直接使用div+css就可以实现. ...

  2. 贝壳2020——Java校招笔试题

    算法题4道: 题目描述: 给出n个正整数,要求找出相邻两个数字中差的绝对值最小的一对数字,如果有差的绝对值相同的,则输出最前面的一对数.(2<n<=100,正整数都在10^16范围内) 输 ...

  3. 利用 Redis 来优化功能部署和错误分类

    来源:Redislabs 作者:Shabih Syed 翻译:Kevin (公众号:中间件小哥) 为了让系统运行更流畅,又避免 Knights Capital 在 2012 年犯下的 4.6 亿美元的 ...

  4. 【ZooKeeper系列】2.用Java实现ZooKeeper API的调用

    温馨提示:在这里我再次提个小要求,希望大家能习惯看官方文档,文档虽然是英文但用词都比较简单,基本都能看懂文档表达的意思.授之以鱼不如授之以渔的道理相信大家都明白,也希望通过猿人谷的这个ZooKeepe ...

  5. Node.js:深入浅出 http 与 stream

    原文链接:https://github.com/iNuanfeng/blog/issues/4 作者:暖风叔叔 前言 stream(流)是Node.js提供的又一个仅在服务区端可用的模块,流是一种抽象 ...

  6. 【docker】Dockerfile

    [docker]Dockerfile 转载: ============================================================= =============== ...

  7. 【hibernate】重写物理表名和列明

    [hibernate]重写物理表名和列明 转载:https://www.cnblogs.com/yangchongxing/p/10357123.html 假设你的数据库命名有这样的需求,表都以 yc ...

  8. Oracle trunc函数的使用

    1. 对日期的操作 2. 对数字的操作 1.对日期的操作 /**************日期********************/ SELECT TRUNC(SYSDATE) FROM DUAL; ...

  9. Cortex-A7 MPCore 简介与处理器运行模型

    Cortex-A7 MPcore 处理器支持 1~4 核,通常是和 Cortex-A15 组成 big.LITTLE 架构的,Cortex-A15 作为大核负责高性能运算,比如玩游戏啥的,Cortex ...

  10. 代码管理平台之git

    yum install -y gitmkdir -p /date/gitrootcd !$git init git add 1.txtgit commit -m "add 1.txt&quo ...