设为首页 加入收藏

TOP

源码安装apache脚本部署(一)
2023-07-23 13:33:24 】 浏览:47
Tags:安装 apache

源码安装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
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇NGINX 实现https自签名证书加密以.. 下一篇VMware虚拟机centOS7下配置桥接网..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目