ansible-playbook roles编写lnmp剧本

目录

集中式编写lnmp剧本

执行

分布式编写lnmp剧本

一定要设置ssh免交互

 nginx

mysql

php

 执行


集中式编写lnmp剧本

vim /etc/ansible/lnmp.yml
- name: lnmp playhosts: dbserversremote_user: roottasks:- name: perpare condifurecopy: src=/etc/yum.repos.d/nginx.repo dest=/etc/yum.repos.d/nginx.repo- name: install nginxyum: name=nginx state=latest- name: start nginxservice: name=nginx state=started enabled=yes- name: install mysqlyum: name=mysql57-community-release-el7-10.noarch.rpm state=latest- name: modify filereplace:path: /etc/yum.repos.d/mysql-community.reporegexp: 'gpgcheck=1'replace: 'gpgcheck=0'- name: install mysql-community-serveryum: name=mysql-community-server state=latest- name: start mysqlservice: name=mysqld state=started enabled=yes- name: add yum filecommand: 'wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm -P /etc/yum.repos.d' - name: rpm epelcommand: 'rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm'- name: rpm el7command: 'rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm'- name: install phpcommand: 'yum install -y php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache'- name: start php-fpmservice: name=php-fpm state=started  enabled=yes- name: copy configurecopy: src=/usr/local/nginx/conf/nginx.conf dest=/etc/nginx/conf.d/default.conf- name: restart nginxservice: name=nginx state=started enabled=yes

执行

ansible-playbook lnmp.yml

分布式编写lnmp剧本

一定要设置ssh免交互

ssh-keygen -t rsa
sshpass -p’zxr123‘ ssh-copy-id  192.168.110.60 
mkdir /etc/ansible/roles/httpd/{files,templates,tasks,handlers,vars,defaults,meta} -p
mkdir /etc/ansible/roles/mysql/{files,templates,tasks,handlers,vars,defaults,meta} -p
mkdir /etc/ansible/roles/php/{files,templates,tasks,handlers,vars,defaults,meta} -ptouch /etc/ansible/roles/httpd/{defaults,vars,tasks,meta,handlers}/main.yml
touch /etc/ansible/roles/mysql/{defaults,vars,tasks,meta,handlers}/main.yml
touch /etc/ansible/roles/php/{defaults,vars,tasks,meta,handlers}/main.yml

 nginx

cd /etc/ansible/roles/nginx/filesindex.php  nginx.repo
 vim /etc/ansible/roles/nginx/files/index.php
<?php
phpinfo();
?>

 vim /etc//ansible/roles/nginx/files/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

 vim /etc/ansible/roles/nginx/main.yml
- include: "init.yml"- name: copy nginx repocopy: src=nginx.repo dest=/etc/yum.repos.d/
- name: install nginxyum: name=nginx state=latest
- name: copy index.phpcopy: src=index.php dest=/var/www/html
- name: transmit nginx configurationtemplate: src=default.conf.j2 dest=/etc/nginx/conf.d/default.conf
- name: start nginxservice: name=nginx state=started enabled=yes

vim /etc/ansible/roles/index.php
- name: stop firewalldservice: name=firewalld state=stopped enabled=no
- name: stop selinuxcommand: 'setenforce 0'

vim /etc/ansible/roles/nginx/template/default.conf.j2
server {listen       80;server_name  localhost;#access_log  /var/log/nginx/host.access.log  main;location / {root   /var/www/html;index  index.php index.html index.htm;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   /usr/share/nginx/html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {root           html;fastcgi_pass   192.168.110.60:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;include        fastcgi_params;}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}
}

mysql

vim /etc/ansible/roles/mysql/tasks/init.yml
- name: stop firewalldservice: name=firewalld state=stopped enabled=no
- name: stop selinuxcommand: 'setenforce 0'

vim /etc/ansible/roles/mysql/main.yml
- include: "init.yml"- name: remove mariadbshell: 'yum remove mariadb* -y'
- name: wgetshell: 'wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm -P /etc/yum.repos.d'
- name: install mysql57-community-release-el7-10.noarch.rpmyum: name=epel-release
- name: sedreplace: path=/etc/yum.repos.d/mysql-community.repo regexp="gpgcheck=1" replace="gpgcheck=0"
- name: install mysql-community-serveryum: name=mysql-community-server
- name: start mysqlservice: name=mysqld.service state=started
- name: passdshell: passd=$(grep "password" /var/log/mysqld.log | awk 'NR==1 {print $NF}')
- name: mysql 1shell: mysql -uroot -p'passd' --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'ZXRabc@123';"ignore_errors: true
- name: mysql 2shell: mysql -uroot -pZXRabc@123 -e "grant all privileges on *.* to root@'%' identified by 'ZXRabc@123' with grant option;"ignore_errors: true

php

vim /etc/ansible/roles/php/tasks/init.yml
- name: stop firewalldservice: name=firewalld state=stopped enabled=no
- name: stop selinuxcommand: 'setenforce 0'

vim /etc/ansible/rolesphp/tasks/main.yml
- include: "init.yml"- name: install yum reposhell: "rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm"ignore_errors: true
- name: install phpcommand: 'yum install -y php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache'
- name: add useruser:name: phpshell: /sbin/nologinsystem: yes
- name: copy php.inicopy: src=php.ini dest=/etc/php.ini
- name: copy www.confcopy: src=www.conf dest=/etc/php-fpm.d/www.conf
- name: copy index.phpcopy: src=index.php dest=/var/www/html
- name: start php-fpmservice: name=php-fpm state=started

 执行

vim /etc/ansible/lnmp.yml
- name: nginx playhosts: webserversremote_user: rootroles:- nginx- name: mysql playhosts: dbserversremote_user: rootroles:- mysql- name: php playhosts: phpserversremote_user: rootroles:- php

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

华为机考--服务失效判断--带答案

新2023年华为OD真题机考题库大全-带答案&#xff08;持续更新)or2023华为OD统一考试&#xff08;AB卷&#xff09;题库清单-带答案&#xff08;持续更新&#xff09; 题目描述 某系统中有众多服务&#xff0c;每个服务用字符串&#xff08;只包含字母和数字&#xff0c;长度<…

使用 NVM(Node Version Manager)管理 Node.js 版本

使用 NVM&#xff08;Node Version Manager&#xff09;管理 Node.js 版本 步骤一&#xff1a;安装 NVM NVM 是一个用于安装和管理不同版本的 Node.js 的工具。首先&#xff0c;你需要确保你的系统上已经安装了 NVM。可以通过以下命令检查 NVM 是否已经安装&#xff1a; nvm …

红队打靶:FourAndSix2.01打靶思路详解(vulnhub)

目录 写在开头 第一步&#xff1a;主机发现与端口扫描 第二步&#xff1a;NFS渗透 第三步&#xff1a;7z压缩包的密码破解 第四步&#xff1a;ssh私钥登录 第五步&#xff1a;lessvi提权 总结与思考 写在开头 本篇博客根据大佬红队笔记的视频进行打靶&#xff0c;详述了…

黑马头条---day1

手机端查看 docker 容器&#xff0c;镜像操作命令 1、docker删除所有镜像命令 删除所有镜像的命令是Docker中一个非常常见的操作。下面是具体的实现步骤和命令示例&#xff1a; $ docker stop $(docker ps -aq) 停止所有正在运行的容器。 $ docker rm $(docker ps -aq) 删…

selenium的java方式打开IE浏览器

1.下载软件Selenium Driver 官方下载地址&#xff1a; ​ https://www.selenium.dev/downloads/解压selenium-java-3.141.59.zip文件到java项目 seleniumDemo&#xff0c;并降解压的文件放入依赖中&#xff08;1&#xff09;双击项目的src打开项目结构&#xff0c;或右键-打开…

python将多张图片拼成一张矩阵图,合成一张大图

用Python实现将多张图片排列成n*m的图像矩阵图 目录 引言环境准备代码实现效果演示总结 引言 在图像处理和图像展示的应用中&#xff0c;将多张图片排列成一个图像矩阵图是一个常见的需求。本博客介绍如何使用Python实现将12张图片排列成n*m的图像矩阵图。 环境准备 为了实…

操作系统专栏2进程管理from 小林coding

进程管理 基本概念进程控制进程上下文切换 线程进程和线程的比较进程通信管道消息队列共享内存信号量信号socket 基本概念 进程:一个具有一定独立功能的程序关于某个数据集合的一次运行活动。它是操作系统动态执行的基本单元.并行和并发:状态: 其中挂起是指没有给程序分配实际…

ZZULIOJ 1187: 棒棒糖(结构体专题),Java

ZZULIOJ 1187: 棒棒糖&#xff08;结构体专题&#xff09;&#xff0c;Java 题目描述 新年快到了&#xff0c;计算机学院新年晚会正在筹备中&#xff0c;今年有一个新创意&#xff1a;来参加晚会的所有学生都有礼物&#xff08;一根棒棒糖&#xff09;。老师把买棒棒糖的任务…

学习中遇到的好博客

c日志工具之——log4cpp ECU唤醒的本质就是给ECU供电。 小文件&#xff1a;零拷贝技术 传输大文件&#xff1a;异步 IO 、直接 IO&#xff1a;如何高效实现文件传输&#xff1a;小文件采用零拷贝、大文件采用异步io直接io (123条消息) Linux网络编程 | 彻底搞懂…

机器学习01 -Hello World(对鸢尾花(Iris Flower)进行训练及测试)

什么是机器学习&#xff1f; 机器学习是一种人工智能&#xff08;AI&#xff09;的子领域&#xff0c;它探索和开发计算机系统&#xff0c;使其能够从数据中学习和改进&#xff0c;并在没有明确编程指令的情况下做出决策或完成任务。 传统的程序需要程序员明确编写指令来告诉…

QT 视图(view)模型(model)汇总

QStringListModel和QListView UI界面 widget头文件 #ifndef WIDGET_H #define WIDGET_H#include <QStringList> #include <QStringListModel> #include <QWidget>QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACEclass Widget : publi…

Leetcode | Kadane Algo | 53. 918.

53. Maximum Subarray 如果cur_sum大于零&#xff0c;可以晋级到下一个元素&#xff0c;因为正数只会让之后的和更大。如果cursum小于零&#xff0c;那就把他reset成0&#xff0c;让下一个元素从头开始。在此过程中一直记录global max 918. Maximum Sum Circular Subarray 两…

使用AOP切面对返回的数据进行脱敏的问题

1.注解类 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;/*** Author: xiaoxin* Date: 2023/7/21 17:15*/ Retention(RetentionPolicy.RUNTIME) Targe…

python文件处理方式

python文件处理方式 file open(D:\pythonText.txt, r, encodingUTF-8) print(file) # <_io.TextIOWrapper nameD:\\pythonText.txt moder encodingUTF-8> print(type(file)) # <class _io.TextIOWrapper>读取文件 file open(D:\pythonText.txt, r, encodingU…

语音播放 linux

调整语音音量大小 pactl list sinks pactl set-sink-volume 15 12345 # 15可以改成别的id安装pip install pyttsx3 sudo apt-get update sudo apt-get install espeak sudo ldconfig pip3 install pyttsx3代码 import pyttsx3 import threading def speak_work(text):engine…

Camera HAL/ISP 专业术语大全

不断更新&#xff0c;建议收藏&#xff0c;快速检索 SOC&#xff0c;System On Chip&#xff0c;片上系统 HAL&#xff0c;Hardware Abstraction Layer&#xff0c;硬件抽象层 ISP&#xff0c;Image Signal Processor&#xff0c;图像信号处理器 KMD&#xff0c;Kernel Mod…

janus的web端开发

janus Web 1. 在线demo 通过janus的源码的html文件以及相应的js文件我们可以参考官方的demo&#xff0c;在上文服务端的部署中最后我们可以进行在线使用。 2. 模块开发 只有demo肯定是不够的&#xff0c;而且使用的是jquery和bootStrap&#xff0c;改起来也特别麻烦。 因此我…

3d软件动物生活习性仿真互动教学有哪些优势

软体动物是一类广泛存在于海洋和淡水环境中的生物&#xff0c;其独特的形态和生活习性给学生带来了新奇和有趣的学习主题&#xff0c;为了方便相关专业学科日常授课教学&#xff0c;web3d开发公司深圳华锐视点基于真实的软体动物&#xff0c;制作软体动物3D虚拟展示系统&#x…

CMake 学习笔记 (Generator Expressions)

CMake 学习笔记 &#xff08;Generator Expressions&#xff09; Generator Expressions 可以认为是一种特殊的变量&#xff0c;它会在编译阶段求值。通常用在 target_link_libraries(), target_include_directories(), target_compile_definitions() 上。 用 Generator Expr…

【visual studio2019】如何打开即时窗口

在 Visual Studio2019 中打开即时窗口&#xff0c;有两种方法&#xff1a; 1、可以通过“调试”菜单&#xff0c;然后选择“窗口”下的“即时窗口”选项 2、直接使用快捷键“Ctrl Alt I” 此时即时窗口将显示在 Visual Studio2019 的底部。在即时窗口中&#xff0c;可以执…