Ansible用源码安装apache服务

1、环境

服务ip
ansible192.168.129133
httpd192.168.129.135

2、解析

[root@ansible ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.129.133 httpd

3、密码

SSH免密登陆

[root@ansible ~]# ssh-keygen -t rsa  #生成密钥,指定加密方式 ,下面默认一路回车即可
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:m9UgEbkFLID4MnlRrsmn76K0ARRhb6NEScTM1etAfEM root@ansible
The key's randomart image is:
+---[RSA 3072]----+
|*O=+=E .++       |
|+==+ +. o..      |
| =.=o o..o.      |
|*.=+..  .. o     |
|.=+ +   S . .    |
|.  o .   +       |
| o.     o        |
|. +.             |
|.o oo            |
+----[SHA256]-----+

[root@ansible ~]# ssh-copy-id root@httpd   #传递公钥
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'httpd (192.168.129.133)' can't be established.
ECDSA key fingerprint is SHA256:+wH81RHiBmLpbkuk2OWGZxVRziiaNwJ9KAVjGtEM8zs.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@httpd's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@httpd'"
and check to make sure that only the key(s) you wanted were added.

ping

[root@ansible playbook]# ansible all -m ping
192.168.129.135 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

4、查看项目文件

[root@ansible playbook]# tree 
.
├── bao.yml
├── install.yml
└── pei.yml

5、源码包地址

wget https://mirrors.bfsu.edu.cn/apache/apr/apr-1.7.0.tar.gz
wget https://mirrors.bfsu.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
wget https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.48.tar.gz

6、下载源码包

bao.yml

[root@ansible playbook]# cat bao.yml 
---
- hosts: httpd
  tasks: 
    - name: httpd
      get_url:
        url: https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.48.tar.gz
        dest: /opt

    - name: apr
      get_url:
        url: https://mirrors.bfsu.edu.cn/apache/apr/apr-1.7.0.tar.gz
        dest: /opt

    - name: apr-util
      get_url:
        url: https://mirrors.bfsu.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
        dest: /opt

空运行

[root@ansible playbook]# ansible-playbook -C bao.yml

PLAY [httpd] ********************************************************************************************************************************************************

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

TASK [httpd] ********************************************************************************************************************************************************
changed: [192.168.129.135]

TASK [apr] **********************************************************************************************************************************************************
changed: [192.168.129.135]

TASK [apr-util] *****************************************************************************************************************************************************
changed: [192.168.129.135]

PLAY RECAP **********************************************************************************************************************************************************
192.168.129.135            : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


7、编写主机变量文件 pei.yml文件

[root@ansible playbook]# cat pei.yml 
---
  dell: gcc,gcc-c++,perl,perl-devel,expat-devel,pcre-devel,pcre
  apr_install: " cd /root/apr-1.7.0/ && ./configure --prefix=/usr/local/apr && make && make install "
  apr_util_install: "cd /root/apr-util-1.6.1/ && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install"
  httpd_install: " cd  /root/httpd-2.4.48/ && ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  && make && make install " 

8、编写源码安装apache文件

install.yml文件

[root@ansible playbook]# cat install.yml 
---
 - hosts: httpd
   vars_files:
     - /opt/playbook/pei.yml
   tasks:
     - name: stop and disabled firewalld
       service:
         name: firewalld
         state: stopped
         enabled: no

     - name: disabled selinux
       lineinfile:
         path: /etc/selinux/config
         regexp: "^SELINUX="
         line: "SELINUX=disabled"
         state: present

     - name: install tools
       yum:
         name: "{{ dell }}"
         state: present
 
     - name: apr
       unarchive:
         src: /opt/apr-1.7.0.tar.gz
         dest: /root
         copy: no
       tags: unarchive

     - name: apr-util
       unarchive:
         src: /opt/apr-util-1.6.1.tar.gz
         dest: /root
         copy: no
       tags: unarchive
          
     - name: httpd
       unarchive:
         src: /opt/httpd-2.4.48.tar.gz
         dest: /root
         copy: no
       tags: unarchive
 
     - name: del
       lineinfile:
         dest: /root/apr-17.0/configure
         regexp: '$RM "$cfgfile"'
         state: absent

     - name: create group
       group: 
         name: apache
         system: yes
         state: present

     - name: create user
       user:
         name: apache
         system: yes
         state: present

     - name: install apr
       shell: " {{ apr_install }}"

     - name: intall apr-util
       shell: " {{ apr_util_install }}"

     - name: install httpd
       shell: " {{ httpd_install }}  "

     - name: start httpd service
       shell: " /usr/local/httpd/bin/apachectl start "

验证语法

[root@ansible playbook]# ansible-playbook --syntax-check install.yml 

playbook: install.yml

空运行

[root@ansible playbook]# ansible-playbook -C install.yml 
PLAY [httpd] ********************************************************************************************************************************************************

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

TASK [stop and disabled firewalld] **********************************************************************************************************************************
ok: [192.168.129.135]

TASK [disabled selinux] *********************************************************************************************************************************************
ok: [192.168.129.135]

TASK [install tools] ************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [apr] **********************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [apr-util] *****************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [httpd] ********************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [del] **********************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [create group] *************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [create user] **************************************************************************************************************************************************
ok: [192.168.129.135]

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

TASK [intall apr-util] **********************************************************************************************************************************************
changed: [192.168.129.135]

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

TASK [start httpd service] ******************************************************************************************************************************************
changed: [192.168.129.135]

PLAY RECAP **********************************************************************************************************************************************************
192.168.129.135            : ok=14   changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
  

执行playbook文件

[root@ansible playbook]# ansible-playbook install.yml
PLAY [httpd] ********************************************************************************************************************************************************

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

TASK [stop and disabled firewalld] **********************************************************************************************************************************
ok: [192.168.129.135]

TASK [disabled selinux] *********************************************************************************************************************************************
ok: [192.168.129.135]

TASK [install tools] ************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [apr] **********************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [apr-util] *****************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [httpd] ********************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [del] **********************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [create group] *************************************************************************************************************************************************
ok: [192.168.129.135]

TASK [create user] **************************************************************************************************************************************************
ok: [192.168.129.135]

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

TASK [intall apr-util] **********************************************************************************************************************************************
changed: [192.168.129.135]

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

TASK [start httpd service] ******************************************************************************************************************************************
changed: [192.168.129.135]

PLAY RECAP **********************************************************************************************************************************************************
192.168.129.135            : ok=14   changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

9、在浏览器用HTTP主机IP访问

在这里插入图片描述
源码安装MYSQL
mysql源码包如何安装

10、总结:源码安装apache

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

添加index.php
DirectoryIndex index.html index.php

添加
<VirtualHost :80>
DocumentRoot “/var/www/html/”
ServerName www.hhr.com
ProxyRequests Off
ProxyPassMatch ^/(.
.php)$ fcgi://192.168.129.137:9000/var/www/html/$1

删除
/root/apr-17.0/configure
R M " RM " RM"cfgfile"’

取消注释
“#ServerName www.example.com:80”
“ServerName www.example.com:80”

php

添加注释(;)
;listen = /run/php-fpm/www.sock
添加端口
listen = 0.0.0.0:9000"

添加ip
listen.allowed_clients = 192.168.129.133

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值