本帖最后由 32ijhgf 于 2016-8-25 09:34 编辑
httpd的简介 httpd是一个开源软件,且一般用作web服务器来使用。目前最流行的web服务器软件叫做httpd,httpd还有一个俗称叫apache,Apache是一个软件基金会,httpd也是这个软件基金会的一个项目。在早期的http server就叫做apache,到了http server 2.0以后就改名为httpd了。所以有时候听到apache服务器和httpd服务器其实都是指得是一个意思。 源码安装httpd服务 下面来一起探讨下源码包编译安装过程,对此我分为以下几部分介绍 1、 使用软硬件介绍
2、 安装编译环境 3、 下载解压源码包 4、 安装apache 5、 测试apache 6、 查看apache安装生成的目录 7、 查看apache的配置文件 8、 apache加入系统启动项 一、使用的软硬件环境简单介绍 1.笔记本电脑
2.vmware虚拟机软件 3.CentOS7.2虚拟机(最小化安装) 5.httpd版本:httpd-2.2.29.tar.bz2 二、安装编译环境 由于在httpd源码编译过程中需要使用gcc、gcc-c++编译器,故需要先对其进行安装,另外因为使用的是教室内网络,所以需要对yum源进行重新配置 1.yum源配置:在/etc/yum.repos.d下创建目录old,把其它的.repo结尾的文件移动到old目录,重新创建base.repo,加入一下内容,先执行yum clean all,清除yum缓存,再执行
yum makecache创建新的yum缓存。
1
2
3
4
5
6
7
8
9
10
11
12
13
| [base]
name=CentOS 7
baseurl=http://10.1.0.1/cobbler/ks_mirror/7/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
[fedora]
name=CentOS
baseurl=http://10.1.0.1/fedora-epel/7/x86_64/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
|
2.安装所需要的编译器,或者是直接安装开发套件
yum install -y gcc gcc-c++ || yum groupinstall -y "Development tools" 3.最小化安装下,没有bzip2这个工具,所以需要对其进行安装才能对源码包解压
yum install -y bzip2 4.我的环境上基本上装完这些就能够顺利安装了,但是由于各人安装系统时选择安装的包组不同,可能会有一些其它依赖的包
这就需要真对相应的情况做出调整。有些需要先对原来系统上带的httpd服务进行卸载,直接使用:yum remove httpd即可
由于我最小化安装没有这个软件,故不需要卸载喽。
三、 下载解压源码包 1.使用lftp 10.1.0.1登陆ftp服务器,这里又要对lftp作下说明,lftp原本系统中没有,需自行安装,当然还是老一套:yum install -y lftp 进入ftp的对应目录,其中有几个httpd的源码包,这里我选择的是 :httpd-2.2.29.tar.bz2,下载完成后对其进行解压
四、安装httpd 1. 安装httpd,我们首先要编译,然后进行安装。
apache服务有很多参数和功能,这里就不一一说明,仅对我编译过程中使用到的参数进行简单说明 --prefix=PREFIX install architecture-independent files in PREFIX //设备安装目录选项 --mandir=DIR man documentation [DATAROOTDIR/man] //man帮助文档路径 --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] //发行时带的一些其它文档存放路径 --sysconfdir=/etc/apache2 //配置信息的存放路径
使用echo $? 查看编译是否成功,如上图中显示,结果0,这么顺利就编译完成了。愉快的进入安装喽
2.安装完成之后把/usr/local/apache2/bin加入PATH环境变量: 在/etc/profile.d下创建path.sh,写入
PATH=$PATH:/usr/local/apache2/bin 然后source /etc/profile
五、启动和测试 在服务器中执行apachectl start启动服务,然后在另外一台机器上执行links iP 测试服务状态。如果有访问受限,需要启动服务器的机器关闭防火墙重新测试。
六、加入系统启动列表 1.拷贝apache2/bin下的apachectl 到/etc/rc.d/init.d/httpd cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd 2.在其中加入第一行后加入启动和关闭顺序 sed -ir "1a \#chkconfig: 2345 10 90\n#description\: Activates/Deactivates Apache Web Server" /etc/rc.d/init.d/httpd &>>/tmp/apache2.log 3.把服务加入启动列表 chkconfig --add httpd 4.设置开机默认启动 chkconfig httpd on 5.经过重启后在此测试依然可用,说明配置以经成功 七、自动安装脚本说明 根据现有环境及配置需求简单整理了自动从通过lftp下载、解压、安装及加入服务项的简单脚本。供个人复习使用。贴于附件,脚本很烂,慎重查看
#!/bin/bash
#
cd /usr/local/src
#如果/usr/local/src目录下没有有源,就从ftp下载,如果有进入下一步
if [ ! -e httpd-2.2.29.tar.bz2 ] ;then
echo "begin to get package from lftp"
lftp 10.1.0.1 <<EOF
cd /pub/Sources/sources/httpd/
mget httpd-2.2.29.tar.bz2
bye
EOF
if [ $? -ne 0 ] ;then
echo "get httpd-2.2.29.tar.bz2 fail"
exit 6
fi
echo "package get sucessfully"
else
echo "httpd-2.2.29.tar.bz2 is already exist"
fi
echo ====================
#检查解压后的httpd-2.2.29文件夹是否存在,不存在解压,存在继续下一步
if [ ! -e httpd-2.2.29 ] ;then
echo > /tmp/apache2.log
tar -xjvf httpd-2.2.29.tar.bz2 &>> /tmp/apache2.log
#判断解压过程是否出错
if [ $? -ne 0 ];then
echo "tar error"
exit 8
fi
echo "httpd-2.2.29 is uncompress ok"
else
echo "httpd-2.2.29 is exist"
fi
cd httpd-2.2.29
echo "begin to ./configure"
#开始编译安装
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/apache2 --mandir=/usr/local/share/man --docdir=/usr/local/share/docs &>> /tmp/apache2.log
#确定编译是否出错
if [ $? -ne 0 ];then
echo "./configure error"
exit 10
else
echo "./configure sucessfully and begin to make"
#开始执行make并判断直接结果的返回值
make &>> /tmp/apache2.log
if [ $? -eq 1 ];then
echo "make error"
exit 11
else
echo "make sucessfully and begin to make install"
#执行make install ,
make install &>> /tmp/apache2.log
if [ $? -eq 1 ];then
exit 12
else
echo "OK make install sucess"
fi
fi
fi
#配置/usr/local/apache2/bin到环境变量中
echo "PATH=$PATH:/usr/local/apache2/bin" >> /root/.bashrc
source /root/.bashrc
#启动服务
apachectl start &>> /tmp/apache2.log
[ -e /etc/rc.d/init.d/httpd ] && rm -rf /etc/rc.d/init.d/httpd
cd /usr/local/apache2/bin
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
#添加启动顺序
sed -ir "1a \#chkconfig: 2345 10 90\n#description\: Activates/Deactivates Apache Web Server" /etc/rc.d/init.d/httpd &>>/tmp/apache2.log
#加入启动列表
chkconfig --add httpd
#设置开机默认启动
chkconfig httpd on
|