erw23312 发表于 2015-6-16 08:23:39

Apache服务【手工编译安装】


简介:
Apache HTTP Server 是开源软件项目的杰出代表,基于标准的HTTP网络协议提供网页浏览服务,在web服务器领域中长期保持着超过半数的份额。Apache服务器可以运行在Linux 、Unix、Windows等多种平台。

Apache的主要特点:
1.开放源代码
2.跨平台服务
3.支持各种网页编程语言
4.模块化设计
5.运行非常稳定
6.良好的安全性

环境:RHEL6.2、
一.Apache服务总览:
1.端口:80(http) https(443)
2.主配置文件(/etc/httpd/)
3.主页存放路径为/usr/local/apache/htdocs/index.html
准备工作:
关闭防火墙、SELinux,并能够和宿主机互联互通。


二、配置思路:
1.在宿主机创建文件夹,并把相关的压缩包放进去,进行共享;
2.使用tar进行解压缩;
3.将解压缩过的包,放入固定的目录中;
4.所需要的软件包:gcc 、 gcc-c++、 make、 、pcre-devel
5.使用手工编译安装;
6.修改主配置文件;

##关闭防火墙和SELinux,并测试与宿主机的连通性。
# service iptables stop
iptables:清除防火墙规则:                                 [确定]
iptables:将链设置为政策 ACCEPT:filter                  [确定]
iptables:正在卸载模块:                                 [确定]
# setenforce 0
# ping 192.168.100.111
PING 192.168.100.111 (192.168.100.111) 56(84) bytes of data.
64 bytes from 192.168.100.111: icmp_seq=1 ttl=64 time=0.167 ms
64 bytes from 192.168.100.111: icmp_seq=2 ttl=64 time=0.321 ms

##在宿主机的桌面上创建文件夹LAMP,右击属性-单击共享,输入everyone,单击添加,给予权限读取、写入


##右击属性,选择高级共享-权限-添加-输入everyone-检查名称-单击确定-给予完全控制权限,就OK 了


##运行secpol.msc,打开本地安装策略,用户权限分配-拒绝从网络访问这台计算机中-删除来宾用户。
##注:(在此之前要开启来宾用户)


##在安全选择中,网络访问中,选择仅来宾。以上步骤完成后,就可以在Linux上进行访问了,


# smbclient -L //192.168.100.111##在Linux上查看Windows所共享的文件目录/LAMP
Enter root's password:
session request to 192.168.100.111 failed (Called name not present)
Domain= OS= Server=

Sharename       Type      Comment
---------       ----      -------
123             Disk      
ADMIN$          Disk      远程管理
C$            Disk      默认共享
D$            Disk      默认共享
E$            Disk      默认共享
F$            Disk      默认共享
G$            Disk      默认共享
IPC$            IPC       远程 IPC
LAMP            Disk      

Users         Disk      
session request to 192.168.100.111 failed (Called name not present)
session request to 192 failed (Called name not present)
session request to *SMBSERVER failed (Called name not present)
NetBIOS over TCP disabled -- no workgroup available

##创建一个空目录名为lamp ,将Windows所共享的目录挂载到lamp目录中
# mkdir /lamp
# mount.cifs //192.168.100.111/LAMP /lamp
Password:
#

##切换到lamp目录下,可以看到安装Apache所必须的压缩包,
##注:(压缩包放在LAMP中一起共享出去的)
# cd /lamp/
# ls
apr-1.4.6.tar.gzapr-util-1.4.1.tar.gzhttpd-2.4.2.tar.gz

##使用命令tar进行解压缩,并指定解压后的路径为/opt下
# tar zxvf apr-1.4.6.tar.gz -C /opt
# tar zxvf httpd-2.4.2.tar.gz -C /opt
# tar zxvf apr-util-1.4.1.tar.gz -C /opt
# cd /opt
# ls
apr-1.4.6apr-util-1.4.1httpd-2.4.2

##将apr和apr-util以解压过后的文件拷贝到httpd-2.4.2/srclib/,在进行编译
# cp -R apr-1.4.6/ /opt/httpd-2.4.2/srclib/apr
# cp -R apr-util-1.4.1/ /opt/httpd-2.4.2/srclib/apr-util
#

##挂载光盘到mnt目录下,
# mount /dev/sr0 /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
##使用命令切换到yum.repo.d/下,编辑abc.repo ,
# cd /etc/yum.repos.d/
# vi abc.repo

name=test
baseurl=file:///mnt
enabled=1
gpgcheck=0

##完成后输入命令yum list,验证yum有没有安装成功,以下就是安装成功的模板,这字复制了一部分,仅供参考。
# yum list
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
abc                                                                      | 4.0 kB   00:00 ...
abc/primary_db                                                         | 3.1 MB   
00:00 ...

##在手工编译之前,首先要安装gcc gcc-c++ 环境,这里安装需要依赖性关系,所以使用yum 进行安装
# yum install gcc -y
# yum install gcc-c++ -y

##安装make包,系统一般都带你安装好的,可以是rpm 进行查看,如果没有进行安装,你懂得。
# rpm -q make
make-3.81-19.el6.x86_64
##安装pcre-devel包,这个包是根据系统的,比如系统是64位的,就安装64位的包
# rpm -ivh /mnt/Packages/pcre-devel-7.8-3.1.el6.x86_64.rpm
warning: /mnt/Packages/pcre-devel-7.8-3.1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ###########################################
   1:pcre-devel             ###########################################
#

##切换到opt下的http-2.4.2/,使用./configure 进行配置
# cd /opt/httpd-2.4.2/
# ./configure \
> --prefix=/usr/local/apache \##指定将httpd服务程序安装到那个目录,如/usr/local/apache;
> --enable-so \   ##启用动态加载模块支持,使httpd具备进一步扩展功能的能力;
> --enable-rewrite \##启用网页地址重写功能,用于网站优化及目录迁移维护;
> --enable-mods-shared=most \## 明确指明要以DSO方式编译的模块,<MODULE-LIST>为空格分隔的模块名列表、all或者most,all表示包含所有模块,most表示包含大部分模块;
> --with-mpm=worker \##先择Apache多路处理模块,<MPM>={beos|event|worker|prefork|mpmt_os2},prefork为Unix系统下默认处理模块,它将运行一个非线程型的、预派生的Web服务器,适合于没有线程安全库,需要避免线程兼容性问题的系统,它是要求将每个请求相互独立的情况下最好的MPM,这样若一个请求出现问题就不会影响到其他请求。
> --disable-cgid \
> --disable-cgi##启用CGI脚本程序支持,便于扩展网站的应用访问能力。

## 完成配置后,执行“make”进行编译,将源代码转换为可执行的程序;然后执行“make install”完成最后的安装过程。(其中make的过程可能需要较长的时间)
# make
# make install


## 这里请注意一下!如果Linux服务器上默认安装了httpd的话(用rpm -qa|grep httpd查看),
## 会有 /etc/init.d/httpd 这个脚本文件的,所以你也可以用以下方法直接生成这个文件来覆盖它
## 那么下次就可以用 service httpd start 来启动了
## 如果需要区分开来的话就使用下面的方式
  ## 首先以apachectl脚本为模板生成httpd服务控制脚本:
# grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd
## 用vi编辑Apache服务控制脚本/etc/init.d/httpd:
# cd /etc/init.d/
# vi httpd
## 在文件最前面插入下面的行,使其支持chkconfig命令:
#!/bin/sh
    # chkconfig:2345 85 15
# description:Apache is a World Wide Web server.

## 保存后退出vi编辑器,执行下面的命令增加httpd服务控制脚本执行权限:# chmod +x /etc/init.d/httpd## 执行下面的命令将http的服务加入到系统服务:# chkconfig --add httpd ##执行下面的命令检查httpd服务的状态# chkconfig --list httpdhttpd          0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭## 执行下列命令将开启http的3、5级别# chkconfig --level 35 httpd on# cd /usr/local/apache/conf/# vim httpd.conf
Listen 192.168.100.20:80##设置服务器监听的IP和端口#Listen 80
ServerName server02.benet.com##设置服务器用于辨识自己的主机名和端口号(用IP代替)。 ServerName server02.benet.com:80# service httpd start   ##启动httpd服务

##完成后在宿主机上进行访问:

# cat /usr/local/apache/htdocs/index.html##主页存放路径<html><body><h1>It works!</h1></body></html>
Apache配置脚本
mount.cifs //192.168.10.102/LAMP /opt/lamp
tar xzvf http-2.4.2.tar.gz -C /opt
tar xzvf apr-1.4.6.tar.gz -C /opt
tar xzvf apr-util-1.4.1.tar.gz -C /opt
cp -Rapr-1.4.6/ /opt/httpd-2.4.2/srclib/apr
cp -Rapr-util-1.4.1/ /opt/httpd-2.4.2/srclib/apr-util
ma
安装 gcc 、 gcc-c++、 make、 pcre、pcre-devel 四个包


cd /opt/httpd-2.4.2c

./configure \
--prefix=/usr/local/apache \
--enable-so \
--enable-rewrite \
--enable-mods-shared=most \
--with-mpm=worker \
--disable-cgid \
--disable-cgi

make
make install

grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd

vi /etc/init.d/httpd 在文件最前面插入下面的行

#!/bin/sh
    # chkconfig:2345 85 15
    # description:Apache is a World Wide Web server.

chmod +x /etc/init.d/httpd

chkconfig --add httpd
chkconfig --list httpd
chkconfig --level 35 httpd on

vi /usr/local/apache/conf/httpd.conf
或者建立软连接便于管理
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf

Listen:IPV4
Servername:主机名.域名

service httpd stop

service httpd start

主页存放路径为/usr/local/apache/htdocs/index.html

页: [1]
查看完整版本: Apache服务【手工编译安装】