ansible角色部署lamp架构

linux ansible角色部署lamp架构

ansible主机创建角色

[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# ls
ansible.cfg  hosts  roles
[root@ansible ansible]# vim hosts 
node1
[root@ansible ansible]# cd roles/
[root@ansible roles]# ansible-galaxy init apache
- Role apache was created successfully
[root@ansible roles]# ansible-galaxy init mysql
- Role mysql was created successfully
[root@ansible roles]# ansible-galaxy init php
- Role php was created successfully

ansible主机配置apache角色

[root@ansible roles]# cd apache/
[root@ansible apache]# ls
defaults  files  handlers  meta  README.md  tasks  templates  tests  vars
[root@ansible apache]# vim tasks/main.yml 
---
# tasks file for apache
- name: stop firewalld
  service: 
    name: firewalld
    state: stopped
    enabled: no
 
- name: stop selinux
  lineinfile: 
    path: /etc/selinux/config
    regexp: '^SELINUX='
    line: SELINUX=disabled

- name: stop selinux1
  shell: 
    cmd: setenforce 0

- name: set yum
  script: yum.sh

- name: install pkgs
  yum: 
    name: "{
  { pkgs }}"
    state: present
 
- name: unzip1
  unarchive: 
    src: apr-1.7.0.tar.gz
    dest: /opt/

- name: unzip2
  unarchive:
    src: apr-util-1.6.1.tar.gz
    dest: /opt/

- name: unzip3
  unarchive:
    src: httpd-2.4.54.tar.gz
    dest: /opt/

- name: create apache
  user: 
    name: apache
    system: yes
    shell: /sbin/nologin
    create_home: no
    state: present

- name: apache.sh
  script: apache.sh

- name: httpd.sh
  script: httpd.sh

- name: cp config
  template: 
    src: httpd.service.j2
    dest: /usr/lib/systemd/system/httpd.service

- name: apply config
  shell: 
    cmd: systemctl daemon-reload

- name: restart httpd
  service: 
    name: httpd
    state: started
    enabled: yes

编写yum库脚本

[root@ansible apache]# vim files/yum.sh
#!/bin/bash
rm -rf /etc/yum.repos.d/*
/usr/bin/curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
/usr/bin/sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
/usr/bin/sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

编写工具包剧本

[root@ansible apache]# vim vars/main.yml 
---
# vars file for apache
pkgs: 
  - bzip2 
  - vim
  - make
  - wget
  - openssl-devel
  - pcre-devel
  - expat-devel
  - libtool
  - gcc
  - gcc-c++
  - libxml2-devel

传输已下载的数据包

[root@ansible apache]# cd files/
[root@ansible files]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz  yum.sh

编写编译安装脚本

[root@ansible apache]# vim files/apache.sh
#!/bin/bash
#编译安装apr
cd /opt/apr-1.7.0
sed -i '/$RM "$cfgfile"/d' configure
./configure --prefix=/usr/local/apr
make
make install

#编译安装apr-util
cd /opt/apr-util
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值