xiaoqiang2000

第一部分:apache原理

1.1        Apache入门简介

1.1.1  进程和线程概念

  1. 进程是操作系统分配资源的基本单位,进程是程序的实体,程序软件是静止的,而进程是将程序运行起来,进程是活动的。
  2. 线程和进程区别?线程是进程的基本单位,范围比进程要小,一个进程中包含一个线程或者多个线程,所有的线程共享该进程的内存空间,如果进程挂掉,所有线程崩溃,如果一个线程异常退出,连同其他的线程或者进程会崩溃,多线程的好处是提高访问效率、并发高网站采用多进程-多线程工作。

l  目前主流的WEB服务器软件包括:Apache、Nginx、Lighttpd、IIS、Resin、Tomcat、WebLogic、Jetty等。

l  Apache是一个古老的web服务器软件,基于apache基金会的开发的,该服务器默认只能发布静态网页(跟数据库没有发生交互的);

l  Apache web服务器是一种多模块式的软件,模块丰富,每个模块都能完成不同功能。

l  Apache web服务器像一辆汽车,必须要有运动引擎(发动机),运动引擎称为工作模式,处理访问请求,通常有三种模式:prefork,worker,event。

l  Apache 默认引擎为prefork,其特点启动startservers个工作的进程,每一个工作进程在特定的时间只能处理一个请求,支持预派生模式,好处就是方便请求到来时不用临时生成请求,提升web服务器的性能,多进程方式,比较消耗内存和系统资源。

l  Worker MPM模式:使用多个进程,每个子进程包含多个线程,每个线程在某个确定的时间只能维持一个连接,内存占用量比较小,适合大并发、高流量的WEB服务器。Worker MPM缺点是一个线程崩溃,整个进程就会连同其任何线程一起挂掉。

 

1.2        源码包安装httpd

Wget  http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.29.tar.bz2

 

 

 

1)./configure 检测系统环境是否能够达到编译的请求

2)make 根据生成的makefile文件来执行对应的编译

3)make install 安装软件配置文件

wget http://archive.apache.org/dist/httpd/httpd-2.4.29.tar.gz

Apache WEB服务器安装步骤如下:

tar  -xjvf  httpd-2.4.29.tar.bz2         tar工具解压httpd包;

cd httpd-2.4.29/                      进入解压后目录;

yum install apr apr-devel apr-util apr-util-devel -y          安装APR相关优化模块;

APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。

./configure --prefix=/usr/local/apache2/ --enable-rewrite --enable-so     预编译Apache,启用rewrite规则、启用动态加载库;

编译的时候可以通过configure的参数来指定

--with-mpm=prefork|worker|event()

也可以编译为三种都支持,通过修改配置来更换。

--enable-mpms-shared=all

make                  编译

make install             安装Apache2.4.29安装完毕,如图10-1所示:

 

图10-1 Apache2.2.32安装图解

 

启动Apache服务,临时关闭selinux、firewalld防火墙:

/usr/local/apache2/bin/apachectl start

setenforce 0

systemctl  stop   firewalld.service

查看Apache服务进程,通过客户端浏览器访问http://192.168.111.131/,如图10-2(a)、10-2(b)所示:

图10-2(a) Apache启动及查看进程

 

  • 图10-2(b) 浏览器访问Apache WEB服务器

第二种 安装Apache服务

1、下载软件包和安装编译工具与插件

[root@localhost ~]# yum -y install wget gcc gcc-c++ make pcre-devel pcre perl expat-devel perl-devel libtool

[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/apache/httpd-2.4.29.tar.gz

[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/apr/apr-1.6.3.tar.gz

[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/apr-util/apr-util-1.6.1.tar.gz

#APR安装

 

1、解压APR软件包

[root@localhost ~]# tar zxf apr-1.6.3.tar.gz

[root@localhost ~]# cd apr-1.6.3

2、预编译

[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr

 

3、编译及安装

[root@localhost apr-1.6.3]# make && make install

 

#Apr-util安装

1、解压apr-util软件包

[root@localhost apr-1.6.3]# cd ..

[root@localhost ~]# tar zxf apr-util-1.6.1.tar.gz

[root@localhost ~]# cd apr-util-1.6.1

2、预编译

[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

 

3、编译及安装

[root@localhost apr-util-1.6.1]# make && make install

 

#Apache安装

1、解压httpd软件包

[root@localhost apr-util-1.6.1]# cd ..

[root@localhost ~]# tar zxf httpd-2.4.29.tar.gz

[root@localhost ~]# cd httpd-2.4.29

2、预编译

[root@localhost ~]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-rewrite --enable-cahreset-lite

 

3、编译及安装

[root@localhost httpd-2.4.29]# make && make install

 

 

4、将httpd服务添加到系统服务

[root@localhost httpd-2.4.29]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

[root@localhost httpd-2.4.29]# vi /etc/init.d/httpd

#添加以下两行(注意,"#"不能省略):

1.    # chkconfig: - 85 21

2.    # description: Apache is a World Wide Web Server

 

#保存退出

5、将httpd加入到SERVICE管理器

[root@localhost httpd-2.4.29]# chkconfig --add httpd

[root@localhost httpd-2.4.29]# systemctl daemon-reload

6、编辑httpd主配置文件

[root@localhost httpd-2.4.29]# vim /usr/local/apache/conf/httpd.conf

修改以下内容:

ServerName localhost:80

#保存退出

 

7、创建软连接

[root@localhost httpd-2.4.29]# ln -s /usr/local/apache/bin/* /usr/bin

#检查语法错误

[root@localhost httpd-2.4.29]# httpd -t

或者:

[root@localhost httpd-2.4.29]# apachectl -t

 

8、启动httpd服务

[root@localhost httpd-2.4.29]# systemctl start httpd

 

9、验证

#浏览器访问服务器IP,http://192.168.0.117

 

分类:

技术点:

相关文章:

  • 2021-09-13
  • 2021-09-15
  • 2021-12-05
  • 2021-11-16
  • 2021-05-25
  • 2022-12-23
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2021-04-28
  • 2022-01-04
  • 2021-11-13
  • 2021-10-15
  • 2021-10-23
相关资源
相似解决方案