当前位置: 首页 > news >正文

playbooks 分布式部署 LNMP

1、环境配置

  • ansible 服务器    192.168.10.10
  • nginx   服务器    192.168.10.20
  • mysql  服务器    192.168.10.21
  • php     服务器    192.168.10.22
     

2、安装 ansble 

#192.168.10.10节点
yum install -y epel-release	 #先安装 epel 源
yum install -y ansible

配置主机清单 

cd /etc/ansible
vim hosts       
[nginx]
192.168.10.20[mysql]
192.168.10.21[php]
192.168.10.22

设置免密登录

 #3、ansible默认使用ssh连接,所以管理前要设置免密登录#配置密钥对验证ssh-keygen -t     #一路回车,生成密钥文件​vim /etc/ssh/ssh_config      #修改ssh服务端和ssh客户端配置文件StrictHostKeyChecking no     #35行,取消注释,将ask修改为no,开启免交互​systemctl restart sshd       #重启sshd//配置密钥对验证
ssh-keygen -t rsa		#一路回车,使用免密登录
sshpass -p 'root的密码' ssh-copy-id root@192.168.10.20
sshpass -p 'root的密码' ssh-copy-id root@192.168.10.21
sshpass -p 'root的密码' ssh-copy-id root@192.168.10.22

3、配置安装nginx

配置nginx相关文件

#配置 nginx 支持 PHP 解析
vim nginx.conf.j2server {listen       {{server_ip}}:{{http_port}};server_name  {{host_name}};charset utf-8;#access_log  logs/host.access.log  main;location / {root   html;index  index.php index.html;}......location ~ \.php$ {root           html;fastcgi_pass   192.168.10.22:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;include        fastcgi_params;}

编写 lnmp.yaml 的 nginx 部分

- name: nginx playhosts: webserversremote_user: rootgather_facts: falsevars:- nginx_addr: 192.168.10.20- nginx_port: 80- nginx_hostname: www.xy101.com- root_dir: /var/www/html- php_addr: 192.168.10.22- php_port: 9000tasks:- name: disable firewalld- service: name=firewalld state=stopped enabled=no- name: disable selinuxcommand: 'setenforce 0'ignore_errors: true- name: copy nginx repocopy: src=/opt/nginx/nginx.repo dest=/etc/yum.repos.d/- name: install nginxyum: name=nginx state=latest- name: create root  dirfile: path={{root_dir}} state=directory- name: copy nginx config template filetemplate: src=/opt/nginx/nginx.conf.j2 dest=/etc/nginx/nginx.confnotify: 'reload nginx'- name: create nfs configcopy: content="{{root_dir}} 192.168.10.0/24(rw,rsync,no_root_squash)" dest=/etc/exports- name: restart rpcbind,nfs,nginxservice: name={{item}} state=restarted enabled=yeswith_items:- rpcbind- nfs- nginxhandlers:- name: reload nginxservice: name=nginx state=reloaded

测试nginx

#在ansible服务器运行
cd /etc/ansible/playbooks/
ansible-playbook lnmp.yaml --syntax-check    #检查yaml文件的语法是否正确
ansible-playbook lnmp.yaml
#在 nginx 服务器查看
systemctl status nginx
netstat -lntp | grep nginx

4、安装 mysql

mysql相关文件配置

准备mysql初始化脚本文件

编写 lnmp.yaml 的 mysql 部分

- name: mysql playhosts: dbserversremote_user: rootgather_facts: falsetasks:- name: disable mysql_server firewalldsrvice: name=firewalld state=stopped enabled=no- name: disable mysql_server selinuxcommand: 'setenforce 0'ignore_errors: true- name: remove mariadbyum: name=mariadb* state=absent- name: copy mysql repocopy: src=/opt/mysql/mysql-community.repo dest=/etc/yum.repos.d/- name: modify mysql reporeplace: path=/etc/yum.repos.d/mysql-community.repo regexp="gpgcheck=1" replace="gpgcheck=0"- name: install mysqlyum: name=mysql-server state=present- name: start mysqlservice: name=mysql state=started enable=yes- name: init mysqlscript: '/opt/mysql/mysql-init.sh'

5、安装php

- name: php playhosts: phpserversremote_user: rootgather_facts: falsevars:- php_username: nginx- php_addr: 192.168.10.22:9000- nginx_addr: 192.168.10.20- root_dir: /var/www/htmltasks:- name: disable php_server firewalldservice: name=firewalld state=stopped- name: disable php_server selinuxcommand: 'setenforce 0'- name: unarchive php tar pkgunarchive: copy=yes src=/opt/php/php.tar.gz dest=/mnt/- name: copy local repocopy: src=/opt/php/local.repo dest=/etc/yum.repos.d/- name: create reposhell: 'createrepo /mnt && yum clean all && yum makecache'- name: install phpyum: name=php72w,php72w-cli,php72w-common,php72w-devel,php72w-embedded,php72w-gd,php72w-mbstring,php72w-pdo,php72w-xml,php72w-fpm,php72w-mysqlnd,php72w-opcache,php72w-ldap,php72w-bcmath state=present- name: create php useruser: name={{php_username}} shell=/sbin/nologin create_home=no- name: modify php.inireplace: path=/etc/php.ini regexp=";date.timezone =" replace="date.timezone = Asia/Shanghai"- name: modify user and group in www.confreplace: path=/etc/php-fpm.d/www.conf regexp="127.0.0.1" replace="{{nginx_addr}}"notify: "reload php-fpm"- name: start php-fpmservice name=php-fpm state=started enabled=yes- name: create www root dirfile: path={{root_dir}} state=directory- name: mount nfsmount: src="{{nginx_addr}}:{{root_dir}}" path={{root_dir}} fstype=nfs state=mounted opts="defaults,_netdev"handlers:- name: reload php-fpmservice: name=php-fpm state=reloaded

访问测试

相关文章:

playbooks 分布式部署 LNMP

1、环境配置 ansible 服务器 192.168.10.10nginx 服务器 192.168.10.20mysql 服务器 192.168.10.21php 服务器 192.168.10.22 2、安装 ansble #192.168.10.10节点 yum install -y epel-release #先安装 epel 源 yum install -y ansible配置主机清单 …...

成为git砖家(8): 使用 git log 查询范围内的 commit

文章目录 1. 查询 git log 的文档2. 不带任何参数: git log 啥意思&#xff1f;3. git log 最主要功能是什么&#xff1f;4. git log <commit1>..<commit2> 什么意思5. 查看最近n次commit6. References 1. 查询 git log 的文档 git help log --web市面上针对 git …...

Win10出现错误代码0x80004005 一键修复指南

对于 Windows 10 用户来说&#xff0c;错误代码 0x80004005 就是这样一种迷雾&#xff0c;它可能在不经意间出现&#xff0c;阻碍我们顺畅地使用电脑。这个错误通常与组件或元素的缺失有关&#xff0c;它可能源自注册表的错误、系统文件的损坏&#xff0c;或者是软件的不兼容。…...

C++ 基础(类和对象下)

目录 一. 再探构造函数 1.1. 初始化列表&#xff08;尽量使用列表初始化&#xff09; 二. static成员 2.1static成员初始化 三.友元 3.1友元&#xff1a;提供了⼀种 突破类访问限定符封装的方式. 四.内部类 4.1如果⼀个类定义在另⼀个类的内部&#xff0c;这个内部类就叫…...

java RestClientBuilder es 集群 鉴权

在Java中使用RestClientBuilder连接到Elasticsearch集群并进行鉴权&#xff0c;可以通过设置HttpHosts、RequestConfig以及添加相应的Header来实现。 以下是一个示例代码&#xff1a; import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.htt…...

【OpenCV】中saturate_cast<uchar>的含义和用法是什么?

saturate_cast<uchar>主要是为了防止颜色溢出操作&#xff08;0~255&#xff09; if(data<0) data0; elseif(data>255) data255;...

【数据结构】哈希表二叉搜索树详解

&#x1f48e; 欢迎大家互三&#xff1a;2的n次方_ &#x1f48e;所属专栏&#xff1a;数据结构与算法学习 &#x1f341;1. 二叉搜索树 二叉搜索树也称为二叉查找树或二叉排序树&#xff0c;是一种特殊的二叉树结构&#xff0c;它的特点是&#xff1a; 1. 若左树不为空&am…...

【SpringBoot】参数传递之@ModelAttribute

ModelAttribute标注的方法会在Controller类的每个映射URL的控制执行方法之前执行。 ModelAttribute public void findUserById(PathVariable("userId") Long userId,Model model){ model.addAttribute("user",userService.findUserById(userId)); } GetM…...

frp搭建ssh内网穿透

frp软件包下载 检查外网服务器架构 uname -i官网下载对应的版本 https://github.com/fatedier/frp/releases 使用wget或拷贝文件到外网服务器/opt目录下并解压 解压得到frp_0.59.0_linux_amd64文件夹 tar -zxvf frp_0.59.0_linux_amd64.tar.gzfrpc 这是 frp 的客户端可执…...

OpenCV库学习之cv2.normalize函数

OpenCV库学习之cv2.normalize函数 一、简介 cv2.normalize是OpenCV库中的一个函数&#xff0c;用于对图像进行归一化处理。归一化是一种线性变换&#xff0c;可以将图像像素值的范围缩放到指定的区间。这种操作在图像处理中非常有用&#xff0c;特别是在需要将图像数据用于某些…...

LINUX操作系统安全

一、概述内容 操作系统负责计算机系统的资产管理&#xff0c;支撑和控制各种应用程序运行&#xff0c;为用户提供管理计算机系统管理接口。操作系统也是构成网络信息系统的核心关键组件&#xff0c;其安全可靠性决定了计算机系统的安全性和可靠性。 操作系统安全是指满足安全…...

vue3.0学习笔记(三)——计算属性、监听器、ref属性、组件通信

1. computed 函数 定义计算属性&#xff1a; computed 函数&#xff0c;是用来定义计算属性的&#xff0c;计算属性不能修改。 计算属性应该是只读的&#xff0c;特殊情况可以配置 get set 核心步骤&#xff1a; 导入 computed 函数 执行函数 在回调参数中 return 基于响应…...

Elasticsearch面试三道题

针对Elasticsearch的面试题&#xff0c;从简单到困难&#xff0c;我可以给出以下三道题目&#xff1a; 1. Elasticsearch的基本概念与优势 问题&#xff1a;请简要介绍Elasticsearch是什么&#xff0c;并说明它相比传统数据库的优势有哪些&#xff1f; 答案&#xff1a; El…...

大厂面经:大疆嵌入式面试题及参考答案(4万字长文:持续更新)

目录 Linux 系统调用的过程,中间发生了什么? 表格总结 Linux 中断流程,谈谈你对中断上下文的理解 中断流程 中断上下文理解 Linux schedule() 函数的原理和调用的时机 schedule() 函数原理 调用时机 页表实现机制,分页的缺点? 页表机制 分页的缺点 介绍操作系…...

数据结构【有头双向链表】

目录 实现双向链表 双向链表数据 创建双向链表 初始化双向链表创建&#xff08;哨兵位&#xff09; 尾插 打印双向链表 头插 布尔类型 尾删 头删 查询 指定位置后插入 指定位置删除数据 销毁 顺序表和链表的分析 代码 list.h list.c test.c 注意&#xff1a…...

docker 安装jenkins详细步骤教程

Jenkins 是一个开源的持续集成(CI)和持续部署(CD)工具,用于自动化软件开发过程中的构建、测试和部署。 特点和功能: 持续集成:Jenkins 可以自动触发构建过程,检查代码变更并进行构建、测试和部署,以确保团队的代码始终保持可集成状态。 插件生态系统:Jenkins 拥有丰富…...

C++模板函数

C模板函数 函数模板简单的函数模板模板类型推导返回输入的类型&#xff0c;模板返回的类型由输入的决定返回类型的模板参数返回值使用auto&#xff0c;编译器自动推导 默认模板实参模板参数重载函数模板 constexpr关键字 函数模板 简单的函数模板 typename 可以使用class代替…...

c#中的正则表达式和日期的使用(超全)

在 C# 中&#xff0c;正则表达式&#xff08;Regular Expressions&#xff09;是一种强大的文本处理工具&#xff0c;用于执行各种字符串搜索、替换和验证任务。以下是一些常用的正则表达式示例及其用途&#xff1a; 1. 邮箱地址验证 ​ string emailPattern "^[^\s][^…...

论文阅读【检测】:商汤 ICLR2021 | Deformable DETR

文章目录 论文地址AbstractMotivation技术细节多尺度backbone特征MSDeformAttention 小结 论文地址 Deformable DETR 推荐视频&#xff1a;bilibili Abstract DETR消除对目标检测中许多手工设计的组件的需求&#xff0c;同时表现出良好的性能。然而&#xff0c;由于Transfor…...

dpdk发送udp报文

dpdk接收到udp报文后&#xff0c;自己构造一个udp报文&#xff0c;将收到的报文中的源mac&#xff0c;目的mac&#xff0c;源ip&#xff0c;目的ip&#xff0c;源端口和目的端口交换下顺序填充到新的udp报文中&#xff0c;报文中的负载数据和收到的udp保持一致。 注&#xff1…...

多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度​

一、引言&#xff1a;多云环境的技术复杂性本质​​ 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时&#xff0c;​​基础设施的技术债呈现指数级积累​​。网络连接、身份认证、成本管理这三大核心挑战相互嵌套&#xff1a;跨云网络构建数据…...

XCTF-web-easyupload

试了试php&#xff0c;php7&#xff0c;pht&#xff0c;phtml等&#xff0c;都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接&#xff0c;得到flag...

iOS 26 携众系统重磅更新,但“苹果智能”仍与国行无缘

美国西海岸的夏天&#xff0c;再次被苹果点燃。一年一度的全球开发者大会 WWDC25 如期而至&#xff0c;这不仅是开发者的盛宴&#xff0c;更是全球数亿苹果用户翘首以盼的科技春晚。今年&#xff0c;苹果依旧为我们带来了全家桶式的系统更新&#xff0c;包括 iOS 26、iPadOS 26…...

基础测试工具使用经验

背景 vtune&#xff0c;perf, nsight system等基础测试工具&#xff0c;都是用过的&#xff0c;但是没有记录&#xff0c;都逐渐忘了。所以写这篇博客总结记录一下&#xff0c;只要以后发现新的用法&#xff0c;就记得来编辑补充一下 perf 比较基础的用法&#xff1a; 先改这…...

【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】

1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件&#xff08;System Property Definition File&#xff09;&#xff0c;用于声明和管理 Bluetooth 模块相…...

反射获取方法和属性

Java反射获取方法 在Java中&#xff0c;反射&#xff08;Reflection&#xff09;是一种强大的机制&#xff0c;允许程序在运行时访问和操作类的内部属性和方法。通过反射&#xff0c;可以动态地创建对象、调用方法、改变属性值&#xff0c;这在很多Java框架中如Spring和Hiberna…...

现代密码学 | 椭圆曲线密码学—附py代码

Elliptic Curve Cryptography 椭圆曲线密码学&#xff08;ECC&#xff09;是一种基于有限域上椭圆曲线数学特性的公钥加密技术。其核心原理涉及椭圆曲线的代数性质、离散对数问题以及有限域上的运算。 椭圆曲线密码学是多种数字签名算法的基础&#xff0c;例如椭圆曲线数字签…...

3403. 从盒子中找出字典序最大的字符串 I

3403. 从盒子中找出字典序最大的字符串 I 题目链接&#xff1a;3403. 从盒子中找出字典序最大的字符串 I 代码如下&#xff1a; class Solution { public:string answerString(string word, int numFriends) {if (numFriends 1) {return word;}string res;for (int i 0;i &…...

laravel8+vue3.0+element-plus搭建方法

创建 laravel8 项目 composer create-project --prefer-dist laravel/laravel laravel8 8.* 安装 laravel/ui composer require laravel/ui 修改 package.json 文件 "devDependencies": {"vue/compiler-sfc": "^3.0.7","axios": …...

08. C#入门系列【类的基本概念】:开启编程世界的奇妙冒险

C#入门系列【类的基本概念】&#xff1a;开启编程世界的奇妙冒险 嘿&#xff0c;各位编程小白探险家&#xff01;欢迎来到 C# 的奇幻大陆&#xff01;今天咱们要深入探索这片大陆上至关重要的 “建筑”—— 类&#xff01;别害怕&#xff0c;跟着我&#xff0c;保准让你轻松搞…...