zoukankan      html  css  js  c++  java
  • 利用shell脚本实现安装httpd服务

    shell脚本安装httpd服务

    注意!

    网速要贼快!!!!

    网速不行的,不推荐使用本脚本!!!!

    脚本中配置了redhat8的网络源!!!!

    步骤如下

    1. 创建一个目录用于存放install.sh脚本
    2. 给脚本执行权限
    3. 运行脚本
    4. 手动启动httpd
    5. 自定义配置

    脚本内容

    #!/bin/bash
    
    #定义变量
    apr_version=1.7.0 
    apr_util_version=1.6.1 
    httpd_version=2.4.46
      
            echo "安装httpd服务"
    
    #配置yum网络源
            echo "正在配置yum网络源..."
            /usr/bin/curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
            /usr/bin/sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
            /usr/bin/sed -i 's|$releasever|8|' /etc/yum.repos.d/CentOS-Base.repo
            yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
            /usr/bin/sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
            /usr/bin/sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
            /usr/bin/sed -i 's|$releasever|8|' /etc/yum.repos.d/epel*
            echo "正在清理缓存,请稍等..."
            yum clean all && yum makecache &> /dev/null
    #检查wget命令
            echo "正在检查是否安装wegt命令..."
    which wget &> /dev/null
    if [[ $? -eq 0 ]];then
       echo "您已安装"
       else
    	echo "您未安装,正在安装wget..."
            yum -y install wget
    fi
    #安装需要的工具包
            echo "正在安装需要的工具包,请稍等..."
            yum -y install bzip2  vim make wget openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel
    	echo "安装完成"
    
    #下载apr包,并解压安装
            echo "正在下载apr源码包,请耐心等待..."
    ls /usr/src/apr-${apr_version} &> /dev/null
    if [[ $? -eq 0 ]];then
    	rm -rf /usr/src/apr-${apr_version}.tar.gz &> /dev/null
    	rm -rf /usr/src/apr-${apr_version} &> /dev/null	
    	rm -rf /usr/local/apr/ &> /dev/null
    	cd /usr/src/
    	wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-${apr_version}.tar.gz
    	echo "下载成功,正在解压apr..."
    	tar xf apr-${apr_version}.tar.gz
    	cd /usr/src/apr-${apr_version}
    	sed -i '/$RM "$cfgfile"/d' configure
    	echo "正在编译安装apr,请耐心等待..."
    	./configure --prefix=/usr/local/apr &> /dev/null
           	make &> /dev/null
           	make install &> /dev/null
    	cd
    	echo "apr安装完成"
    else
    	rm -rf /usr/src/apr-${apr_version}.tar.gz &> /dev/null
            rm -rf /usr/src/apr-${apr_version} &> /dev/null
    	rm -rf /usr/local/apr/ &> /dev/null
    	cd /usr/src/    
    	wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-${apr_version}.tar.gz
    	echo "下载成功,正在解压apr..."
    	tar xf apr-${apr_version}.tar.gz
            cd /usr/src/apr-${apr_version}
            sed -i '/$RM "$cfgfile"/d' configure
            echo "正在编译安装apr,请耐心等待..."
    	./configure --prefix=/usr/local/apr &> /dev/null
    	make &> /dev/null
    	make install &> /dev/null
    	cd
    	echo "apr安装完成"
    fi
    
    #下载apr-util包,并解压安装
            echo "正在下载apr-util源码包,请耐心等待..."
    ls /usr/src/apr-util-${apr_util_version} &> /dev/null
    if [[ $? -eq 0 ]];then
    	rm -rf /usr/src/apr-util-${apr_util_version}.tar.gz &> /dev/null
    	rm -rf /usr/src/apr-util-${apr_util_version} &> /dev/null
    	rm -rf /usr/local/apr-util &> /dev/null
    	cd /usr/src/
    	wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-${apr_util_version}.tar.gz
    	echo "下载成功,正在解压apr-util..."
    	tar xf apr-util-${apr_util_version}.tar.gz
    	cd /usr/src/apr-util-${apr_util_version}
    	echo "正在编译安装apr-util,请耐心等待..."
    	./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &> /dev/null
    	make &> /dev/null
           	make install &> /dev/null
    	cd
    	echo "apr-util安装完成"							
    else
    	rm -rf /usr/src/apr-util-${apr_util_version}.tar.gz &> /dev/null
            rm -rf /usr/src/apr-util-${apr_util_version} &> /dev/null
    	rm -rf /usr/local/apr-util &> /dev/null
    	cd /usr/src/
    	wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-${apr_util_version}.tar.gz
    	echo "下载成功,正在解压apr-util..."
    	tar xf apr-util-${apr_util_version}.tar.gz
    	cd /usr/src/apr-util-${apr_util_version}
    	echo "正在编译安装apr-util,请耐心等待..."
    	./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &> /dev/null
    	make &> /dev/null
           	make install &> /dev/null
    	cd
    	echo "apr-util安装完成"
    fi
    
    #下载httpd包,并解压安装
    echo "正在下载httpd源码包,请耐心等待..."
    ls /usr/src/httpd-${httpd_version} &> /dev/null
    if [[ $? -eq 0 ]];then
    	rm -rf /usr/src/httpd-${httpd_version}.tar.bz2 &> /dev/null
    	rm -rf /usr/src/httpd-${httpd_version} &> /dev/null
    	rm -rf /usr/src/apache &> /dev/null
    	cd /usr/src
    	wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-${httpd_version}.tar.bz2
    	echo "下载成功,正在解压httpd..."
    	tar xf httpd-${httpd_version}.tar.bz2
    	cd /usr/src/httpd-${httpd_version}
    	echo "正在编译安装httpd,请耐心等待..."
    	./configure --prefix=/usr/local/apache 
    		--sysconfdir=/etc/httpd24 
    		--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 &> /dev/null
    	make &> /dev/null
    	make install &> /dev/null
    	cd
    	echo "httpd安装完成"
    
    else
    	rm -rf /usr/src/httpd-${httpd_version}.tar.bz2 &> /dev/null
    	rm -rf /usr/src/httpd-${httpd_version} &> /dev/null
    	rm -rf /usr/src/apache &> /dev/null
    	cd /usr/src
    	wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-${httpd_version}.tar.bz2
    	echo "下载成功,正在解压httpd..."
    	tar xf httpd-${httpd_version}.tar.bz2
    	cd /usr/src/httpd-${httpd_version}
    	echo "正在编译安装httpd,请耐心等待..."
    	./configure --prefix=/usr/local/apache 
    		--sysconfdir=/etc/httpd24 
    		--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 &> /dev/null
    	make &> /dev/null
    	make install &> /dev/null
    	cd
    	echo "httpd安装完成"
    fi
    

    执行脚本

    [root@localhost ~]# chmod +x install.sh 
    [root@localhost ~]# ls
    anaconda-ks.cfg  install.sh
    
    #执行
    [root@localhost ~]# ./install.sh
    

    启动

    #因为是通用性配置所以要手动启动,忽略警告
    [root@localhost ~]# /usr/local/apache/bin/apachectl start
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
    [root@localhost ~]# ss -antl
    State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    
    LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*       
    LISTEN     0          128                  0.0.0.0:80                0.0.0.0:*       
    LISTEN     0          128                     [::]:22                   [::]:* 
    

    测试

    [root@localhost ~]# curl localhost
    <html><body><h1>It works!</h1></body></html>
    
  • 相关阅读:
    4408: [Fjoi 2016]神秘数
    UOJ #35. 后缀排序[后缀数组详细整理]
    POJ 2887 Big String
    搜索过滤grep(win下为findstr)
    解决putty自动断开的问题
    > >> 将错误输出到文件
    环境变量
    端口被占用,查看并杀死占用端口的进程
    查找文件路径find
    【vim使用】
  • 原文地址:https://www.cnblogs.com/leixixi/p/14611412.html
Copyright © 2011-2022 走看看