CentOS 6.10源码编译及使用ansible编译安装httpd2.4.39

所属分类: 操作系统 / unix linux 阅读数: 137
收藏 0 赞 0 分享

一、编译安装

编译环境准备

主机 系统
A centos6.10

编译所需的httpd、apr、apr-util

apr-1.7.0.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.39.tar.gz

1.安装编译所需要的软件

yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree screen lsof tcpdump wget ntpdate net-tools iotop bc zip unzip nfs-utils expat-devel -y

2.解压所有压缩包

[root@CentOS6 ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@CentOS6 ~]# tar -xf apr-1.7.0.tar.gz 
[root@CentOS6 ~]# tar -xf httpd-2.4.39.tar.gz

3.将apr及apr-util复制到httpd-2.4.39/srclib目录中

[root@CentOS6 ~]# cp -a apr-1.7.0 httpd-2.4.39/srclib/apr
[root@CentOS6 ~]# cp -a apr-util-1.6.1 httpd-2.4.39/srclib/apr-util

4.编译httpd

[root@CentOS6 ~]# cd httpd-2.4.39
[root@CentOS6 httpd-2.4.39]# ./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr=/root/httpd-2.4.39/srclib/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

5.安装

[root@CentOS6 ~]# make && make install

6.为httpd创建系统用户

[root@CentOS6 ~]# useradd -r -s /sbin/nologin apache

7.修改配置文件,将httpd运行的用户和组改为apache

[root@CentOS6 ~]# vim /app/httpd24/conf/httpd.conf 
User apache
Group apache

8.配置环境变量

[root@CentOS6 ~]# echo "PATH=/app/httpd24/bin:$PATH" > /etc/profile.d/httpd24.sh

9.设置为开机启动

[root@CentOS6 ~]# vim /etc/rc.d/rc.local 
/app/httpd24/bin/apachectl start
ansible-playbook编译安装httpd2.4

ansible 编译安装httpd

一、创建角色目录结构

[root@localhost data]# mkdir -pv roles/httpd2.4/{tasks,files,vars,templates,handlers}
mkdir: created directory ‘roles'
mkdir: created directory ‘roles/httpd2.4'
mkdir: created directory ‘roles/httpd2.4/tasks'
mkdir: created directory ‘roles/httpd2.4/files'
mkdir: created directory ‘roles/httpd2.4/vars'
mkdir: created directory ‘roles/httpd2.4/templates'
mkdir: created directory ‘roles/httpd2.4/handlers'

二、创建task

进入tasks目录

[root@localhost ~]# cd /data/roles/httpd2.4/tasks/

1.为httpserver创建安装目录

[root@localhost tasks]# vim createdir.yaml 
- name: Create dir
 file: path=/app state=directory

2.解压httpd,apr,apr-util到远程主机

[root@localhost tasks]# vim ungzhttpd.yaml 
- name: ungz httpd24
 unarchive: src=httpd.tar.gz dest=/app copy=yes
- name: ungz apr to srclib
 unarchive: src=apr.tar.gz dest=/app/httpd-2.4.39/srclib copy=yes
- name: ungz apr-util to srclib
 unarchive: src=apr-util.tar.gz dest=/app/httpd-2.4.39/srclib copy=yes

3.对解压后的apr.tar.gz及apr-util.tar.gz做软连接

[root@localhost tasks]# vim links.yaml
- name: link apr-util
 file: src=/app/httpd-2.4.39/srclib/apr-util-1.6.1 dest=/app/httpd-2.4.39/srclib/apr-util state=link
- name: link apr
 file: src=/app/httpd-2.4.39/srclib/apr-1.7.0 dest=/app/httpd-2.4.39/srclib/apr state=link

4.编译httpd

[root@localhost tasks]# vim configure.yaml 
- name: configer httpd
 shell: /app/httpd-2.4.39/configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr=/root/httpd-2.4.39/srclib/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

5.make

[root@localhost tasks]# vim make.yaml 
- name: make
 shell: make

6.make install

[root@localhost tasks]# vim install.yaml 
- name: install
 shell: make install

7.设置开机自启

[root@localhost tasks]# vim chkconf.yaml 
- name: chkconfig
 lineinfile: path=/etc/rc.d/rc.local insertafter="^touch.*" line="/app/httpd24/bin/apachectl start"

8.添加apache用户

[root@localhost tasks]# vim useradd.yaml 
- name: add user
 user: name=apache system=yes shell=/sbin/nologin create_home=no

9.调用模板文件生成环境变量及httpd配置文件

[root@localhost tasks]# vim template.yaml
- name: httpd config
 template: src=httpd.conf.j2 dest=/app/httpd24/conf/httpd.conf
- name: Path
 template: src=httpd.sh.j2 dest=/etc/profile.d/httpd.sh

10.读取环境变量

[root@localhost tasks]# vim source.yaml 
- name: source path
 shell: source /etc/profile.d/httpd.sh

11.启动服务

[root@localhost tasks]# vim service.yaml 
- name: start service
 shell: apachectl start

12.创建main.yaml

[root@localhost tasks]# vim main.yaml 
- include: createdir.yaml
- include: ungzhttpd.yaml
- include: links.yaml
- include: configure.yaml
- include: make.yaml
- include: install.yaml
- include: chkconf.yaml
- include: useradd.yaml
- include: template.yaml
- include: source.yaml
- include: service.yaml

三、创建playbook

[root@localhost data]# vim role_httpd.yaml 
[root@localhost tasks]# cd /data
[root@localhost data]# vim role_httpd.yaml 
---
- hosts: all
 roles:
 - role: httpd2.4

四、目录结构

[root@localhost data]# tree /data
/data
├── role_httpd.yaml
└── roles
 └── httpd2.4
  ├── files       #此目录下存放所有需要解压的包,注意去掉版本号
  │ ├── apr.tar.gz
  │ ├── apr-util.tar.gz
  │ └── httpd.tar.gz
  ├── handlers
  ├── tasks
  │ ├── chkconf.yaml
  │ ├── configure.yaml
  │ ├── createdir.yaml
  │ ├── install.yaml
  │ ├── links.yaml
  │ ├── main.yaml
  │ ├── make.yaml
  │ ├── service.yaml
  │ ├── source.yaml
  │ ├── template.yaml
  │ ├── ungzhttpd.yaml
  │ └── useradd.yaml
  ├── templates      #此目录下存放配置文件和环境变量的模板文件
  │ ├── httpd.conf.j2
  │ └── httpd.sh.j2
  └── vars

五、执行playbook

[root@localhost ansible]# ansible-playbook role_httpd.yaml

以上所述是小编给大家介绍的CentOS 6.10源码编译及使用ansible编译安装httpd2.4.39,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

更多精彩内容其他人还在看

Linux通过命令仅获取IP地址的方法

这篇文章主要介绍了Linux通过命令仅获取IP地址的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Linux 下VSFTP服务搭建过程

这篇文章主要介绍了Linux 下VSFTP服务搭建,需要的朋友可以参考下
收藏 0 赞 0 分享

CentOS 7.0关闭默认防火墙启用iptables防火墙的设置方法

这篇文章主要介绍了CentOS 7.0关闭默认防火墙启用iptables防火墙的设置方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Linux系统下解决getch()输入数值不回显示问题

这篇文章主要介绍了Linux系统下解决getch()输入数值不回显示问题,本文给大家介绍的非常详细,具有参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

监控Linux系统节点和服务性能的方法

这篇文章主要介绍了监控Linux系统节点和服务性能的方法,本文给大家介绍的非常详细,具有参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

Linux下scp无密码上传 下载 文件 目录的方法

这篇文章主要介绍了Linux下scp无密码上传 下载 文件 目录的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

简述Linux文本处理命令“sed”

sed是一种流编辑器,它是文本处理中非常中的工具,能够完美的配合正则表达式使用,功能不同凡响。下面通过本文给大家简单介绍Linux文本处理命令“sed”,需要的朋友参考下吧
收藏 0 赞 0 分享

Linux简易彩色进度条的实例代码

#进度条:顾名思义就是看计算机处理任务时的速度,完成度。下面通过本文给大家分享Linux简易彩色进度条的实例代码,需要的朋友参考下吧
收藏 0 赞 0 分享

详解shell中source、sh、bash、./执行脚本的区别

这篇文章主要介绍了shell中source、sh、bash、./执行脚本的区别,需要的朋友可以参考下
收藏 0 赞 0 分享

详解Linux实现U盘自动挂载(图文教程)

这篇文章主要介绍了Linux实现U盘自动挂载功能,本文图文并茂给大家介绍的非常详细,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多