Define the installation and configuration of the lamp Platform Based on Roles

Source: Internet
Author: User

写在前面:如果此文有幸被某位朋友看见并发现有错的地方,希望批评指正。如有不明白的地方,愿可一起探讨。


实验拓扑图

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4B/D6/wKioL1Q0qcODFblZAAFoPie__64182.jpg" title="图1" alt="wKioL1Q0qcODFblZAAFoPie__64182.jpg" />


安装ansible

# yum -y install ansible

修改/etc/ansible/hosts配置文件

# vim /etc/ansible/hosts
[hbhosts]172.16.115.101172.16.115.102172.16.115.103

由于ansible通过ssh实现配置管理、应用部署、任务执行等功能,因此需要先配置ansible端能基于秘钥认证的方式联系各个被管理的主机

# ssh-keygen -t rsa -P ‘‘# ansible hbhosts --module-name=copy --args=‘src=/root/.ssh/id_rsa.pub   dest=/root/.ssh/authorized_keys owner=root group=root mode=600‘ --ask-pass

创建以roles命名的目录

# mkdir -pv /root/lamp/roles

正式安装LAMP平台前,需要做一些初始化的工作,在roles目录下创建comman目录来存放初始化所需要的文件和任务

# cd /root/lamp/roles# mkdir -pv common/{files,tasks}

提供测试页面文件

# vim common/files/index.php
<?php    $link = mysql_connect(‘127.0.0.1‘,‘root‘,‘‘);    if ($link)        echo "Success...";    else        echo "Failure...";    mysql_close();        phpinfo();?>

提供时间同步任务和复制测试文件

# vim common/tasks/main.yaml
- name: sync time  cron: name="sync time" minute="*/3" job="/usr/sbin/ntpdate 172.16.0.1 &> /dev/null"- name: page file  copy: src=index.php dest=/var/www/html

安装lamp平台需要安装http、php、mysql-server、php-mysql,因此需要提供安装这些程序的任务

# mkdir -pv lamp/{files,tasks}

提供安装lamp平台任务和启动lamp平台任务

# vim lamp/tasks/maim.yml
- name: install lamp platform  yum: name={{ item }} state=present  with_items:    - httpd    - php    - mysql-server    - php-mysql  tags: inst- name: start lamp  service: name={{ item }} state=started enabled=no  with_items:    - httpd    - mysqld  tags: start

提供用于ansible-playbook的文件

# cd /root/lamp# vim lamp.yml
- name: install and config lamp  remote_user: root  hosts: hbhosts  roles:  - common  - lamp

安装整个lamp平台

# ansible-playbook lamp.yml

测试是否安装成功

在浏览器中分别键入172.16.115.101、172.16.115.102、172.16.115.103,都可以得到如下结果

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4B/D8/wKioL1Q0uIqRndknAADBHNkYpOM903.jpg" title="图2" alt="wKioL1Q0uIqRndknAADBHNkYpOM903.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4B/D9/wKioL1Q0uM3gW7KUAADJ6_sMIYg656.jpg" title="图3" alt="wKioL1Q0uM3gW7KUAADJ6_sMIYg656.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4B/D7/wKiom1Q0uMrCd0QvAADFBE4RHYk691.jpg" title="图4" alt="wKiom1Q0uMrCd0QvAADFBE4RHYk691.jpg" />


基于roles的方式定义安装配置LAMP平台

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.