ansible安装lnmp(集中式)

一、安装nginx

- name: the nginx play
  hosts: webservers
  remote_user: root
  tasks:
  - name: stop firewalld                 #关闭防火墙
    service: name=firewalld state=stopped enabled=no
  - name: selinux stop
    command: '/usr/sbin/setenforce 0'
  - name: mount dev                      #挂载光盘
    mount: src=/dev/sr0 path=/mnt state=mounted fstype=iso9660
    ignore_errors: true
  - name: copy nginx.repo                #nginx源
    copy: src=/etc/yum.repos.d/nginx.repo dest=/etc/yum.repos.d
  - name: install nginx
    yum: name=nginx state=latest
    ignore_errors: true
  - name: restart nginx
    service: name=nginx state=started enabled=yes
    ignore_errors: true
vim /etc/yum.repos.d
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

在这里插入图片描述

在这里插入图片描述

二、安装mysql

- name: the mysql play#
  hosts: webservers
  remote_user: root
  tasks:
  - name: copy mysql file
    copy: src=/etc/yum.repos.d/mysql57-community-release-el7-11.noarch.rpm dest=/etc/yum.repos.d/
  - name: yum mysql
    shell: 'cd /etc/yum.repos.d&&rpm -ivh mysql57-community-release-el7-11.noarch.rpm'
    ignore_errors: true
  - name: replace
    replace: path=/etc/yum.repos.d/mysql-community.repo regexp="gpgcheck=1" replace="gpgcheck=0"
  - name: yum mysql-server
    yum: name=mysql-server state=installed
    ignore_errors: true
  - name: start mysql
    service: name=mysqld.service state=restarted enabled=yes
  - name: mysql.sh
    script: /opt/mysql.sh
    ignore_errors: true
vim /opt/mysql.sh
passd=$(grep "A temporary password is generated for root@localhost:" /var/log/mysqld.log | awk '{print $NF}')
mysql -uroot -p"$passd" --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123';"
mysql -uroot -pAdmin@123 -e "grant all privileges on *.* to root@'%' identified by 'Admin@123' with grant option;"

在这里插入图片描述

在这里插入图片描述

三、安装php

- name: the php play
  gather_facts: false
  hosts: webservers
  remote_user: root
  tasks:
  - name: copy php
    copy: src=/etc/yum.repos.d/epel.repo dest=/etc/yum.repos.d/
  - name: copy php1
    copy: src=/etc/yum.repos.d/epel-testing.repo dest=/etc/yum.repos.d/
  - name: copy php2
    copy: src=/etc/yum.repos.d/webtatic-archive.repo dest=/etc/yum.repos.d/
  - name: copy php3
    copy: src=/etc/yum.repos.d/webtatic.repo dest=/etc/yum.repos.d/
  - name: copy php4
    copy: src=/etc/yum.repos.d/webtatic-testing.repo dest=/etc/yum.repos.d/
  - name: yum php
    shell: yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache
    ignore_errors: true
  - name: start php
    service: name=php-fpm state=started
  - name: copy nginx.conf
    copy: src=/etc/nginx/conf.d/default.conf dest=/etc/nginx/conf.d/
  - name: start nginx
    service: name=nginx state=restarted
  - name: copy index.php
    copy: src=/usr/share/nginx/html/index.php dest=/usr/share/nginx/html/

在这里插入图片描述

测试:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值