您好,欢迎来到网暖!
?
当前位置:网暖 » 站长资讯 » 建站基础 » 网络技术 » 文章详细 订阅RssFeed

ansible远程编译部署httpd和php

来源:网络整理 浏览:193次 时间:2020-02-27
ansible远程编译部署httpd和php说明:

参考:https://blog.51cto.com/14012942/2444580

应该是能跑得起来的,不过还差的很远…

模块可拆分成多个文件

很多都是shell模块实现的,yum装包,修改配置文件等

实现第一步:能用

远程执行shell脚本应使用script模块

src文件在远程主机,应使用copy模块的remote_src参数

httpd.conf应该配个域名

相关文件压缩包:下载:https://www.lanzous.com/i6xbouj 密码:6vub

修改后:下载:https://www.lanzous.com/i72hdcb?密码:gnbe

修改后的main.yml文件:

roles/httpd/tasks/main.yml


-?name:?create?group??group:?????name:?apache????gid:?48????system:?yes????state:?present-?name:?create?user??user:?????name:?apache????uid:?48????group:?apache????comment:?"Apache"????state:?present????createhome:?no????system:?yes????shell:?/sbin/nologin-?name:?yum?install?dependency?package??yum:????name:??????-?gcc??????-?openssl-devel??????-?pcre-devel??????-?libnghttp2-devel??????-?ncurses-devel??????-?lbzip2??????-?bzip2???????-?expat-devel??????-?libtool????state:?present-?name:?unarchive?httpd.tar.gz?to?remote?server??unarchive:?????src:?roles/httpd/files/httpd-2.4.41.tar.gz????dest:?"{{?SRC?}}"-?name:?unarchive?apr.util.tar.gz?to?remote?server??unarchive:?????src:?roles/httpd/files/apr-util-1.6.1.tar.gz????dest:?"{{?SRC?}}/httpd-2.4.41/srclib/"-?name:?unarchive?apr.tar.gz?to?remote?server??unarchive:?????src:?roles/httpd/files/apr-1.7.0.tar.gz????dest:?"{{?SRC?}}/httpd-2.4.41/srclib/"-?name:?rename????shell:?|??????mv?{{?SRC?}}/httpd-2.4.41/srclib/apr-1.7.0?{{?SRC?}}/httpd-2.4.41/srclib/apr??????mv?{{?SRC?}}/httpd-2.4.41/srclib/apr-util-1.6.1?{{?SRC?}}/httpd-2.4.41/srclib/apr-util-?name:?configure??shell:?./configure?--prefix={{?PREFIX?}}?--sysconfdir={{?SYSCONFDIR?}}?--enable-http2?--enable-ssl?--enable-so??--enable-cgi?--enable-rewrite?--with-zlib?--with-pcre?--with-included-apr?--enable-modules=most?--enable-mpms-shared=all?--with-mpm=prefork??args:????chdir:?"{{?SRC?}}/httpd-2.4.41/"-?name:?Build?the?default?target??make:?????target:?install????chdir:?"{{?SRC?}}/httpd-2.4.41/"-?name:?PATH??shell:?echo?"PATH={{?PREFIX?}}/bin:$PATH"?>>?/etc/profile.d/http.sh-?name:?copy?service?file??template:?????src:?roles/httpd/templates/httpd.service.j2????dest:?/usr/lib/systemd/system/httpd.service-?name:?httpd?conf??shell:?|??????sed??'/^Group/?s/daemon/apache/'?{{?SYSCONFDIR?}}/httpd.conf??-i??????sed??'/^User/?s/daemon/apache/'?{{?SYSCONFDIR?}}/httpd.conf??-i??????sed?'$a?LoadModule?proxy_module?modules/mod_proxy.so\nLoadModule?proxy_fcgi_module?modules/mod_proxy_fcgi.so\nLoadModule?proxy_fdpass_module?modules/mod_proxy_fdpass.so'?{{?SYSCONFDIR?}}/httpd.conf??-i-?name:?systemreload??systemd:?????name:?httpd????state:?started????daemon_reload:?yes????enabled:?yes

roles/php/tasks/main.yml

-?name:?create?group??group:?????name:?apache????gid:?48????system:?yes????state:?present-?name:?create?user??user:?????name:?apache????uid:?48????group:?apache????comment:?"Apache"????state:?present????createhome:?yes????system:?yes????shell:?/sbin/noshell-?name:?yum?install??yum:?????name:??????-?gcc??????-?openssl-devel??????-?pcre-devel??????-?libnghttp2-devel??????-?ncurses-devel??????-?lbzip2??????-?bzip2??????-?expat-devel??????-?libxml2-devel??????-?libxml2??????-?libtool-?name:?copy?php??unarchive:?????src:?roles/php/files/php-7.3.10.tar.gz?????dest:?"{{?SRC?}}"-?name:?compile??shell:?|????./configure?--prefix=/usr/local/php?--enable-mysqlnd?--with-mysqli=mysqlnd?--with-pdo-mysql=mysqlnd?--with-openssl?--with-freetype-dir?--with-jpeg-dir?--with-png-dir?--with-zlib?--with-config-file-path=/usr/loca/php/etc?--with-config-file-scan-dir=/usr/local/php/etc/php.d?--enable-mbstring?--enable-xml?--enable-sockets?--enable-fpm?--enable-maintainer-zts?--disable-fileinfo??args:?????chdir:?"{{?SRC?}}/php-7.3.10/"-?name:?make?install??make:?????target:?install????chdir:?"{{?SRC?}}/php-7.3.10/"????params:??????NUM_THREADS:?4-?name:?copy?php-fpm.conf??copy:?????src:?roles/php/files/php-fpm.conf?????dest:?/usr/local/php/etc/php-fpm.conf-?name:?copy?www.conf??copy:?????src:?roles/php/files/www.conf?????dest:?/usr/local/php/etc/php-fpm.d/www.conf-?name:?copy?init?file??copy:?????src:?roles/php/files/php-fpm?????dest:?/etc/init.d/php-fpm?????mode:?0755-?name:?system?reload??systemd:?????name:?php-fpm?????state:?started?????daemon_reload:?yes?????enabled:?yes





目录结构:

image.png

入口文件
[[email protected]?test_playbook]#?cat?deploy.yml?-?hosts:?web??gather_facts:?true??remote_user:?root??roles:????-?httpd????-?php
清单文件
[[email protected]?test_playbook]#?cat??inventory/testenv?[web]192.168.38.145[web:vars]PREFIX=/usr/local/httpd2.4.41SYSCONFDIR=/etc/httpdSRC=/usr/local/srcSYSCONFDIR=/etc/httpd
httpd主任务文件
[[email protected]?test_playbook]#?cat?roles/httpd/tasks/main.yml?-?name:?create?group??group:?name=apache?gid=48?system=yes?state=present-?name:?create?user??user:?name=apache?uid=48?group=apache?comment="Apache"?state=present?createhome=no?system=yes?shell=/sbin/noshell-?name:?yum?install??shell:?yum?install?gcc?openssl-devel?pcre-devel?libnghttp2-devel?ncurses-devel??lbzip2??bzip2?expat-devel?autoconf?libtool?-y-?name:?copy?httpd??unarchive:?src=roles/httpd/files/httpd-2.4.41.tar.gz??dest={{?SRC?}}-?name:?copy?apr-utils??unarchive:?src=roles/httpd/files/apr-util-1.6.1.tar.gz?dest={{?SRC?}}/httpd-2.4.41/srclib/-?name:?cpoy?apr??unarchive:?src=roles/httpd/files/apr-1.7.0.tar.gz?dest={{?SRC?}}/httpd-2.4.41/srclib/-?name:?rename????shell:?|??????mv?{{?SRC?}}/httpd-2.4.41/srclib/apr-1.7.0?{{?SRC?}}/httpd-2.4.41/srclib/apr??????mv?{{?SRC?}}/httpd-2.4.41/srclib/apr-util-1.6.1?{{?SRC?}}/httpd-2.4.41/srclib/apr-util-?name:?compile??shell:?|??????cd?{{?SRC?}}/httpd-2.4.41/???????????./configure?--prefix={{?PREFIX?}}?--sysconfdir={{?SYSCONFDIR?}}?--enable-http2?--enable-ssl?--enable-so??--enable-cgi?--enable-rewrite?--with-zlib?--with-pcre?--with-included-apr?--enable-modules=most?--enable-mpms-shared=all?--with-mpm=prefork??????make?-j?4?&&?make?install#-?name:??compile#??shell:?chdir=/usr/local/httpd-2.4.41/?make?-j?4#-?name:?install?#??shell:?make?install?#??PATH变量看情况处理下-?name:?PATH??shell:?echo?"PATH={{?PREFIX?}}/bin:$PATH"?>>?/etc/profile.d/http.sh-?name:?copy?service?file??template:?'src=roles/httpd/templates/httpd.service.j2?dest=/usr/lib/systemd/system/httpd.service'-?name:?httpd?conf??shell:?|??????sed??'/^Group/?s/daemon/apache/'?{{?SYSCONFDIR?}}/httpd.conf??-i??????sed??'/^User/?s/daemon/apache/'?{{?SYSCONFDIR?}}/httpd.conf??-i??????sed?'$a?LoadModule?proxy_module?modules/mod_proxy.so\nLoadModule?proxy_fcgi_module?modules/mod_proxy_fcgi.so\nLoadModule?proxy_fdpass_module?modules/mod_proxy_fdpass.so'?{{?SYSCONFDIR?}}/httpd.conf??-i-?name:?systemreload??systemd:?daemon_reload=yes?name=httpd
httpd的service文件
[[email protected]?test_playbook]#?cat?roles/httpd/files/httpd.service?[Unit]Description=The?Apache?HTTP?ServerAfter=network.target?remote-fs.target?nss-lookup.target[Service]Type=simpleEnvironmentFile=${SYSCONFDIR}/httpd.confExecStart=${PREFIX}/bin/apachectl?-k?start??-DFOREGROUNDExecReload=${PREFIX}/bin/apachectl??-k?gracefulExecStop=/usr/bin/kill?-WINCH?${MAINPID}PrivateTmp=true[Install]WantedBy=multi-user.target
php主任务文件
[[email protected]?test_playbook]#?cat?roles/php/tasks/main.yml?-?name:?create?group??group:?name=apache?gid=48?system=yes?state=present-?name:?create?user??user:?name=apache?uid=48?group=apache?comment="Apache"?state=present?createhome=no?system=yes?shell=/sbin/noshell-?name:?yum?install??shell:?yum?install?gcc?openssl-devel?pcre-devel?libnghttp2-devel?ncurses-devel??lbzip2??bzip2?expat-devel?libxml2-devel?libxml2??autoconf?libtool?-y-?name:?copy?php??unarchive:?src=roles/php/files/php-7.3.10.tar.gz?dest={{?SRC?}}-?name:?compile??shell:?|??????cd?{{?SRC?}}/php-7.3.10/??????./configure?--prefix=/usr/local/php?--enable-mysqlnd?--with-mysqli=mysqlnd?--with-pdo-mysql=mysqlnd?--with-openssl?--with-freetype-dir?--with-jpeg-dir?--with-png-dir?--with-zlib?--with-config-file-path=/usr/loca/php/etc?--with-config-file-scan-dir=/usr/local/php/etc/php.d?--enable-mbstring?--enable-xml?--enable-sockets?--enable-fpm?--enable-maintainer-zts?--disable-fileinfo??????make?-j?4?&&?make?install?-?name:?copy?php-fpm.conf??copy:?'src=roles/php/files/php-fpm.conf?dest=/usr/local/php/etc/php-fpm.conf'-?name:?copy?www.conf??copy:?'src=roles/php/files/www.conf?dest=/usr/local/php/etc/php-fpm.d/www.conf'-?name:?copy?init?file??copy:?'src=roles/php/files/php-fpm?dest=/etc/init.d/php-fpm?mode=0755'-?name:?system?reload??systemd:?daemon_reload=yes?name=php-fpm
php启动文件
#php程序生成的[[email protected]?test_playbook]#?ll?roles/php/files/php-fpm-rwxr-xr-x?1?root?root?2401?Oct?23?06:01?roles/php/files/php-fpm
php配置文件

改的东西不多:进程用户,监听套接字,php进程数量没改

安装完成,没太大问题中途报错单步排错:
#?php和httpd应该加入开机启动#?httpd可以选择安装目录#?编译php不建议改安装目录了,不然后面还要改脚本#?例如ansible?web??-i?../../../inventory/testenv?-m?template?-a?'src=../../httpd/templates/httpd.service.j2?dest=/usr/lib/systemd/system/httpd.service'[[email protected]?test_playbook]#?ansible?web?-i?inventory/testenv?-m?unarchive?-a?'src=roles/php/files/php-7.3.10.tar.gz?dest=/usr/local/src'[[email protected]?test_playbook]#?ansible?web?-i?inventory/testenv?-m?systemd?-a?'name=httpd?state=started?daemon_reload=yes?enabled=yes'[[email protected]?test_playbook]#?ansible?web?-i?inventory/testenv?-m?systemd?-a?'name=php-fpm?state=started?daemon_reload=yes?enabled=yes'#使用ansible直接操作主机IP时主机应存在于/etc/ansible/hosts,#开启密钥验证就用-k了#playbook脚本中管道|可?#36828;?#34892;执行shell命令
安装完成后测试
[[email protected]?~]#?cat?>>?/etc/httpd/httpd.conf?<<EOFProxyRequests?OffProxyPassMatch?^/(.*\.php)$?unix:/var/run/php-fpm.sock|fcgi://localhost/var/www/htmlEOF[[email protected]?~]#?sed??'s/DirectoryIndex?index.html/DirectoryIndex?index.php?index.html/'?/etc/httpd/httpd.conf?-i[[email protected]?~]#?sed?-r?'[email protected]/usr/local/httpd2.4.41/[email protected]/var/www/[email protected]'?/etc/httpd/httpd.conf?-i[[email protected]?~]#?mkdir?/var/www/html?-p[[email protected]?~]#?cat?>?/var/www/html/index.php?<<EOF<?????phpinfo();?>EOF[[email protected]?~]#?httpd?-t[[email protected]?~]#?systemctl?restart?httpd


推荐站点

  • 腾讯腾讯

    腾讯网(www.QQ.com)是中国浏览量最大的中文门户网站,是腾讯公?#23601;?#20986;的集新闻信息、互动社区、娱乐产品和基础服务为一体的大型综合门户网站。腾讯网服务于全球华人用户,致力成为最具传播力和互动性,权威、主流、时尚的互联网媒体平台。通过?#30475;?#30340;实时新闻和全面深入的信息资讯服务,为中国数以亿计的互联网用户提供富有创意的网上新生活。

    www.qq.com
  • 搜狐搜狐

    搜狐网是全球最大的中文门户网站,为用户提供24小时不间断的最新资讯,及搜索、邮件等网络服务。内容包括全球热点事件、突发新闻、时事评论、热播影视剧、体育赛事、行业动态、生活服务信息,以及论坛、博客、微博、我的搜狐等互动空间。

    www.sohu.com
  • 网易网易

    网易是中国领先的互联网技术公司,为用户提供免费邮箱、游戏、搜索引擎服务,开设新闻、娱乐、体育等30多个内容?#26723;潰安?#23458;、视频、论坛等互动交流,网聚?#35828;?#21147;量。

    www.163.com
  • 新浪新浪

    新浪网为全球用户24小时提供全面及时的中文资讯,内容覆盖国内外突发新闻事件、体坛赛事、娱乐时尚、产业资讯、实用信息等,设?#34892;?#38395;、体育、娱乐、财经、科技、房产、汽车等30多个内容?#26723;潰?#21516;时开设博客、视频、论坛等自由互动交流空间。

    www.sina.com.cn
  • 百度一下百度一下

    百度一下,你就知道

    www.baidu.com
?
诙谐财富送彩金
我查云南十一选五开 浙江十一选五一定牛 基金配资申请 基金配资比例两种模式 007足球指数 大赢家比分网ume8 新疆25选7 天津11选5 吉林十一选五开奖直 武汉麻将怎么玩图解 广西打牌的技巧 七位数今天开奖结果 河北20选5今日开 排球比分多少算赢 北单比分推荐app 天津11选5