您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
怎样在ansible-playbook中批量搭建LAMP?针对这个问题,今天小编总结了这篇文章,希望帮助更多想学习LAMP的同学找到更加简单易行的办法。
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
看完上诉内容,你们掌握在ansible-playbook中批量搭建LAMP的方法了吗?如果想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。