用三台机器 做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. windows下tomcat闪退问题(启动失败)

    1. 第一种情况:Java jdk环境变量没配置或配置有问题 java jdk详细的配置过程这里贴一下:https://jingyan.baidu.com/article/6dad5075d1dc40 ...

  2. Mybatis获取自动增长Id

    Mybatis获取自动增长Id MyBatis成功插入后获取自动增长的id 1.向xxMapping.xml配置中加上两个配置. <insert id="insertUser" ...

  3. Day 09 函数

    目录 函数 函数的基本概念 为何使用函数 定义函数 什么是参数(形参,parameter) 定义函数的三种形式 无参函数 有参函数 空函数 函数的参数 形参和实参(parameter & ar ...

  4. Vue-兄弟组件传值

    学习博客:https://www.jianshu.com/p/b10b3ac3729a

  5. 伸缩容器-display:flex设置flex属性的理解

    1.flex属性 1.1 flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto. flex-grow: 定义项目的放大比例,默认为0,即 ...

  6. django----Sweetalert bulk_create批量插入数据 自定义分页器

    目录 一.Sweetalert使用AJAX操作 二.bulk_create 三.分页器 divmod 分页器组件 自定义分页器的使用 一.Sweetalert使用AJAX操作 ​ sweetalert ...

  7. java—将数据库读取的list转tree

    一.引言 有时候我们从数据库中读取出了一个表的数据,比如存储的是中国的省市县的ID.名称与父节点ID,读出来的数据并不是前台想要的,这个时候我们要想法处理一下都出来的list,将它变为一个树. 比如直 ...

  8. C# 使用自带Microsoft.Office.Interop.Excel简单操作Excel文件

    项目添加应用 Microsoft.Office.Interop.Excel.dll 文件 引用命名空间: using Excel = Microsoft.Office.Interop.Excel; 简 ...

  9. 《MySQL数据库》MySQL数据库安装(linux)

    1.  下载安装包: 百度网盘:链接: https://pan.baidu.com/s/1toGl8O9gMBpDWn0mHWwFyg 提取码: i51g 官网下载:https://dev.mysql ...

  10. CQRS+ES项目解析-Diary.CQRS

    在<当我们在讨论CQRS时,我们在讨论些神马>中,我们讨论了当使用CQRS的过程中,需要关心的一些问题.其中与CQRS关联最为紧密的模式莫过于Event Sourcing了,CQRS与ES ...