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

ansible-playbook roles模块编写lnmp剧本

目录

一:集中式编写lnmp剧本

二:分布式安装lnmp

1、nginx 配置

  2、mysql配置

 3、php配置

 4、运行剧本


一:集中式编写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=yesansible-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} -ptouch /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.ymlcd /etc/ansible/roles/nginx/filesindex.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=1vim /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=yesvim /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.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 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 'admin@123';"ignore_errors: true
- name: mysql 2shell: 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 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

 4、运行剧本

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.lryc.cn/news/103463.html

相关文章:

  • 什么是汽车软件的模糊测试?
  • Datax使用
  • HTML不常用但是好用的标签
  • 蓝桥杯2018省赛全球变暖dfs
  • Bean的作用域 - spring
  • [ncnn]ncnnoptimize使用
  • Elasticsearch笔记
  • 《怎样顺利通过答辩:论文答辩的策略与技巧》
  • uniapp 微信小程序:页面+组件的生命周期顺序
  • Linux CentOS 8 编译安装Apache Subversion
  • 谈一谈缓存穿透,击穿,雪崩
  • 如何对反编译的安卓应用进行调试并修改
  • C#实现数据库数据变化监测(sqlservermysql)
  • MFC第二十三天 HBrush对闭合图形的填充、CPen、CFont类常用功能与LOGFONT和LOGPEN结构体
  • 深入学习 Redis - 渐进式遍历 scan 命令、数据库管理命令
  • python+opencv实现显示摄像头,截取相关图片,录取相关视频
  • 第十章:重新审视扩张卷积:一种用于弱监督和半监督语义分割的简单方法
  • 指令收集:DOCKER+K8S
  • Minecraft 1.20.x Forge模组开发 05.矿石生成
  • 运维面试大全
  • 【线程安全的讨论(一)】CPU多核缓存架构和JMM
  • 以太网交换机的生成树协议STP
  • 手机照片转换成pdf怎么做?了解这几种方法就可以了
  • 跨境电商还有人在做吗,这十大选品技巧建议收藏!
  • HTML快速学习
  • centos7搭建k8s环境并部署springboot项目
  • nuitka打包软件程序
  • 12-3_Qt 5.9 C++开发指南_创建和使用静态链接库
  • conda模式安装paddlepaddle2.4.2版本
  • 英语疑问句