跳至主要內容

CentOS7无网络情况下安装httpd


背景介绍

本故事发生在 2017年12月14号的笔记记录,系统环境大概是CentOS 7,但是系统是线上环境,没有互联网,安装软件繁琐。

当时需要用httpd2 来搭建一个简单的web服务器,但是系统没有安装httpd2,要求版本是 httpd2.4.29

当然现在通用的选择是 Nginx,所以本记录只对那些特殊情况下,特殊要求才适用。

操作记录

# 卸载系统原有的httpd
rpm -qa|grep httpd
rpm -e --nodeps httpd-2.2.15-29.el6_4.x86_64
rpm -e --nodeps httpd-tools-2.2.15-29.el6_4.x86_64
############################################################################
# 安装gcc,系统有跳过
yum -y install gcc gcc-c++ libstdc++-devel
gcc -v
# gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
############################################################################
cd /data/tools/httpd

ll
#解压: 这些包都要提前下好
tar -zxvf apr-1.6.3.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
tar -zxvf pcre-8.41.tar.gz
tar -zxvf httpd-2.4.29.tar.gz
######################################
mkdir /local/httpd
mkdir /local/apr
mkdir /local/apr-util
mkdir /local/pcre

cd apr-1.6.3
./configure --prefix=/local/apr
make
make install
###############################
yum install expat-devel
###############################
cd ../apr-util-1.6.1
./configure --prefix=/local/apr-util --with-apr=/local/apr/bin/apr-1-config
make
make install
###############################
cd ../pcre-8.41/
./configure --prefix=/local/pcre --with-apr=/local/apr/bin/apr-1-config
make
make install
###############################
cd ../httpd-2.4.29/
./configure --prefix=/local/httpd --with-pcre=/local/pcre --with-apr=/local/apr --with-apr-util=/local/apr-util
make
make install
############################################################################
cp /local/httpd/bin/apachectl /etc/init.d/httpd
############################################################################

service httpd start

项目(主要)配置

项目1配置

/etc/httpd/conf/httpd.conf

Listen 80
Listen 8080

ServerName 172.xx.xxx.xx

<Directory />
    AllowOverride none
    Require all denied
</Directory>


<Proxy balancer://inproxy>
    BalancerMember ajp://172.xxx.xxx.xx0:8009 loadfactor=1 route=jvmRoute1
    BalancerMember ajp://172.xxx.xxx.xx1:8009 loadfactor=1 route=jvmRoute2
	ProxySet stickysession=ROUTEID1
</Proxy>

 
<Proxy balancer://outproxy>
    BalancerMember ajp://172.xxx.xxx.xx0:8009 loadfactor=1 route=jvmRoute3
    BalancerMember ajp://172.xxx.xxx.xx1:8009 loadfactor=1 route=jvmRoute4
	ProxySet stickysession=ROUTEID2
</Proxy>

项目2配置

/etc/httpd/conf.d/httpd_vhosts.conf

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/local/httpd/docs/default"
    ServerName xxx.xxx.xx0
    ServerAlias in
    ErrorLog "logs/inproxy-error_log"
    CustomLog "logs/inproxy-access_log" common
	
	Header add Set-Cookie "ROUTEID1=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
	ProxyPass /  balancer://inproxy/ stickysession=ROUTEID1 nofailover=On timeout=5 maxattempts=3
	ProxyPassReverse / balancer://inproxy/ 
</VirtualHost>

<VirtualHost *:8080>
   ServerAdmin [email protected]
    DocumentRoot "/local/httpd/docs/default"
    ServerName xxx.xxx.xx1
    ServerAlias out
    ErrorLog "logs/outproxy-error_log"
    CustomLog "logs/outproxy-access_log" common
	
	Header add Set-Cookie "ROUTEID2=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
	ProxyPass /  balancer://outproxy/ stickysession=ROUTEID2 nofailover=On timeout=1500 maxattempts=3
	ProxyPassReverse / balancer://outproxy/ 
</VirtualHost>

项目3配置

/etc/httpd/conf.d/project_other.conf

Listen 80
Listen 81

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

NameVirtualHost *:81
<VirtualHost *:81> 
DocumentRoot /var/www/manage
ServerName localhost:81
</VirtualHost>

NameVirtualHost *:80
<VirtualHost *:80> 
DocumentRoot /var/www/contract
ServerName localhost:80
</VirtualHost>


IncludeOptional conf.d/*.conf

有网络情况安装

yum list httpd
yum install httpd.x86_64

service httpd start

增加服务,开机自动运行

# 服务所在位置
ll /etc/init.d/

# 增加httpd服务
chkconfig --add httpd
# 设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
chkconfig --level 2345 httpd  on 
chkconfig --list httpd
上次编辑于:
贡献者: lizhiquan