源码安装apache脚本部署过程详解


Posted in Servers onSeptember 23, 2022

源码安装apache脚本部署

[root@localhost ~]# ls
anaconda-ks.cfg  httpd.tar.xz
[root@localhost ~]# tar xf httpd.tar.xz  解压存放脚本的压缩包
[root@localhost ~]# ls
anaconda-ks.cfg  httpd  httpd.tar.xz
[root@localhost ~]# cd httpd/
[root@localhost httpd]# ls
apache_lnh.sh(编译安装apache脚本)  config.sh(附属脚本)  files
[root@localhost httpd]# ls files/    //存放安装包的目录
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz  httpd-2.4.54.tar.gz  zhuawawa(源码包的目录)
[root@localhost httpd]# cat apache_lnh.sh 
#/bin/bash

#列出httpd版本号进行选择
cat > /tmp/xbz.txt <<EOF
请输入要安装的版本序号:
1. 2.4.54
2. 2.4.53
q. 退出

EOF
cat /tmp/xbz.txt
read -p "选择版本号"  apache_version
case $apache_version in
        1)
        apache_version=$(awk 'NR==2{print $2}'  /tmp/xbz.txt)
        echo $apache_version
        ;;
        2)
        apache_version=$(awk 'NR==3{print $2}'  /tmp/xbz.txt)
        echo $apache_version
        ;;
        q)
        apache_version=$(awk 'NR==4{print $2}'  /tmp/xbz.txt)
        echo $apache_version
        exit
        ;;
        *)
        echo "错误输入"
        exit
esac
#设置执行权限
if [ $UID -ne 0 ];then
        echo "请以管理员用户进行执行"
        exit
fi
#定义变量
install_dir=/usr/local/apache
#创建用户
id apache &> /dev/null
if [ $? -ne 0 ];then
            useradd -r -M -s /sbin/nologin apache
    else
            echo "用户已存在"
fi
#安装依赖包
dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget make vim  zip --allowerasing
#解压源码包
rm -rf /tmp/*
tar xf files/apr-1.7.0.tar.gz -C /tmp/
tar xf files/apr-util-1.6.1.tar.gz -C /tmp/
tar xf files/httpd-$apache_version.tar.gz -C /tmp/
#编译安装apr
cd /tmp/apr-1.7.0
if [ ! -d /usr/local/apr ];then
sed -i '/$RM "$cfgfile"/d' configure
./configure --prefix=/usr/local/apr && \
make && make install    
else
        ls /usr/local
        echo "apr 编译安装完成"
fi
#编译安装apr-util
cd ../apr-util-1.6.1/
if [ ! -d /usr/local/apr-util ];then
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
make && make install
else
         ls /usr/local/
         echo "apr-util 编译安装完成"       
fi
#编译安装httpd
cd ../httpd-$apache_version/
if [ ! -d ${install_dir} ];then
            ./configure --prefix=${install_dir} \
                    --enable-so \
                    --enable-ssl \
                    --enable-cgi \
                    --enable-rewrite \
                    --with-zlib \
                    --with-pcre \
                    --with-apr=/usr/local/apr \
                    --with-apr-util=/usr/local/apr-util/ \
                    --enable-modules=most \
                    --enable-mpms-shared=all \
                    --with-mpm=prefork   
             make && make install    
else
          ls ${install_dir}
          echo "httpd 编译安装完成"
fi
#设置环境变量,man文档,头文件
echo "export PATH=${install_dir}/bin:\$PATH" > /etc/profile.d/apache.sh
ln -s ${install_dir}/include /usr/include/apache &> /dev/null
grep 'apache' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
            sed -i "22a MANDATORY_MANPATH                       ${install_dir}/man" /etc/man_db.conf
fi
#将其加入systemd服务里面
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=httpd server daemon
After=network.target

[Service]
Type=forking
ExecStart=${install_dir}/bin/apachectl start
ExecStop=${install_dir}/bin/apachectl stop
ExecReload=/bin/kill -HUP \$MAINPID

[Install]
WantedBy=multi-user.target
EOF
#加载文件并设置开机自启
systemctl daemon-reload
systemctl enable --now httpd
#查看端口
ss -antl
[root@localhost httpd]# cat config.sh 
#!/bin/bash

#定义变量
install_dir=$(grep '^install_dir=' apache_lnh.sh  | awk -F'=' '{print $2}' )
echo $install_dir

#添加包含虚拟主机
grep 'Include conf/extra/httpd-vhosts.conf' $install_dir/conf/httpd.conf &> /dev/null
if [ $? -eq 0 ];then
        echo "Include conf/extra/httpd-vhosts.conf" >> $install_dir/conf/httpd.conf
fi
#配置虚拟主机
cat > $install_dir/conf/extra/httpd-vhosts.conf <<EOF
<VirtualHost *:80>
    DocumentRoot "$install_dir/htdocs/zhuawawa.example.com"
    ServerName zhuawawa.example.com
    ErrorLog "logs/zhuawawa.example.com-error_log"
    CustomLog "logs/zhuawawa.example.com-access_log" common
</VirtualHost>
EOF
#添加防火墙规则
firewall-cmd --add-rich-rule 'rule family=ipv4 source address=0.0.0.0/0 port port=80 protocol=tcp accept' --permanent &> /dev/null
firewall-cmd --reload
#创建网站存放目录
mkdir -p $install_dir/htdocs/zhuawawa.example.com
cp -r files/zhuawawa/* $install_dir/htdocs/zhuawawa.example.com

#重启httpd
systemctl restart httpd
#查看端口
ss -antl
[root@localhost httpd]# ls
apache_lnh.sh  config.sh  files
[root@localhost httpd]# ls files/
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz  httpd-2.4.54.tar.gz  zhuawawa(提前将源码包解压到这里)
[root@localhost httpd]# ls files/zhuawawa/  (此处是我解压的源码包)
Battle_City  audio  css  images  index.html  js  tk.zip

进行访问:

源码安装apache脚本部署过程详解

[root@localhost ~]# tar -Jcf httpd.tar.xz httpd/  //压缩脚本存放目录
[root@localhost ~]# ls
anaconda-ks.cfg  httpd  httpd.tar.xz

到此这篇关于源码安装apache脚本部署的文章就介绍到这了,更多相关源码安装apache内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Servers 相关文章推荐
Nginx tp3.2.3 404问题解决方案
Mar 31 Servers
nginx 多个location转发任意请求或访问静态资源文件的实现
Mar 31 Servers
使用 Apache Superset 可视化 ClickHouse 数据的两种方法
Jul 07 Servers
Kubernetes中Deployment的升级与回滚
Apr 01 Servers
基于Apache Hudi在Google云构建数据湖平台的思路详解
Apr 07 Servers
Mac电脑OS系统下安装Nginx的详细教程
Apr 14 Servers
解决Vmware虚拟机安装centos8报错“Section %Packages Does Not End With %End. Pane Is Dead”
Jun 01 Servers
Linux中文件的基本属性介绍
Jun 01 Servers
openEuler 搭建java开发环境的详细过程
Jun 10 Servers
Windows Server 2008配置防火墙策略详解
Jun 28 Servers
windows server2012 R2下安装PaddleOCR服务的的详细步骤
Sep 23 Servers
nginx sticky实现基于cookie负载均衡示例详解
Dec 24 Servers
教你使用Ubuntu搭建DNS服务器
Sep 23 #Servers
windows server2012 R2下安装PaddleOCR服务的的详细步骤
Apache SkyWalking 监控 MySQL Server 实战解析
Sep 23 #Servers
服务器nginx权限被拒绝解决案例
Sep 23 #Servers
Fluentd搭建日志收集服务
Sep 23 #Servers
Flink 侧流输出源码示例解析
Sep 23 #Servers
修改Nginx配置返回指定content-type的方法
Sep 23 #Servers
You might like
php对gzip文件或者字符串解压实例参考
2008/07/25 PHP
Codeigniter出现错误提示Error with CACHE directory的解决方案
2014/06/12 PHP
php使用正则表达式获取图片url的方法
2015/01/16 PHP
PHP实现通过二维数组键值获取一维键名操作示例
2019/10/11 PHP
IE与Firefox下javascript getyear年份的兼容性写法
2007/12/20 Javascript
jQuery源码解读之addClass()方法分析
2015/02/20 Javascript
浅谈jQuery中的事件
2015/03/23 Javascript
深入浅析JS是按值传递还是按引用传递(推荐)
2016/09/18 Javascript
超全面的javascript中变量命名规则
2017/02/09 Javascript
Bootstrap3 多个模态对话框无法显示的解决方案
2017/02/23 Javascript
基于nodejs res.end和res.send的区别
2018/05/14 NodeJs
vue中使用sessionStorage记住密码功能
2018/07/24 Javascript
video.js 一个页面同时播放多个视频的实例代码
2018/11/27 Javascript
[02:15]2014DOTA2国际邀请赛 专访LGD.lin小兔子是大腿
2014/07/14 DOTA
Python抽象类的新写法
2015/06/18 Python
wxpython中Textctrl回车事件无效的解决方法
2016/07/21 Python
解决python3捕获cx_oracle抛出的异常错误问题
2018/10/18 Python
Python中如何导入类示例详解
2019/04/17 Python
Python 一行代码能实现丧心病狂的功能
2020/01/18 Python
有关pycharm登录github时有的时候会报错connection reset的问题
2020/09/15 Python
Python Charles抓包配置实现流程图解
2020/09/29 Python
Pycharm常用快捷键总结及配置方法
2020/11/14 Python
HTML5-WebSocket实现聊天室示例
2016/12/15 HTML / CSS
HTML5在canvas中绘制复杂形状附效果截图
2014/06/23 HTML / CSS
小米官方旗舰店:Xiaomi
2020/08/07 全球购物
2014年公司植树节活动方案
2014/03/04 职场文书
经典禁毒标语
2014/06/16 职场文书
社区四风存在问题及整改措施
2014/10/26 职场文书
简单的离婚协议书范本
2014/11/16 职场文书
清洁工岗位职责
2015/02/13 职场文书
2015年会计个人工作总结
2015/04/02 职场文书
尼克胡哲观后感
2015/06/08 职场文书
中学教师读书笔记
2015/07/01 职场文书
初中地理教学反思
2016/02/19 职场文书
用Python将GIF动图分解成多张静态图片
2021/06/11 Python
教你使用Ubuntu搭建DNS服务器
2022/09/23 Servers