运维开发网

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

运维开发网 https://www.qedev.com 2020-01-16 13:50 出处:网络 作者: Masuri
这篇文章主要介绍了CentOS 6.10源码编译及使用ansible编译安装httpd2.4.39的教程,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

一、编译安装

编译环境准备

主机 系统
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.解压所有压缩包

[[email protected] ~]# tar -xf apr-util-1.6.1.tar.gz 
[[email protected] ~]# tar -xf apr-1.7.0.tar.gz 
[[email protected] ~]# tar -xf httpd-2.4.39.tar.gz

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

[[email protected] ~]# cp -a apr-1.7.0 httpd-2.4.39/srclib/apr
[[email protected] ~]# cp -a apr-util-1.6.1 httpd-2.4.39/srclib/apr-util

4.编译httpd

[[email protected] ~]# cd httpd-2.4.39
[[email protected] 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.安装

[[email protected] ~]# make && make install

6.为httpd创建系统用户

[[email protected] ~]# useradd -r -s /sbin/nologin apache

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

[[email protected] ~]# vim /app/httpd24/conf/httpd.conf 
User apache
Group apache

8.配置环境变量

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

9.设置为开机启动

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

ansible 编译安装httpd

一、创建角色目录结构

[[email protected] 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目录

[[email protected] ~]# cd /data/roles/httpd2.4/tasks/

1.为httpserver创建安装目录

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

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

[[email protected] 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做软连接

[[email protected] 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

[[email protected] 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

[[email protected] tasks]# vim make.yaml 
- name: make
 shell: make

6.make install

[[email protected] tasks]# vim install.yaml 
- name: install
 shell: make install

7.设置开机自启

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

8.添加apache用户

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

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

[[email protected] 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.读取环境变量

[[email protected] tasks]# vim source.yaml 
- name: source path
 shell: source /etc/profile.d/httpd.sh

11.启动服务

[[email protected] tasks]# vim service.yaml 
- name: start service
 shell: apachectl start

12.创建main.yaml

[[email protected] 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

[[email protected] data]# vim role_httpd.yaml 
[[email protected] tasks]# cd /data
[[email protected] data]# vim role_httpd.yaml 
---
- hosts: all
 roles:
 - role: httpd2.4

四、目录结构

[[email protected] 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

[[email protected] ansible]# ansible-playbook role_httpd.yaml

总结

以上所述是小编给大家介绍的CentOS 6.10源码编译及使用ansible编译安装httpd2.4.39,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号