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

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
ansible-playbook lnmp.yml

http://www.lryc.cn/news/105926.html

相关文章:

  • 相机可用性变化监听AvailabilityCallback流程分析
  • 使用Python多线程实现生产者消费者模型
  • Notepad++工具通过正则表达式批量替换内容
  • 从零构建深度学习推理框架-3 手写算子relu
  • 想做上位机,学C#还是QT?
  • Ansible —— playbook 剧本
  • ARM寻址方式
  • 【JAVA】String ,StringBuffer 和 StringBuilder 三者有何联系?
  • 关于计数以及Index返回订单号升级版(控制字符长度,控制年月标记)
  • 【计算机网络】11、网桥(bridge)、集线器(hub)、交换机(switch)、路由器(router)、网关(gateway)
  • 第九篇-自我任务数据准备
  • 2023.8.1号论文阅读
  • webpack优化前端框架性能
  • Unity UGUI的Outline(描边)组件的介绍及使用
  • 爆改vue3 setup naiveui可编辑table
  • 功率放大器的种类有哪三种类型
  • HDFS 分布式存储 spark storm HBase
  • Vue3文字实现左右和上下滚动
  • Docker Sybase修改中文编码
  • 【SpringCloud Alibaba】(六)使用 Sentinel 实现服务限流与容错
  • mysql的主从复制
  • 【Golang 接口自动化03】 解析接口返回XML
  • Java+bcprov库实现对称和非对称加密算法
  • 国内最大Llama开源社区发布首个预训练中文版Llama2
  • Qt应用开发(基础篇)——滑块类 QSlider、QScrollBar、QDial
  • 【3-D深度学习:肺肿瘤分割】创建和训练 V-Net 神经网络,并从 3D 医学图像中对肺肿瘤进行语义分割研究(Matlab代码实现)
  • MongoDB文档--架构体系
  • GEE学习03-Geemap配置与安装,arcgis pro自带命令提示符位置等
  • 软件测试面试总结——http协议相关面试题
  • 大数据与okcc呼叫中心融合的几种方式