软件包管理-编译安装HTTPD

本文介绍了如何在Linux系统中手动编译和安装HTTPD服务,包括关闭防火墙和SELinux,安装开发工具,运行configure脚本,使用make和make install命令,以及配置安装路径和启用服务的过程。同时,提到了一键安装脚本的创建和使用。
摘要由CSDN通过智能技术生成

编译和安装

稍微复杂一些的程序和服务都是提供源码
这样就就不能通过rpm和yum来安装软件
必须自己编译和安装程序

make项目管理器

  • c、c++
  • configure脚本 --> Makefile.in --> makefile
  1. ./configure 执行脚本

1.1. 可以传递参数,指定其中特性、安装路径等;执行时会参考用户的指定以及Makefile.in文件生成Makefile
1.2. 检查依赖到的外部环境,如依赖的软件包

  1. make 根据Makefile文件,构建应用程序
  2. make install 复制文件到相应路径

maven

  • java

前提工作

  • 关闭防火墙

centos6: service iptables stop; chkconfig iptables off
centos7: systemctl stop firewalld; systemctl disable firewalld

  • 关闭SELinux

setenforce 0
vim /etc/selinux/config SELINUX=disable

  • 安装相应的包和包组,如一般需要安装开发包yum groupinstall “Development tools”

编译

下载源码至服务器上,解包后查看目录
目录中可看到configure脚本、Makefile.in
帮助文档README和安装说明INSTALL

[root@centos7 httpd-2.2.34]#ls
ABOUT_APACHE  BuildAll.dsp  config.layout  emacs-style  httpd.spec      LAYOUT        LICENSE       NOTICE         README.platforms  srclib
acinclude.m4  BuildBin.dsp  configure      httpd.dep    include         libhttpd.dep  Makefile.in   NWGNUmakefile  README-win32.txt  support
Apache.dsw    buildconf     configure.in   httpd.dsp    INSTALL         libhttpd.dsp  Makefile.win  os             ROADMAP           test
build         CHANGES       docs           httpd.mak    InstallBin.dsp  libhttpd.mak  modules       README         server            VERSIONING

运行脚本

./configure --help #查看帮助
./configure \ #运行脚本
–prefix=/app \ #设置默认安装路径
–sysconfdir=/etc/httpd222 \ #把配置文件单独设置目录
–enable-ssl \ #开启SSL服务
如果缺包会检测不成功,打包完之后继续运行直到$?=0

[root@centos7 httpd-2.2.34]#./configure --prefix=/app --sysconfdir=/etc/httpd222 --enable-ssl

make

-j 2 使用两个CPU来运行
echo -e “\a” 发出一声响声

[root@centos7 httpd-2.2.34]#make -j 2 && echo -e "\a";sleep 1;echo -e "\a";sleep 1;echo -e "\a";sleep 1;echo -e "\a"

make install

[root@centos7 app]#ls
bin  build  cgi-bin  error  htdocs  icons  include  lib  logs  man  manual  modules
[root@centos7 app]#cd /etc/httpd222/
[root@centos7 httpd222]#ls
extra  httpd.conf  magic  mime.types  original
[root@centos7 httpd222]#

启用服务

把/app/bin加入PATH变量,然后直接启动http服务
有报错,但是80服务起来了,去浏览器验证
安装目录中ntdocs,存放web站点

[root@centos6 httpd-2.2.34]$apachectl start
httpd: apr_sockaddr_info_get() failed for centos6.localdomain
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@centos6 httpd-2.2.34]$ss -ntl
State      Recv-Q Send-Q               Local Address:Port                 Peer Address:Port 
LISTEN     0      128                             :::44230                          :::*     
LISTEN     0      128                              *:47495                           *:*     
LISTEN     0      128                             :::111                            :::*     
LISTEN     0      128                              *:111                             *:*     
LISTEN     0      128                             :::80                             :::*     
LISTEN     0      128                             :::22                             :::*     
LISTEN     0      128                              *:22                              *:*     
LISTEN     0      128                      127.0.0.1:631                             *:*     
LISTEN     0      128                            ::1:631                            :::*     
LISTEN     0      100                            ::1:25                             :::*     
LISTEN     0      100                      127.0.0.1:25                              *:*     
[root@centos6 httpd-2.2.34]$

作业:
1 一键安装脚本centos6 编译安装httpd2.2.34,centos7 编译安装httpd2.4.25

在本机远程执行install.sh
curl http://testsrv/install.sh |bash

一键安装或卸载httpd2.4
install remove

remove 是删除安装目录 和源码包

# 1.  关闭httpd服务

echo "Remove httpd starting "
echo "stopping httpd"

apachectl stop &> /dev/null


# 2. 删除安装目录 /app

echo "deleting  httpd dir."
rm -rf /app &> /dev/null


# 3. 删除源码和PATH变量
echo "deleting  httpd source file."

find / -regex ".*httpd-2.4.27.*" |sed -r 's@(.*/httpd-2.4.27)/.*@\1@' | uniq |xargx rm -rf &> null

echo "deleting httpd path file"
rm -rf /etc/profile.d/httpdpath.sh &>/dev/null

echo "httpd has removed."

install

# 1. 配置YUM
rm -rf /etc/yum.repos.d/*
cat >/etc/yum.repos.d/base.repo <<EOF
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpcheck=0

[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/x86_64/
enabled=1
gpcheck=0

EOF



yum clean all &> /dev/null
yum list  &> /dev/null
yum makecache  &> /dev/null


# 2. 安装包

yum -y groupinstall "Development tools" &> /dev/null
yum -y install apr-devel   &> /dev/null
yum -y install apr-util-devel &> /dev/null


# 3. 获取httpd
echo "Getting the httpd.tar form network,please wait."
wget http://archive.apache.org/dist/httpd/httpd-2.4.27.tar.gz &>/dev/null
tar -zxvf httpd-2.4.27.tar.gz &> /dev/null
cd httpd-2.4.27

# 编译安装

echo "Begin install httpd server,please wait."
./configure --prefix=/app &> /dev/null && make &>/dev/null && make isntall &> /dev/null

echo "httpd service has been finished."
echo "httpd service is starting "

cat >/etc/profile.d/httpdpath.sh<<EOF
PATH=/app/bin:$PATH

EOF
PATH=/app/bin:$PATH

apachectl start &> /dev/null

echo "Apache httpd service is working!"






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值