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.解压所有压缩包
[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,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
以上是 CentOS 6.10源码编译及使用ansible编译安装httpd2.4.39 的全部内容, 来源链接: utcz.com/z/312661.html