怎样在ansible-playbook中批量搭建LAMP
发表于:2024-09-30 作者:千家信息网编辑
千家信息网最后更新 2024年09月30日,怎样在ansible-playbook中批量搭建LAMP?针对这个问题,今天小编总结了这篇文章,希望帮助更多想学习LAMP的同学找到更加简单易行的办法。先在ansible服务器安装LAMP环境,然后再
千家信息网最后更新 2024年09月30日怎样在ansible-playbook中批量搭建LAMP
怎样在ansible-playbook中批量搭建LAMP?针对这个问题,今天小编总结了这篇文章,希望帮助更多想学习LAMP的同学找到更加简单易行的办法。
先在ansible服务器安装LAMP环境,然后再将配置文件通过ansible拷贝到远程主机
1.安装httpd软件
yum -y install httpd
2.安装mysql
yum -y install mariadb-server mysqlsystemctl start mairadb
3.安装php 和php-mysql模块
yum -y install php php-mysql
4.提供php测试页
vim /var/www/html/index.phpsystemctl restart httpd
访问ip:80 查看是否出现测试页
创建对应的文件
mkdir -pv /etc/ansible/lamp/roles/{prepare,httpd,mysql,php}/{tasks,files,templates,vars,meta,default,handlers}
将搭建成功的LAMP环境的httpd和MySQL的配置文件拷贝到对应目录下
cd /etc/ansible/cp /etc/httpd/conf/httpd.conf lamp/roles/httpd/files/cp /etc/my.cnf lamp/roles/mysql/files/
写prepare角色的playbooks #前期准备
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 #关闭防火墙
构建httpd任务
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服务
部署mariadb数据库
创建MySQL服务任务,需要安装mysql服务,改变属主属性,启动mysql
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服务
构建php任务
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
执行playbook
ansible-playbook -i /etc/ansible/hosts ./site.yml
访问192.168.1.129 查看是否有测试页
看完上诉内容,你们掌握在ansible-playbook中批量搭建LAMP的方法了吗?如果想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
服务
文件
配置
任务
测试
拷贝
成功
内容
更多
环境
目录
易行
简单易行
主机
前期
办法
同学
名字
属性
插件
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
中国的数据库软件公司
提高网络安全防范意识课件
重庆邮电网络安全课程试卷
湖南菜先生网络技术有限公司
开源安全服务器
崂山区系统软件开发
复杂网络安全手抄报图片
acl网络安全技术
剑灵端游服务器人数
中信网络技术股份有限公司
服务器硬盘录像机配置
营业范围软件开发销售
自家电脑怎么变成服务器
pc读不出苹果硬盘的数据库
泉州软件开发待遇
pi数据库多大
网络安全法规定的游戏
肥乡区直销网络推广需要服务器吗
大厅效果图软件开发
网络安全视频幼儿儿歌
亿索网络技术有限公司
宜阳软件开发公司
海信软件开发岗位职责
db3 数据库
软件开发是不是要发展新的软件
中专网络技术以后从事
网络安全组织徽标
dell服务器盘槽是通用的么
我心中的网络安全论文1300字
大厅效果图软件开发