怎样在ansible-playbook中批量搭建LAMP?针对这个问题,今天小编总结了这篇文章,希望帮助更多想学习LAMP的同学找到更加简单易行的办法。
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、网站建设、西乡塘网络推广、成都微信小程序、西乡塘网络营销、西乡塘企业策划、西乡塘品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供西乡塘建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com
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
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
看完上诉内容,你们掌握在ansible-playbook中批量搭建LAMP的方法了吗?如果想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!