环境准备
服务器系统 |
Centos6.8 |
内存 |
1G |
CPU |
2核 |
IP地址 |
10.0.0.20 |
服务 |
MysqL |
服务器系统 |
Centos6.8 |
内存 |
1G |
CPU |
2核 |
IP地址 |
10.0.0.21 |
服务 |
Ansible管理主机 |
服务器系统 |
Centos6.8 |
内存 |
1G |
CPU |
2核 |
IP地址 |
10.0.0.22 |
服务 |
LAMP环境 |
服务器系统 |
Centos6.8 |
内存 |
1G |
CPU |
2核 |
IP地址 |
10.0.0.23 |
服务 |
LAMP环境 |
在21Ansible管理主机上操作,我们需要准备阿帕奇配置文件和wordpress源码包
创建目录
mkdir playbook
进入目录
cd playbook/
安装阿帕奇服务
yum -y install httpd
拷贝阿帕奇服务的配置文件至当前目录
cp /etc/httpd/conf/httpd.conf ./
编辑阿帕奇配置文件
vim httpd.conf
编辑yml文件
vim lamp.yml
---
- hosts: webservers
tasks:
- name: "安装Apache、php、unzip"
yum: name=httpd,php,php-mysql,unzip state=latest
- name: "推送配置文件"
copy: src=httpd.conf dest=/etc/httpd/conf/httpd.conf
- name: "关闭firewalld"
service: name=iptables state=stopped enabled=no
- name: "启动httpd"
service: name=httpd state=restarted
- name: "推送wordpress源码"
unarchive: src=wordpress-4.9.4-zh_CN.zip dest=/var/www/html mode=777
- hosts: db
tasks:
- name: "安装MYSQL"
yum: name=mysql,mysql-server state=latest
- name: "关闭firewalld"
service: name=iptables state=stopped enabled=no
- name: "启动MYSQL"
service: name=mysqld state=started enabled=yes
- name: "创建数据库wordpress"
shell: mysql -e "create database if not exists wordpress charset utf8;"
- name: "授权账号给wordpress"
shell: mysql -e "grant all on wordpress.* to 'tom'@'10.0.0.%' identified by '123';"
检查yml文件的语法是否正确
ansible-playbook --syntax-check lamp.yml
执行ansible 命令
ansible-playbook lamp.yml
好,开始Web端的操作,测试WordPress访问页面