源码包编译安装Apache搭建虚拟Web主机

安装Apache源码包[h源码包编译安装Apache搭建虚拟Web主机

安装Apache源码包[httpd-2.2.25.tar.gz]根据源码包安装四步骤,先安装gcc工具

挂载光盘安装gcc

1.挂载光盘配置yum库

[root@localhost ~]# cd /misc/cd/Server/

You have new mail in /var/spool/mail/root

[root@localhost Server]# cd /etc/yum.repos.d/

You have new mail in /var/spool/mail/root

[root@localhost yum.repos.d]# ls

rhel-debuginfo.repo

[root@localhost yum.repos.d]# cp rhel-debuginfo.repo rhel-server.repo

[root@localhost yum.repos.d]# ls

rhel-debuginfo.repo  rhel-server.repo

[root@localhost yum.repos.d]# vim rhel-server.repo

[rhel-server]

name=Red Hat Enterprise Linux S

baseurl=file:///misc/cd/Server/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[root@localhost yum.repos.d]# yum -y install gcc*    //安装源码包需要安装gcc

[root@localhost yum.repos.d]# yum clean all

Loaded plugins: product-id, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Cleaning up Everything

[root@localhost yum.repos.d]# yum list | wc -l               //yum库安装完毕

3347

[root@localhost ~]# ls Desktop///VMware-tools工具拖拽到桌面或挂载到指定的路径

httpd-2.2.25.tar.gz

[root@localhost ~]# tar -zxf Desktop/httpd-2.2.25.tar.gz -C /usr/local/

[root@localhost ~]# cd /usr/local/

[root@localhost local]# ls

awstats  etc    httpd-2.2.25  lib    libexec  share

bin      games  include       lib64  sbin     src

[root@localhost local]# cd httpd-2.2.25/

You have new mail in /var/spool/mail/root

2.源码包安装

[root@localhost httpd-2.2.25]# ./configure              //进入软件包执行安装第一步

config.status: creating support/split-logfile

config.status: creating build/rules.mk

config.status: creating build/pkg/pkginfo

config.status: creating build/config_vars.sh

config.status: creating include/ap_config_auto.h

config.status: executing default commands

[root@localhost httpd-2.2.25]# echo $?     //测试上一步是否安装成功,如果是0就是对的

0

[root@localhost httpd-2.2.25]# make        //执行编译

libmod_negotiation.la modules/mappers/libmod_dir.la modules/mappers/libmod_actions.la modules/mappers/libmod_userdir.la modules/mappers/libmod_alias.la modules/mappers/libmod_so.la server/mpm/prefork/libprefork.la os/unix/libos.la -lm /usr/local/httpd-2.2.25/srclib/pcre/libpcre.la /usr/local/httpd-2.2.25/srclib/apr-util/libaprutil-1.la /usr/local/httpd-2.2.25/srclib/apr-util/xml/expat/libexpat.la /usr/local/httpd-2.2.25/srclib/apr/libapr-1.la -lrt -lcrypt -lpthread -ldl

make[1]: Leaving directory `/usr/local/httpd-2.2.25'

[root@localhost httpd-2.2.25]# echo $?

0

[root@localhost httpd-2.2.25]# make install     //执行make install将相关文件部署到系统

mkdir /usr/local/apache2/man

mkdir /usr/local/apache2/man/man1

mkdir /usr/local/apache2/man/man8

mkdir /usr/local/apache2/manual

make[1]: Leaving directory `/usr/local/httpd-2.2.25'

You have new mail in /var/spool/mail/root

[root@localhost httpd-2.2.25]# echo $?

0

[root@localhost httpd-2.2.25]# ls

ABOUT_APACHE   configure       libhttpd.dep   os

acinclude.m4   configure.in    libhttpd.dsp   README

Apache.dsw     docs            libhttpd.mak   README.platforms

build          emacs-style     LICENSE        README-win32.txt

BuildAll.dsp   httpd          【Makefile】    ROADMAP

BuildBin.dsp   httpd.dep       Makefile.in    server

buildconf      httpd.dsp       Makefile.win   srclib

buildmark.o    httpd.mak       modules        support

CHANGES        httpd.spec      modules.c      test

config.layout  include         modules.lo     VERSIONING

config.log     INSTALL         modules.o

config.nice    InstallBin.dsp  NOTICE

config.status  LAYOUT          NWGNUmakefile

[root@localhost local]# cd apache2/bin/

[root@localhost bin]# ls

ab         apr-1-config  apxs      dbmmanage  envvars-std   htdbm     htpasswd  httxt2dbm   rotatelogs

apachectl  apu-1-config  checkgid  envvars    htcacheclean  htdigest  httpd     logresolve

[root@localhost bin]# pwd

/usr/local/apache2/bin

[root@localhost bin]# /usr/local/apache2/bin/apachectl start    //用绝对路径执行apachect1启动

3.源码包安装成功,开始搭建DNS服务器:

安装bind bind-chroot caching-nameserver软件:

[root@localhost ~]#cd /misc/cd/Server/

[root@localhost Server]#rpm -ivh bind-9.3.6-20.P1.el5_8.5.x86_64.rpm bind-chroot-9.3.6-20.P1.el5_8.5.x86_64.rpm caching-nameserver-9.3.6-20.P1.el5_8.5.x86_64.rpm

[root@localhost Server]# rpm -q bind bind-chroot caching-nameserver

bind-9.3.6-20.P1.el5_8.5

bind-chroot-9.3.6-20.P1.el5_8.5

caching-nameserver-9.3.6-20.P1.el5_8.5

[root@localhost Server]# [root@localhost ~]# cd /var/named/chroot/etc/

You have new mail in /var/spool/mail/root

[root@localhost etc]# ls

localtime                      rndc.key

named.caching-nameserver.conf  named.rfc1912.zones

[root@localhost etc]#cp -p named.caching-nameserver.conf named.conf

[root@localhost etc]# vim named.conf

// caching-nameserver package upgrade.

//

options {

       listen-on port 53 { 192.168.10.90; };     //本机ip地址

       directory       "/var/named";

       dump-file       "/var/named/data/cache_dump.db";

       statistics-file "/var/named/data/named_stats.txt";

       memstatistics-file "/var/named/data/named_mem_stats.txt";

       allow-query     { any; };

       allow-query-cache { any; };

};

logging {

       channel default_debug {

               file "data/named.run";

               severity dynamic;

       };

};

view localhost_resolver {

       match-clients      { any; };

       match-destinations { any; };

       recursion yes;

       include "/etc/named.rfc1912.zones";

};

:%s/localhost/any/gc

[root@localhost etc]# vim named.rfc1912.zones

//一般搭建DNS服务器只需配置正向解析:

zone "tarena.com" IN {

       type master;

       file "tarena.com.zone";

       masters { 192.168.10.1; };

};

[root@localhost etc]# named-checkconf named.conf named.rfc1912.zones

[root@localhost etc]# cd ../var/named/

data              named.broadcast  named.local

localdomain.zone  named.ca         named.zero

localhost.zone    named.ip6.local  slaves

[root@localhost named]# cp -p named.local tarena.com.zone

[root@localhost named]# vim tarena.com.zone

$TTL    86400

@       IN      SOA     tarena.com. root.tarena.com.  (

                                     2014030701 ; Serial

                                     28800      ; Refresh

                                     14400      ; Retry

                                     3600000    ; Expire

                                     86400 )    ; Minimum

       IN      NS     dns1.tarena.com.

dns1    IN      A       192.168.10.1

www     IN      A       192.168.10.1

bbs     IN      A       192.168.10.1

~                                                                              

~                                                  

[root@localhost named]# named-checkzone tarena.com tarena.com.zone

zone tarena.com/IN: loaded serial 2014030701

OK

[root@localhost named]# service named restart

停止 named:                                               [确定]

启动 named:                                               [确定]

[root@localhost named]# nslookup www.tarena.com

Server:         192.168.10.1

Address:        192.168.10.1#53

Name:   www.tarena.com

Address: 192.168.10.1

[root@localhost named]# nslookup bbs.tarena.com

Server:         192.168.10.1

Address:        192.168.10.1#53

Name:   bbs.tarena.com

Address: 192.168.10.1

[root@localhost ~]# mkdir -p /data/wed/{www,bbs}   //创建一个html程序目录

[root@localhost ~]# cd /data/web/

[root@localhost web]# ls

bbs  www

[root@localhost web]# vim www/index.html    //写入一个html程序

<h1>www.tarena.com</h1>

[root@localhost web]# vim bbs/index.html

<h1>bbs.tarena.com</h1>

[root@localhost ~]# cd /usr/local/apache2/conf

[root@localhost conf]# ls

extra  httpd.conf  magic  mime.types  original

[root@localhost conf]# pwd

/usr/local/apache2/conf

[root@localhost conf]# cd extra/

[root@localhost extra]# ls

httpd-autoindex.conf  httpd-languages.conf           httpd-ssl.conf

httpd-dav.conf        httpd-manual.conf              httpd-userdir.conf

httpd-default.conf    httpd-mpm.conf                 httpd-vhosts.conf

httpd-info.conf       httpd-multilang-errordoc.conf

[root@localhost extra]# vim httpd-vhosts.conf     //进入虚拟主机配置文件

NameVirtualHost *:80

<VirtualHost *:80>

   DocumentRoot "/data/web/www"

   ServerName www.tarena.com

   ErrorLog "logs/dummy-www.tarena.com-error_log"

   CustomLog "logs/dummy-www.tarena.com-access_log" common

</VirtualHost>

<VirtualHost *:80>

   DocumentRoot "/data/web/bbs"     //网站的根路径

   ServerName bbs.tarena.com        //网站名称

   ErrorLog "logs/dummy-bbs.tarena.com-error_log"  //网站错误日志路径

   CustomLog "logs/dummy-bbs.tarena.com-access_log" common

</VirtualHost>

[root@localhost extra]# cd ../

[root@localhost conf]# ls

extra  httpd.conf  magic  mime.types  original

[root@localhost conf]# pwd

/usr/local/apache2/conf

[root@localhost conf]# vim httpd.conf    //http主配置文件

.

.

114 #

115 <Directory />

116     Options FollowSymLinks

117     AllowOverride None

118     Order deny,allow

119     Allow from all

120 </Directory>

121

.

.

163 # DirectoryIndex: sets the file that Apache will serve if a directory

164 # is requested.

165 #

166 <IfModule dir_module>

167     DirectoryIndex index.html

168 </IfModule>

395 # Virtual hosts

396 Include conf/extra/httpd-vhosts.conf//删除前面#

[root@localhost conf]#/usr/local/apache2/bin/apachectl stop

[root@localhost conf]#/usr/local/apache2/bin/apachectl start

cp /usr/local/apache2/bin/apachect1 /etc/init.d/

cd /etc/init.d/

mv apachect1 apache

head -n 5 apache




你可能感兴趣的