Ansible用变量编译安装httpd服务

本文档详细介绍了如何使用Ansible自动化编译安装Apache HTTPD服务的过程,包括下载源码包、安装依赖、解压、配置、安装及启动服务,并解决了启动时的域名问题,最后进行了浏览器访问测试,确保服务正常运行。
摘要由CSDN通过智能技术生成

Ansible用变量编译安装httpd服务

1.包下载

1.首先我们要在百度上去复制地址,下载httpd服务相应的包

httpd地址:https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/

apr地址:https://mirrors.tuna.tsinghua.edu.cn/apache/apr/

[root@node1 ansible]# ls
ansible.cfg       apr-util-1.6.1.tar.gz  hosts                index.html   long  shen
apr-1.7.0.tar.gz  fei                    httpd-2.4.48.tar.gz  install.yml  node
[root@node1 ansible]# 

我们下载用wget下载。如果没有装的我们先用yum安装wget,然后在复制百度上的地址。

[root@node1 ansible]# yum install -y wget    //我们这里已经按安装
Repository extras is listed more than once in the configuration
上次元数据过期检查:0:19:21 前,执行于 2021年07月21日 星期三 15时06分10秒。
软件包 wget-1.19.5-10.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@node1 ansible]# 

2.包装安装httpd相应的模块

创建这个yml文件,然后编写这个文件,代码如下:

[root@node1 node]# cat httpd.yml 
packages: 
  - openssl-devel
  - pcre
  - perl-devel
  - perl
  - pcre-devel
  - expat-devel
  - libtool
  - gcc
  - gcc-c++
  - make
  - '@development tools'
[root@node1 node]# 

然后我们写playbook,创建一个执行文件,代码如下:

[root@node1 ansible]# cat install.yml 
---
- hosts: apache
  vars_files:
    - node/httpd.yml
  tasks:
    - name: install base packages
      yum:
        name: '{{item}}'
        state: present
      loop: '{{packages}}'

    - name: uncompress apr
      unarchive:
        src: /etc/ansible/apr-1.7.0.tar.gz
        dest: /opt/

    - name: uncompress apr-util
      unarchive:
        src: /etc/ansible/apr-util-1.6.1.tar.gz
        dest: /opt/

    - name: uncompress httpd
      unarchive:
        src: /etc/ansible/httpd-2.4.48.tar.gz
        dest: /opt/
    
    - name: install apr
      shell: cd /opt/apr-1.7.0 && ./configure  --prefix=/usr/local/apr && make && make install

    - name: install apr-util
      shell: cd /opt/apr-util-1.6.1 && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install

    - name: install httpd 
      shell: cd /opt/httpd-2.4.48 && ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ && make && make install
[root@node1 ansible]#
[root@node1 ansible]# ansible-playbook install.yml     //执行,然后等待结果

PLAY [apache] ******************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************
ok: [192.168.100.147]

TASK [create user] *************************************************************************************************
changed: [192.168.100.147]

TASK [install base packages] ***************************************************************************************
changed: [192.168.100.147] => (item=openssl-devel)
ok: [192.168.100.147] => (item=pcre)
changed: [192.168.100.147] => (item=perl-devel)
changed: [192.168.100.147] => (item=perl)
changed: [192.168.100.147] => (item=pcre-devel)
changed: [192.168.100.147] => (item=expat-devel)
changed: [192.168.100.147] => (item=libtool)
ok: [192.168.100.147] => (item=gcc)
changed: [192.168.100.147] => (item=gcc-c++)
ok: [192.168.100.147] => (item=make)
changed: [192.168.100.147] => (item=@development tools)

TASK [uncompress apr] **********************************************************************************************
changed: [192.168.100.147]

TASK [uncompress apr-util] *****************************************************************************************
changed: [192.168.100.147]

TASK [uncompress httpd] ********************************************************************************************
changed: [192.168.100.147]

TASK [configure] ***************************************************************************************************
changed: [192.168.100.147]

TASK [install apr] *************************************************************************************************
changed: [192.168.100.147]

TASK [install apr-util] ********************************************************************************************
changed: [192.168.100.147]

TASK [install httpd] ***********************************************************************************************
changed: [192.168.100.147]

PLAY RECAP *********************************************************************************************************
192.168.100.147            : ok=10   changed=9    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

3.查看受管主机

[root@localhost local]# ls    //我们发现我们这边有这三个编译完成的包(apr|apr-util|httpd)
apr  apr-util  bin  etc  games  httpd  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# 

4.启动服务

我们在playbook里面并没有写启动服务,所以我们手动启动

[root@localhost ~]#  /usr/local/httpd/bin/apachectl start   //启动报错,那么我们只要修改配置文件
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

5.修改配置文件

[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf    //我们进入这个文件中
[root@localhost ~]# 


ServerName localhost:80      //利用过滤找到这行,然后改成localhost,记得取消掉注释


[root@localhost ~]#  /usr/local/httpd/bin/apachectl start    //服务启动成功
httpd (pid 102793) already running

``

6.浏览器访问测试

在这里插入图片描述
如果我们要修改访问测试的内容,那么我们可以修改配置文件

[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf    //进入这个配置文件
[root@localhost ~]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html    //修改这个文件按
[root@localhost htdocs]# cat index.html 
<html><body><h1>shun zi xi huan chi shi ,wo zhi dao ta hao zhe kou!!!</h1></body></html>
[root@localhost htdocs]# 

然后访问测试内容就可以改变啦!!!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lfei5120

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值