ansible-playbook roles模块编写lnmp剧本

目录

一:集中式编写lnmp剧本

二:分布式安装lnmp

1、nginx 配置

  2、mysql配置

 3、php配置

 4、运行剧本


一:集中式编写lnmp剧本

vim /etc/ansible/lnmp.yml

- name: lnmp play
  hosts: dbservers
  remote_user: root
 
  tasks:
  - name: perpare condifure
    copy: src=/etc/yum.repos.d/nginx.repo dest=/etc/yum.repos.d/nginx.repo
  - name: install nginx
    yum: name=nginx state=latest
  - name: start nginx
    service: name=nginx state=started enabled=yes
    
  - name: install mysql
    yum: name=mysql57-community-release-el7-10.noarch.rpm state=latest
  - name: modify file
    replace:
      path: /etc/yum.repos.d/mysql-community.repo
      regexp: 'gpgcheck=1'
      replace: 'gpgcheck=0'
  - name: install mysql-community-server
    yum: name=mysql-community-server state=latest
  - name: start mysql
    service: name=mysqld state=started enabled=yes
 
  - name: add yum file
    command: 'wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm -P /etc/yum.repos.d' - name: rpm epel
    command: 'rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm'
  - name: rpm el7
    command: 'rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm'
  - name: install php
    command: '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-fpm
    service: name=php-fpm state=started  enabled=yes
  - name: copy configure
    copy: src=/usr/local/nginx/conf/nginx.conf dest=/etc/nginx/conf.d/default.conf
  - name: restart nginx
    service: name=nginx state=started enabled=yes

ansible-playbook lnmp.yml  运行

 

二:分布式安装lnmp

1、nginx 配置

#创建各个服务的节点
vim /etc/ansible/hosts

[webservers]
192.168.231.102

[dbservers]
192.168.231.103

[phpservers]
192.168.231.110

#免交互
ssh-keygen -t rsa
sshpass -p '123456' ssh-copy-id  192.168.231.102 

#创建文件
mkdir /etc/ansible/roles/nginx/{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} -p
 
touch /etc/ansible/roles/nginx/{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

cd /etc/ansible/roles/nginx/files
 index.php  nginx.repo
#编写php测试文件
 vim /etc/ansible/roles/nginx/files/index.php
<?php
phpinfo();
?>

#编辑nginx配置源
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 repo
  copy: src=nginx.repo dest=/etc/yum.repos.d/
- name: install nginx
  yum: name=nginx state=latest
- name: copy index.php
  copy: src=index.php dest=/var/www/html
- name: transmit nginx configuration
  template: src=default.conf.j2 dest=/etc/nginx/conf.d/default.conf
- name: start nginx
  service: name=nginx state=started enabled=yes

vim /etc/ansible/roles/index.php
- name: stop firewalld
  service: name=firewalld state=stopped enabled=no
- name: stop selinux
  command: '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.321.110: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;
    #}
}
 

  2、mysql配置

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

vim /etc/ansible/roles/mysql/main.yml
- include: "init.yml"
 
- name: remove mariadb
  shell: 'yum remove mariadb* -y'
- name: wget
  shell: '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.rpm
  yum: name=epel-release
- name: sed
  replace: path=/etc/yum.repos.d/mysql-community.repo regexp="gpgcheck=1" replace="gpgcheck=0"
- name: install mysql-community-server
  yum: name=mysql-community-server
- name: start mysql
  service: name=mysqld.service state=started
- name: passd
  shell: passd=$(grep "password" /var/log/mysqld.log | awk 'NR==1 {print $NF}')
- name: mysql 1
  shell: mysql -uroot -p'passd' --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'admin@123';"
  ignore_errors: true
- name: mysql 2
  shell: mysql -uroot -padminabc@123 -e "grant all privileges on *.* to root@'%' identified by 'admin@123' with grant option;"
  ignore_errors: true

 3、php配置

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


vim /etc/ansible/rolesphp/tasks/main.yml
- include: "init.yml"
 
- name: install yum repo
  shell: "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 php
  command: '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 user
  user:
    name: php
    shell: /sbin/nologin
    system: yes
- name: copy php.ini
  copy: src=php.ini dest=/etc/php.ini
- name: copy www.conf
  copy: src=www.conf dest=/etc/php-fpm.d/www.conf
- name: copy index.php
  copy: src=index.php dest=/var/www/html
- name: start php-fpm
  service: name=php-fpm state=started

 4、运行剧本

vim /etc/ansible/lnmp.yml
- name: nginx play
  hosts: webservers
  remote_user: root
  roles:
    - nginx
- name: mysql play
  hosts: dbservers
  remote_user: root
  roles:
    - mysql
 
- name: php play
  hosts: phpservers
  remote_user: root
  roles:
    - php

 

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

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

相关文章

谷歌云 | 电子商务 | 如何更好地管理客户身份以支持最佳的用户体验

【本文由Cloud Ace整理发布。Cloud Ace是谷歌云全球战略合作伙伴&#xff0c;拥有 300 多名工程师&#xff0c;也是谷歌最高级别合作伙伴&#xff0c;多次获得 Google Cloud 合作伙伴奖。作为谷歌托管服务商&#xff0c;我们提供谷歌云、谷歌地图、谷歌办公套件、谷歌云认证培训…

嵌入式开发学习(STC51-10-直流电机)

内容 直流电机工作约5S后停止 直流电机简介 直流电机是指能将直流电能转换成机械能&#xff08;直流电动机&#xff09;或将机械能转换成直流电能&#xff08;直流发电机&#xff09;的旋转电机&#xff1b; 直流电机的结构应由定子和转子两大部分组成&#xff1b; 直流电…

k8s概念-pv和pvc

回到目录 kubernetes存储卷的分类太丰富了,每种类型都要写相应的接口与参数才行&#xff0c;这就让维护与管理难度加大。 persistenvolume(PV) 是配置好的一段存储(可以是任意类型的存储卷) 也就是说将网络存储共享出来,配置定义成PV。 PersistentVolumeClaim(PVC)是用户pod使…

麦肯锡战略思维四大原则

麦肯锡战略思维四大原则 曾任职麦肯锡、安永等国家国际知名咨询机构的周正元&#xff0c;在其著作《麦肯锡结构化战略思维》将其系统的整理呈现出来&#xff0c;便于学习和使用。 模型介绍 工作中的你&#xff0c;是不是经常遇到复杂问题&#xff0c;六神无主&#xff1f; 专业…

【树形DP+换根思想】2022牛客多校加赛 H

登录—专业IT笔试面试备考平台_牛客网 题意&#xff1a; 思路&#xff1a; 这个虽然是树形DP&#xff0c;却用了换根的思想.... 首先&#xff0c;后缀0的个数可以转化成min(cnt2,cnt5)&#xff0c;其中cnt2为2的因子个数&#xff0c;cnt5为5的因子个数 然后进行DP 设dp[u]…

openGauss学习笔记-31 openGauss 高级数据管理-索引

文章目录 openGauss学习笔记-31 openGauss 高级数据管理-索引31.1 语法格式31.2 参数说明31.3 示例 openGauss学习笔记-31 openGauss 高级数据管理-索引 索引是一个指向表中数据的指针。一个数据库中的索引与一本书的索引目录是非常相似的。 索引可以用来提高数据库查询性能&…

解决:树莓派VNC连接屏幕显示不全

目录 前导&#xff1a;我在重新烧录玩树莓派系统&#xff0c;开启完VNC并连接后&#xff0c;发现我的树莓派远程桌面屏幕显示不全&#xff0c;看着很难受&#xff01; PS&#xff1a;开启VNC服务的过程 问题如下现象&#xff1a; 问题分析&#xff1a;当树莓派通过VNC连接时&…

ThreadLocal原理

ThreadLocal原理 ThreadLocal对象new出来存放到堆中&#xff0c;ThreadLocal引用是存放在栈里 Thread 类有个 ThreadLocalMap 成员变量&#xff0c;Map的key是Threadlocal 对象&#xff0c;value是你要存放的线程局部变量。 public void set(T value) {//获取当前线程Thread&…

springboot+vue农业技术信息管理系统_9927h

随着信息时代的发展&#xff0c;计算机迅速普及&#xff0c;传统的农业信息管理方式显得不够快捷&#xff0c;这时我们就需要创造更加便利的管理方法&#xff0c;对农业信息进行统计&#xff0c;便于统一管理。将传统管理方式转变为信息、智能化显得尤为重要&#xff0c;农业信…

web开发中的安全和防御入门——csp (content-security-policy内容安全策略)

偶然碰到iframe跨域加载被拒绝的问题&#xff0c;原因是父页面默认不允许加载跨域的子页面&#xff0c;也就是的content-security-policy中没有设置允许跨域加载。 简单地说&#xff0c;content-security-policy能限制页面允许和不允许加载的所有资源&#xff0c;常见的包括&a…

【万字长文】SpringBoot整合Atomikos实现多数据源分布式事务(提供Gitee源码)

前言&#xff1a;在最近的实际开发的过程中&#xff0c;遇到了在多数据源的情况下要保证原子性的问题&#xff0c;这个问题当时遇到了也是思考了一段时间&#xff0c;后来通过搜集大量资料与学习&#xff0c;最后是采用了分布式事务来解决这个问题&#xff0c;在讲解之前&#…

睿讯微带你深度了解汽车交流充电桩

这几年随着新能源汽车的普及&#xff0c;充电桩也越来越多的出现在我们的视野中。新能源纯电汽车就好比一种大号的电子产品&#xff0c;而充电桩则是它不可缺少的子系统&#xff0c;是新能源车主们的必要选择。 汽车充电桩分为直流和交流两种&#xff0c;2022年底全国公共充电桩…

Java课题笔记~ Spring 概述

Spring 框架 一、Spring 概述 1、Spring 框架是什么 Spring 是于 2003 年兴起的一个轻量级的 Java 开发框架&#xff0c;它是为了解决企业应用开发的复杂性而创建的。Spring 的核心是控制反转&#xff08;IoC&#xff09;和面向切面编程&#xff08;AOP&#xff09;。 Spring…

创建vue-cli(脚手架搭建)

目录 功能 需要的环境 使用HbuilderX快速搭建一个vue-cli项目 组件路由 element-ui vue-cli 官方提供的一个脚手架&#xff0c;用于快速生成一个 vue 的项目模板&#xff1b;预先定义 好的目录结构及基础代码&#xff0c;就好比咱们在创建 Maven 项目时可以选择创建一个 骨…

VR内容研发公司 | VR流感病毒实验虚拟现实课件

由广州华锐互动开发的《VR流感病毒实验虚拟现实课件》是一种新型的教学模式&#xff0c;可以为学生提供更加真实和直观的流感病毒分离鉴定实验操作体验&#xff0c;从而提高学生的实验技能和工作效率。 《VR流感病毒实验虚拟现实课件》涉及了生物安全二级实验室(BSL-2)和流感病…

分布式应用:Zookeeper 集群与kafka 集群部署

目录 一、理论 1.Zookeeper 2.部署 Zookeeper 集群 3.消息队列 4.Kafka 5.部署 kafka 集群 6.FilebeatKafkaELK 二、实验 1.Zookeeper 集群部署 2.kafka集群部署 3.FilebeatKafkaELK 三、问题 1.解压文件异常 2.kafka集群建立失败 3.启动 filebeat报错 4.VIM报错…

基于DiscordMidjourney API接口实现文生图

https://discord.com/api/v9/interactions 请求头&#xff1a; authorization:取自 浏览器中discord 文生图请求头中的 authorization 的值 Content-Type:application/json 请求体&#xff1a; {“type”:2,“application_id”:“93692956130267xxxx”,“guild_id”:“1135900…

python-MySQL数据库建表语句(需要连接数据库)转存为Excel文档-工作小记

将create table XXXXXX 转为指定Excel文档。该脚本适用于数据库表结构本地文档记录 呈现效果 代码 # -*- coding:utf-8 -*- # Time : 2023/8/2 15:14 # Author: 水兵没月 # File : MySQL建表_2_excel.py import reimport mysql.connector import pandas as pd db 库名 mydb …

TS协议之PMT(节目映射表)

TS协议之PAT&#xff08;节目关联表&#xff09; 1.概要 PMT&#xff1a;节目映射表&#xff0c;与PAT成对出现&#xff0c;包含了该节目下所有的节目元素。 PMT数据结构如下&#xff1a; 字段分析&#xff1a; 字段字段描述表id标识一个TS PSI分段的内容是节目关联分段&am…

性能分析记录

4实例压测TPS浮动在200-300 1.TPS浮动200-300&#xff0c;ART浮动的可能性是10-20ms&#xff0c;链路复杂是可接受的&#xff0c;链路简单则需要分析原因。 1&#xff09;缓存没命中&#xff0c;对某些账号缓存没命中&#xff0c;或缓存失效后导致隔段时间耗时升高。 2&…
最新文章