IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 变量安装Apache服务 -> 正文阅读

[系统运维]变量安装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访问

在这里插入图片描述

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章           查看所有文章
加:2021-07-24 11:53:55  更:2021-07-24 11:56:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/4 7:45:32-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码