Centos7 系统使用Playbook批量部署多台LNMP环境

使用Playbook批量部署多台LNMP环境

 配置absible源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

 yum -y install ansible

配置主机清单
定义主机名

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

[webservers]

192.168.10.12

192.168.10.13
设置ssh免密连接

[root@cjq11 ~]# yum install sshpass -y(如果安装不了,下面源码安装)

源码安装sshpass脚本

[root@cjq11 ~]# vim sshpass.sh

#!/bin/bash

#这是源码安装sshpass的脚本

get="wget http://downloads.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz"

yum_install="yum -y install gcc gcc-c++ make zlib-devel pcre pcre-devel openssl-devel"

app="sshpass-1.06.tar.gz"

directory="/usr/local/src/sshpass-1.06"

precompile="./configure"

if  $get && $yum_install 1>/dev/null ; then

      if tar -zxf $app -C /usr/local/src/ && cd $directory 1>/dev/null ; then

       if $precompile 1>/dev/null ; then

         if make -j 2 && make install 1>/dev/null ; then

          echo "sshpass install ok!"

         else

          echo "sshpass install errot!"

         fi

       else

         echo "cmake error!"

         exit 1

       fi

      else

       echo "tar error!"

       exit 1

      fi

else

  echo "yum error!"

  exit 1

fi

自动配置ssh连接的脚本

[root@cjq11 ~]# vim keygen.sh

#!/bin/bash

#这是自动配置ssh连接的脚本

echo " 192.168.10.12

192.168.10.13 " > ip.list    #这个文件的IP需要改成自己的客户端IP

rpm -q sshpass &>/dev/null

[ -f /root/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa -P '' -q

export SSHPASS=123456

while read ip

do

sshpass -e ssh-copy-id -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" $ip

done<ip.list
配置playbook创建一个lnmp构建的任务
创建相关文件

[root@cjq11 ~]# mkdir -pv /etc/ansible/lnmp/roles/{prepare,nginx,mysql,php}/{tasks,files,templates,vars,meta,default,handlers}

构建nginx的任务
配置nginxtasks

[root@cjq11 ]# cd /etc/ansible/lnmp/roles

[root@cjq11 roles]# vim nginx/tasks/main.yml

- name: 下载nginx

  get_url:

    url: "https://nginx.org/download/nginx-1.22.0.tar.gz"

    dest: /root/

- name: 下载依赖安装包

  shell: yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel  pcre pcre-devel

- name: 解压

  shell: tar -zxf "/root/nginx-1.22.0.tar.gz"

- name: 进入目录

  shell: cd /usr/local/src/nginx-1.22.0

- name: 预编译

  shell: ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module

  args:

    chdir: /usr/local/src/nginx-1.22.0

- name: 编译和安装

  shell: make -j 2 && make install

  args:

    chdir: /usr/local/src/nginx-1.22.0

- name:启动nginx

 shell: /usr/local/nginx/sbin/nginx
部署MySQL8
MySQL8.0.25下载(8.0.35安装方法相同)

官网:www.mysql.com

把安装包上传到ansible服务器

[root@cjq11 roles]# cd /etc/ansible/lnmp/roles

构建mysql的任务
配置mysqltasks

[root@cjq11 roles]# vim mysql/tasks/main.yml

- name: install the mysql

- name: 移除mariadb数据库

  shell: yum -y remove mariadb-libs.x86_64

-name: 传软件包

  copy:

    src: /root/mysql-8.0.25-1.el7.x86_64.rpm-bundle.tar

    dest: /root/

- name: 创建mysql解压目录

  file:

    path: /usr/local/mysql/

    state: directory

- name: 解压

  shell:  tar -xvf mysql-8.0.25-1.el7.x86_64.rpm-bundle.tar -C /usr/local/mysql/

- name: 安装MySQL客户端工具

  shell: rpm -ivh mysql-community-common-8.0.25-1.el7.x86_64.rpm --nodeps --force

  args:

    chdir: /usr/local/mysql/

- name: 安装MySQL的库文件

  shell: rpm -ivh mysql-community-libs-8.0.25-1.el7.x86_64.rpm --nodeps --force

  args:

    chdir: /usr/local/mysql/

- name: 安装MySQL服务器的主包

  shell: rpm -ivh mysql-community-client-8.0.25-1.el7.x86_64.rpm --nodeps --force

  args:

    chdir: /usr/local/mysql/

- name: 安装MySQL的公共文件

  shell: rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm --nodeps --force

  args:

    chdir: /usr/local/mysql/

- name: 初始化

  shell: mysqld --initialize

- name: 改权限

  file:

    path: /var/lib/mysql/

    group: mysql

    owner: mysql

    recurse: yes

  notify: restart mysqld
构建mysql的handlers

[root@cjq11 roles]#vim mysql/handlers/main.yml

- name: restart mysqld

  service: name=mysqld enabled=yes state=restarted
构建PHP源码安装的任务
配置phptasks

[root@cjq11 roles]#vim php/tasks/main.yml

- name: 下载oniguruma5php

  shell: wget https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.8-1.el7.remi.x86_64.rpm --no-check-certificate

- name: 下载oniguruma5php-devel

  shell: wget https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.8-1.el7.remi.x86_64.rpm --no-check-certificate

- name: 下载Libmcrypt

  shell: wget https://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz --no-check-certificate

- name: 下载依赖安装包

  shell: yum -y install oniguruma5php-*

- name: 解压libmcrypt

  shell: tar -zxf "libmcrypt-2.5.8.tar.gz"

- name: 预编译libmcrypt

  shell: ./configure --prefix=/usr/local/libmcrypt-2.5.8

  args:

    chdir: /root/libmcrypt-2.5.8

- name: 编译和安装libmcrypt

  shell: make && make install

  args:

    chdir: /root/libmcrypt-2.5.8

- name: 下载php

  shell: wget https://www.php.net/distributions/php-8.1.9.tar.gz --no-check-certificate

- name: 下载依赖安装包

  shell: yum -y install php-mcrypt libmcrypt libmcrypt-devel  autoconf  freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c bzip2-devel libmcrypt-devel freetype-devel libjpeg-devel sqlite-devel libwebp expat-devel

- name: 解压php

  shell: tar -zxf "php-8.1.9.tar.gz" -C /usr/local/src/

- name: 预编译php

  shell: ./configure --prefix=/usr/local/php8.1.9 --enable-mysqlnd  --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-gd --with-zlib --enable-sysvshm --enable-mbstring --with-freetype --with-expat --enable-xml --with-mhash --with-config-file-path=/etc --with-config-file-scan-dir=/usr/local/php8.1.9/etc/ --with-bz2 --with-jpeg

  args:

    chdir: /root/libmcrypt-2.5.8

- name: 编译安装php

  shell: make -j 2 && make install

  args:

    chdir: /root/libmcrypt-2.5.8        

                                                                                            

定义整个的任务入口文件

[root@cjq11 ~]#  vim /etc/ansible/lnmp/roles/site.yml

- name: prepare build

  remote_user: root

  hosts: webservers

  roles:

    - prepare    #要执行的roles,确保roles目录下有同名的文件夹

  tags: prepare   #给任务打标签,方便单独测试



- name: lnmp build mysql

  remote_user: root

  hosts: webservers

  roles:

    - mysql

  tags: mysql



- name: lnmp build php

  remote_user: root

  hosts: webservers

  roles:

    - php

  tags: php



- name: lnmp build nginx

  remote_user: root

  hosts: webservers

  roles:

    - nginx

  tags: nginx
根据tags标签测试服务

[root@cjq11 ~]#ansible-playbook -C /etc/ansible/lnmp/roles/site.yml -t nginx

开始部署

[root@cjq11 ~]#ansible-playbook -i /etc/ansible/hosts  /etc/ansible/lnmp/roles/site.yml

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/319172.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

常见的加密算法

加密算法 AES 高级加密标准(AES,Advanced Encryption Standard)为最常见的对称加密算法(微信小程序加密传输就是用这个加密算法的)。对称加密算法也就是加密和解密用相同的密钥&#xff0c;具体的加密流程如下图&#xff1a; RSA RSA 加密算法是一种典型的非对称加密算法&am…

山西电力市场日前价格预测【2024-01-15】

日前价格预测 预测说明&#xff1a; 如上图所示&#xff0c;预测明日&#xff08;2024-01-15&#xff09;山西电力市场全天平均日前电价为399.10元/MWh。其中&#xff0c;最高日前电价为583.33元/MWh&#xff0c;预计出现在18:15。最低日前电价为275.09元/MWh&#xff0c;预计…

第 3 场 蓝桥杯小白入门赛 解题报告 | 珂学家 | 单调队列优化的DP + 三指针滑窗

前言 整体评价 T5, T6有点意思&#xff0c;这场小白入门场&#xff0c;好像没真正意义上的签到&#xff0c;整体感觉是这样。 A. 召唤神坤 思路: 前后缀拆解 #include <iostream> #include <algorithm> #include <vector> using namespace std;int main()…

二分图最大匹配——匈牙利算法详解

文章目录 零、前言一、红娘牵线二、二分图最大匹配2.1概念2.2交替路2.3增广路2.4匈牙利算法2.4.1算法原理2.4.2算法示例2.4.3代码实现 3.OJ练习3.1模板3.2棋盘覆盖3.3車的放置 零、前言 关于二分图的基本知识见&#xff1a;二分图及染色法判定 一、红娘牵线 一位红娘近日遇到一…

Word插件-大珩助手-手写电子签名

手写签名 支持鼠标写&#xff0c;支持触摸屏写&#xff0c;点击画笔按钮切换橡皮擦&#xff0c;支持清空画板重写&#xff0c;点击在word中插入签名&#xff0c;可插入背景透明的签字图 素材库-保存签名 将写好的签字图复制粘贴到素材库中&#xff0c;以便永久使用&#xff…

详解Java之Spring框架中事务管理的艺术

第1章&#xff1a;引言 大家好&#xff0c;我是小黑&#xff0c;咱们今天聊聊Spring框架中的事务管理。不管是开发小型应用还是大型企业级应用&#xff0c;事务管理都是个不可避免的话题。那么&#xff0c;为什么事务管理这么重要呢&#xff1f;假设在银行系统中转账时&#x…

OpenCV——多分辨率LBP的计算方法

目录 一、算法原理1、原理概述2、参考文献 二、代码实现三、结果展示 OpenCV——多分辨率LBP的计算方法由CSDN点云侠原创&#xff0c;爬虫自重。如果你不是在点云侠的博客中看到该文章&#xff0c;那么此处便是不要脸的爬虫。 一、算法原理 1、原理概述 基本LBP算子虽然在早期…

Qt/QML编程学习之心得:使用camera摄像头(35)

汽车应用中,camera起到了越来越多的作用,数字化的作用,这点无可争议,而作为GUI设计工具,如何让Camera类的应用能更好的发挥作用呢? You can use Camera to capture images and movies from a camera, and manipulate the capture and processing settings that get appl…

关于 setData 同步异步的问题

小程序官方文档中的回答解释: 所以大概意思就是: 1.setData在逻辑层的操作是同步&#xff0c;因此this.data中的相关数据会立即更新,比如下面的例子: const a 1 this.setData({b: a ? a : , }) console.log(that.data.b) // 1 2. setData在视图层的操作是异步&#xff0c;…

Linux Ubuntu搭建我的世界Minecraft服务器实现好友远程联机MC游戏

文章目录 前言1. 安装JAVA2. MCSManager安装3.局域网访问MCSM4.创建我的世界服务器5.局域网联机测试6.安装cpolar内网穿透7. 配置公网访问地址8.远程联机测试9. 配置固定远程联机端口地址9.1 保留一个固定tcp地址9.2 配置固定公网TCP地址9.3 使用固定公网地址远程联机 前言 Li…

C语言之从浅入深一步一步全方位理解指针【附笔试题】

文章目录 前言从浅入深理解指针《第一阶段》一、内存和地址1.1 内存1.2 究竟该如何理解编址 二、指针变量和地址2.1 取地址操作符&#xff08;&&#xff09; 三、指针变量和解引用操作符&#xff08;*&#xff09;3.1 指针变量3.2 如何拆解指针类型3.3 解引用操作符 四、指…

web网页设计学习记录(五)

1.如何设置背景色呢&#xff1f; 格式为&#xff1a; <body bgcolor"色彩值"> “色彩值”可以为色彩的英文名或相应十六进制值。 2.如何将图片作为背景呢&#xff1f; 格式为&#xff1a;<body background"图片文件名"> 使用<body&g…

具于xilinx FPGA的可动态配置DDS频率控制字的DDS IP核使用例程详解

目录 1 概述2 IP examples功能3 IP 使用例程4注意事项5 DDS IP Examples下载位置 1 概述 本文用于讲解xilinx IP 的dds ip examples&#xff08;动态配置频率&#xff09;的功能说明&#xff0c;方便使用者快速上手。 2 IP examples功能 本examples 是月隐编写的针对DDS的使…

一分钟找到所有的中文核心期刊

1.进入中国知网找到出版物检索 2.在出版来源导航这里选择期刊导航 3.右边拉到底选择核心期刊导航 4.选择自己专业的期刊即可

软件设计不是CRUD(10):低耦合模块设计理论——业务抽象:从需求中提取业务维度

接上文《软件设计不是CRUD(9):低耦合模块设计理论——设计落地所面临的挑战》 2、什么是业务抽象 业务抽象是一种将需求落地成模块功能的设计思想,是对业务需求和技术设计进行转换、隔离的一种分析方法。经过业务抽象后的业务模块一般具有较高的业务屈服度,能更大程度满…

Hex Editor的使用教程(VS Code)

Hex Editor&#xff08;十六进制编辑器&#xff09;是一种用于查看和编辑计算机文件的低级别编辑工具。与常规文本编辑器不同&#xff0c;它允许用户直接查看和修改文件的二进制数据。在 Hex Editor 中&#xff0c;数据通常以十六进制&#xff08;hex&#xff09;格式显示&…

Arduino| IDE下载、安装和设置以及开发板的连接

IDE下载、安装和设置以及开发板的连接 IDE下载IDE安装IDE设置首选项——设置语言、字体、主题、地址等等开发板管理器——添加开发板 开发板的连接 IDE下载 第一步&#xff1a;进入Arduino官网https://www.arduino.cc。 第二步&#xff1a;选择导航栏的Software&#xff0c;然…

【论文阅读笔记】Prompt Tuning for Parameter-efficient Medical Image Segmentation

Fischer M, Bartler A, Yang B. Prompt tuning for parameter-efficient medical image segmentation[J]. Medical Image Analysis, 2024, 91: 103024. 【开源】 【核心思想】 本文的核心思想是提出了一种用于医学图像分割的参数高效的提示调整&#xff08;Prompt Tuning&…

Flutter开发进阶之动画

Flutter开发进阶之动画 在Flutter中&#xff0c;动画是至关重要的一个部分&#xff0c;它能够为应用程序提供更加丰富和生动的用户体验&#xff0c;Flutter中的动画系统是UI框架的核心功能之一&#xff0c;也是开发者学习Flutter框架的重要部分&#xff0c;由于动画原理在所有…

实时时钟芯片DS1302单片机C语言驱动程序

实时时钟RTC相关索引 1.单片机RTC及时钟芯片的时间到底从哪一年起始&#xff1f; 2.STM32F103单片机内部RTC实时时钟驱动程序 3.实时时钟芯片DS1302单片机C语言驱动程序 一、DS1302简介 DS1302 是 DALLAS&#xff08;达拉斯&#xff09;公司推出的一款涓流充电时钟芯片。 主…