标签:ali web 插件 director 防火墙 出现 sdn ext mairadb
先在ansible服务器安装LAMP环境,然后再将配置文件通过ansible拷贝到远程主机yum -y install httpd
yum -y install mariadb-server mysql
systemctl start mairadb
yum -y install php php-mysql
vim /var/www/html/index.php
<?php
phpinfo();
?>
systemctl restart httpd
mkdir -pv /etc/ansible/lamp/roles/{prepare,httpd,mysql,php}/{tasks,files,templates,vars,meta,default,handlers}
cd /etc/ansible/
cp /etc/httpd/conf/httpd.conf lamp/roles/httpd/files/
cp /etc/my.cnf lamp/roles/mysql/files/
vim lamp/roles/prepare/tasks/main.yml
- name: provide yumrepo file
shell: rm -rf /etc/yum.repos.d/*.repo #删除原有yum配置文件
shell: wget - o /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-repo #下载新的yum配置文件
- name: clean the yum repo
shell: yum clean all
- name: clean the iptables
shell: systemctl stop firewalld #关闭防火墙
cp /var/www/html/index.php lamp/roles/httpd/files/
vim lamp/roles/httpd/tasks/main.yml
- name: web server install
yum: name=httpd state=present #安装httpd服务
- name: provide test page
copy: src=index.php dest=/var/www/html #提供测试页
notify: restart httpd #当前面的copy执行成功后,通过notify通知名字为restart httpd的handlers运行
- name: restart httpd
service: name=httpd enabled=yes state=restarted #重启httpd服务
vim lamp/roles/mysql/tasks/main.yml
- name: install the mysql
yum: name=mariadb-server state=present #安装mysql服务
- name: mkdir date directory
shell: mkdir -p /mydata/data #创建挂载点目录
- name: provide configration file
copy: src=my.cnf dest=/etc/my.cnf #拷贝mysql的配置文件
- name: chage the owner
shell: chown -R mysql:mysql /mydata/* #更改属主和属主
- name: start mariadb
service: name=mariadb enabled=yes state=started #启动mysql服务
vim lamp/roles/php/tasks/main.yml
- name: install php
yum: name=php state=present #安装php
- name: install php-mysql
yum: name=php-mysql state=present #安装php与mysql交互插件
vim lamp/roles/site.yml
- name: LAMP build
remote_user: root
hosts: all
roles:
- prepare
- mysql
- php
- httpd
ansible-playbook -i /etc/ansible/hosts ./site.yml
标签:ali web 插件 director 防火墙 出现 sdn ext mairadb
原文地址:https://blog.51cto.com/14486455/2453755