Ansible部署LAMP架构

本文档详细介绍了如何使用Ansible自动化部署LAMP(Linux, Apache, MySQL, PHP)架构。从配置主控机和受控主机开始,包括安装httpd服务、MySQL数据库、PHP,到配置apache和php,最后进行访问测试,确保环境正常运行。" 117341213,7662313,Django+Celery+Websocket:构建聊天机器人实践,"['Django', 'WebSocket', 'Celery', 'Python爬虫', '实时通讯']
摘要由CSDN通过智能技术生成

1.配置主控机和受控主机

环境说明:

主机名 作用 IP
ansible Ansible控制主机 192.168.237.167
apache 受控主机1(apache) 192.168.237.168
mysql 受控主机2(MySQL) 192.168.237.169
php 受控主机3(PHP) 192.168.237.170

在主控机上将node1、node2、node3加入清单文件:

[root@master ansible]# cat inventory 
[apache]
192.168.237.168

[mysql]
192.168.237.169

[php]
192.168.237.170

配置免密登录:

[root@localhost ansible]# ssh-keygen
[root@localhost ansible]# ssh-copy-id root@192.168.237.168
[root@localhost ansible]# ssh-copy-id root@192.168.237.169
[root@localhost ansible]# ssh-copy-id root@192.168.237.170

测试,用ping模块看主控机与受控主机能否ping通:

[root@master ansible]# ansible all -m ping
192.168.237.168 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
192.168.237.169 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
192.168.237.170 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

为所有受控主机关闭防火墙和selinux

[root@localhost ansible]# ansible all -m service -a 'name=firewalld state=stopped enabled=no'
[root@localhost ansible]# ansible all -m lineinfile -a 'path=/etc/selinux/config regexp="SELINUX=enforcing" line="SELINUX=disabled"'
[root@localhost ansible]# ansible all -m shell -a 'setenforce 0'

2.安装httpd服务

在主控机上通过ansible在apache上安装apache服务:

[root@ansible ansible]# ansible apac
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值