1、自建yum仓库,分别为网络源和本地源
所有Yum仓库的配置文件均需以 .repo 结尾并存放在/etc/yum.repos.d/目录中的
[rhel-media] : yum仓库唯一标识符,避免与其他仓库冲突。
name=linuxprobe : yum仓库的名称描述,易于识别仓库用处。
baseurl=file:///media/cdrom :提供方式包括FTP(ftp://..)、HTTP(http://..)、本地(file:///..)
enabled=1 : 设置此源是否可用,1为可用,0为禁用。
gpgcheck=1 : 设置此源是否校验文件,1为校验,0为不校验。
gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release :若为校验请指定公钥文件地址。
配置本地源:
[root@localhost yum.repos.d]# vi CentOS-Media.repo
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[Test-repo]
name=Test-$releasever
baseurl=file:///yum/repo/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
Test-repo Test-7 138
base-source CentOS-7 - Base Sources 3,971
c7-media CentOS-7 - Media 3,971
repolist: 8,080
配置网络源:
[epel]
name=aliyun epel
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
编译安装httpd2.4
# tar xf httpd-2.4.9.tar.bz2
以下为几个主要的配置项
--sysconfdir=/etc/httpd24 指定配置文件路径
--enable-so 启动模块动态装卸载
--enable-ssl 编译ssl模块
--enable-cgi 支持cgi机制(能够让静态web服务器能够解析动态请求的一个协议)
--enable-rewrite 支持url重写
--with-zlib 支持数据包压缩
--with-pcre 支持正则表达式
--with-apr=/usr/local/apr 指明依赖的apr所在目录
--with-apr-util=/usr/local/apr-util/ 指明依赖的apr-util所在的目录
--enable-modules=most 启用的模块
--enable-mpms-shared=all 以共享方式编译的模块
--with-mpm=prefork 指明httpd的工作方式为prefork
# cd httpd-2.4.9
# ./configure \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-mpm=prefork \
--enable-modules=most \
--enable-mpms-shared=all
# make
# make install
配置http2.4启动及停止
1、修改端口号
修改端口号使得与2.2版本使用不同的端口,可以同时运行,修改后如下
# cat /etc/httpd24/httpd.conf |grep Listen |grep -v ^#
Listen 8080
2、启动与停止
# /usr/local/apache/bin/apachectl start
# netstat -nltp|grep 80
tcp 0 0 :::8080 :::* LISTEN 17365/httpd
# /usr/local/apache/bin/apachectl status
Not Found
The requested URL /server-status was not found on this server.
通过修改httpd.conf,增加如下配置
# grep server-stat /etc/httpd24/httpd.conf -A5
<Location /server-status>
SetHandler server-status
# Order deny,allow
# Deny from all
Allow from 192.168.21.157 192.168.21.10
</Location>
# /usr/local/apache/bin/apachectl restart
# /usr/local/apache/bin/apachectl status
Apache Server Status for localhost (via 127.0.0.1)
Server Version: Apache/2.4.9 (Unix)
Server MPM: prefork
..........
# /usr/local/apache/bin/apachectl stop
3、配置自启动文件
可以通过复制2.2版本的启动文件,修改相关路径后将2.4版作为单独服务运行,如下
注启动文件pid文件位置要配置成与/usr/local/apache/bin/apachectl -V看到的pid位置一致
查看pid位置
# /usr/local/apache/bin/apachectl -V|grep pid
-D DEFAULT_PIDLOG="logs/httpd.pid"
# cp /etc/init.d/httpd /etc/init.d/httpd24
# vi /etc/init.d/httpd24
# diff /etc/init.d/httpd /etc/init.d/httpd24
26,27c26,27
< if [ -f /etc/sysconfig/httpd ]; then
< . /etc/sysconfig/httpd
---
> if [ -f /etc/httpd24 ]; then
> . /etc/httpd24
42,46c42,46
< apachectl=/usr/sbin/apachectl
< httpd=${HTTPD-/usr/sbin/httpd}
< prog=httpd
< pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
< lockfile=${LOCKFILE-/var/lock/subsys/httpd}
---
> apachectl=/usr/local/apache/bin/apachectl
> httpd=${HTTPD-/usr/local/apache/bin/httpd}
> prog=httpd24
> pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
> lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
# service httpd24 start
Starting httpd24: [ OK ]
# service httpd24 status
httpd (pid 15641) is running...
# netstat -nltp|grep 80
tcp 0 0 :::80 :::* LISTEN 15677/httpd ###2.2版httpd
tcp 0 0 :::8080 :::* LISTEN 15641/httpd ###2.4版httpd
可以通过复制apachectl文件生成服务脚本
# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd249
# service httpd249 start
# service httpd249 status
ELinks: Connection refused ###该方式无法查看到状态
[root@orasrv1 bin]# netstat -nltp|grep 80
tcp 0 0 :::8080 :::* LISTEN 15999/httpd
最后将配置文件添加到服务,以下为http24为例
# chkconfig --add httpd24
# chkconfig httpd24 on
验证:
# echo "This is a apached 2.4.9 version">>/usr/local/apache/htdocs/index.html
# curl http://192.168.21.10:8080
<html><body><h1>It works!</h1></body></html>