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.安装编译所需要的软件
yuminstallgccgcc-c++glibcglibc-develpcrepcre-developensslopenssl-develsystemd-develzlib-develvimlrzsztreescreenlsoftcpdumpwgetntpdatenet-toolsiotopbczipunzipnfs-utilsexpat-devel-y
2.解压所有压缩包
[root@CentOS6~]#tar-xfapr-util-1.6.1.tar.gz [root@CentOS6~]#tar-xfapr-1.7.0.tar.gz [root@CentOS6~]#tar-xfhttpd-2.4.39.tar.gz
3.将apr及apr-util复制到httpd-2.4.39/srclib目录中
[root@CentOS6~]#cp-aapr-1.7.0httpd-2.4.39/srclib/apr [root@CentOS6~]#cp-aapr-util-1.6.1httpd-2.4.39/srclib/apr-util
4.编译httpd
[root@CentOS6~]#cdhttpd-2.4.39 [root@CentOS6httpd-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&&makeinstall
6.为httpd创建系统用户
[root@CentOS6~]#useradd-r-s/sbin/nologinapache
7.修改配置文件,将httpd运行的用户和组改为apache
[root@CentOS6~]#vim/app/httpd24/conf/httpd.conf Userapache Groupapache
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/apachectlstart ansible-playbook编译安装httpd2.4
ansible编译安装httpd
一、创建角色目录结构
[root@localhostdata]#mkdir-pvroles/httpd2.4/{tasks,files,vars,templates,handlers} mkdir:createddirectory‘roles' mkdir:createddirectory‘roles/httpd2.4' mkdir:createddirectory‘roles/httpd2.4/tasks' mkdir:createddirectory‘roles/httpd2.4/files' mkdir:createddirectory‘roles/httpd2.4/vars' mkdir:createddirectory‘roles/httpd2.4/templates' mkdir:createddirectory‘roles/httpd2.4/handlers'
二、创建task
进入tasks目录
[root@localhost~]#cd/data/roles/httpd2.4/tasks/
1.为httpserver创建安装目录
[root@localhosttasks]#vimcreatedir.yaml -name:Createdir file:path=/appstate=directory
2.解压httpd,apr,apr-util到远程主机
[root@localhosttasks]#vimungzhttpd.yaml -name:ungzhttpd24 unarchive:src=httpd.tar.gzdest=/appcopy=yes -name:ungzaprtosrclib unarchive:src=apr.tar.gzdest=/app/httpd-2.4.39/srclibcopy=yes -name:ungzapr-utiltosrclib unarchive:src=apr-util.tar.gzdest=/app/httpd-2.4.39/srclibcopy=yes
3.对解压后的apr.tar.gz及apr-util.tar.gz做软连接
[root@localhosttasks]#vimlinks.yaml -name:linkapr-util file:src=/app/httpd-2.4.39/srclib/apr-util-1.6.1dest=/app/httpd-2.4.39/srclib/apr-utilstate=link -name:linkapr file:src=/app/httpd-2.4.39/srclib/apr-1.7.0dest=/app/httpd-2.4.39/srclib/aprstate=link
4.编译httpd
[root@localhosttasks]#vimconfigure.yaml -name:configerhttpd 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@localhosttasks]#vimmake.yaml -name:make shell:make
6.makeinstall
[root@localhosttasks]#viminstall.yaml -name:install shell:makeinstall
7.设置开机自启
[root@localhosttasks]#vimchkconf.yaml -name:chkconfig lineinfile:path=/etc/rc.d/rc.localinsertafter="^touch.*"line="/app/httpd24/bin/apachectlstart"
8.添加apache用户
[root@localhosttasks]#vimuseradd.yaml -name:adduser user:name=apachesystem=yesshell=/sbin/nologincreate_home=no
9.调用模板文件生成环境变量及httpd配置文件
[root@localhosttasks]#vimtemplate.yaml -name:httpdconfig template:src=httpd.conf.j2dest=/app/httpd24/conf/httpd.conf -name:Path template:src=httpd.sh.j2dest=/etc/profile.d/httpd.sh
10.读取环境变量
[root@localhosttasks]#vimsource.yaml -name:sourcepath shell:source/etc/profile.d/httpd.sh
11.启动服务
[root@localhosttasks]#vimservice.yaml -name:startservice shell:apachectlstart
12.创建main.yaml
[root@localhosttasks]#vimmain.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@localhostdata]#vimrole_httpd.yaml [root@localhosttasks]#cd/data [root@localhostdata]#vimrole_httpd.yaml --- -hosts:all roles: -role:httpd2.4
四、目录结构
[root@localhostdata]#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@localhostansible]#ansible-playbookrole_httpd.yaml
总结
以上所述是小编给大家介绍的CentOS6.10源码编译及使用ansible编译安装httpd2.4.39,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!