Ansible用源码安装apache服务

[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: ‘ R M " RM " 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]

最后

码字不易,觉得有帮助的可以帮忙点个赞,让更多有需要的人看到

又是一年求职季,在这里,我为各位准备了一套Java程序员精选高频面试笔试真题,来帮助大家攻下BAT的offer,题目范围从初级的Java基础到高级的分布式架构等等一系列的面试题和答案,用于给大家作为参考

以下是部分内容截图
架构面试专题及架构学习笔记导图.png
29.135]

TASK [create group] *************************************************************************************************************************************************

ok: [192.168.129.135]

TASK [create user] **************************************************************************************************************************************************

ok: [192.168.129.135]

最后

码字不易,觉得有帮助的可以帮忙点个赞,让更多有需要的人看到

又是一年求职季,在这里,我为各位准备了一套Java程序员精选高频面试笔试真题,来帮助大家攻下BAT的offer,题目范围从初级的Java基础到高级的分布式架构等等一系列的面试题和答案,用于给大家作为参考

以下是部分内容截图
[外链图片转存中…(img-D3EIYaZQ-1721131024428)]

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值