一、源码包安装
### --- 注意事项 ### --- 应该选择哪种软件包? ~~~ 如果软件包是为大量客户提供访问,建议使用源码包进行安装LAMP环境搭建, ~~~ 因为源码包效率更高。 ~~~ 若给软件包Linux建议使用底层或只访问少量客户rpm包安装, ~~~ 因为rpm包简单。
### --- 源码包从何而来? ~~~ rpm直接包含在光盘中,用户无需单独下载。而源码包是通过官网下载的, ~~~ 若需使用,则需单独下载。 ### --- 是否可以在系统中安装rpm包的Apache,安装源码包Apache? ~~~ 答案是肯定的,因为安装了两种安装方法Apache,例如:
### --- RPM 包:不建议在默认位置指定安装位置(RPM 包装服务有标准卸载命令,不怕到处安装文件) ~~~ 配置文件: /etc/httpd/conf/httpd.conf ~~~ 网页位置: /var/www/html/ ~~~ 日志位置: /var/log/httpd/ ~~~ 启动方法: 1) service httpd restart ~~~ 2) /etc/rc.d/init.d/httpd restart ~~~ 源码包:必须设置安装位置(源码包没有安装数据库,未删除命令) ~~~ 配置文件: /usr/local/apache2/conf/httpd.conf ~~~ 网页文件: /usr/local/apache2/htdocs/ ~~~ 日志位置: /usr/local/apache2/logs/ ~~~ 启动方法: /usr/local/apache2/bin/apachectl start
二、安装过程
### --- 生产服务器会同时安装两种吗?Apache? ~~~ 当然不是,因为系统中只有80个端口,你只能启动一个端口Apache, ~~~ 安装多个只会浪费资源。建议安装源码包Apache。
### --- 安装过程 ### --- 我们来解释一下源码包安装的具体步骤。 ~~~ (1)下载软件包。 ~~~ (2)解压缩。 ~~~ (3)进入解压目录。 ~~~ (4)./configure 编译前准备
### --- 这一步主要有三个功能: ~~~ 在安装前,需要检查系统环境是否符合安装要求。 ~~~ 定义所需的功能选项。“./configure有许多功能选项支持, ~~~ 可以执行“./configure --help” ~~~ 命令查询其支持的功能。通常会通过通常会通过./configure --prefix=指定安装路径的安装路径。 ~~~ 将系统环境的检测结果和定义功能选项写入 Makefile 文件, ~~~ 本文件的内容取决于后续的编译和安装。 ~~~ 需要注意的是,configure 不是系统命令,而是源码包软件自带的脚本程序, ~~~ 因此,必须采用必须采用./configure执行方法(.在当前目录下代表/)。
### --- make ~~~ 编译 ~~~ make 会调用 gcc 并读取编译器 Makefile 系统软件编译文件中的信息。 ~~~ 编译的目的是将源码程序转换为能够被编译 Linux 识别的可执行文件, ~~~ 这些可执行文件保存在当前目录下。编译过程耗时,需要足够的耐心。
### --- make clean:清空编译内容(非必要步骤)。 ~~~ 如果在“./configure”或“make编译中报错, ~~~ 在重新执行命令之前,我们必须记住执行命令 makeclean 命令, ~~~ 它会清空 Makefile 文件或编译产生的.o”头文件。
### --- make install: ~~~ 编译安装 ~~~ 这是真正的安装过程,程序的安装位置通常会写清楚。 ~~~ 如果您忘记了指定的安装目录,您可以保存此命令的执行过程,以便将来删除。
三、安装流程:实验专题:
### --- 系统中安装rpm包apache,现在安装源码包apache? ### --- 答案: ~~~ 不,安装位置不同,所以可以在系统中安装一个rpm因为rpm有数据库, ~~~ 有卸载命令;所以不会报错; ### --- 部分软件包源码包安装不指定安装位置 ### --- 答案: ~~~ 因为这些软件包依赖于底层核技术;或者其他软件依赖;如果安装位置改变;会报错。 ~~~ 文件很小,依赖底核。 ~~~ 而且依赖底核,文件很小。影响不大;因此,不指定位置的成本最低。
### --- 将apache上传到服务器的源代码包 [root@server11 ~]# ls httpd-2.2.9.tar.gz [root@server11 ~]# tar -zxvf httpd-2.2.9.tar.gz [root@server11 ~]# cd httpd-2.2.9/
### --- 安装apache服务 [root@server11 httpd-2.2.9]# ./configure // ./:当前目录;因为configure不是系统命令,而是源码包命令,需要路径调用 ~~~ 安装前需要检查系统更换是否符合安装要求 ~~~ 定义所需的功能选项 ./config --help ~~~ 将系统更换的检测结果和定义功能选项写入Makefile中, ~~~ 后出安装是从Makefile依赖文件 [root@server11 httpd-2.2.9]# ./configure --prefix=/usr/local/apache2/ configure: error: C compiler cannot create executables
### --- 报错后需要执行make clean:清空编译生成的临时文件(非必要步骤) ### --- 源码报错: ~~~ 必须停止安装过程 ~~~ 查看是否no,warning,error关键字说明报错 [root@server11 httpd-2.2.9]# yum install -y gcc* [root@server11 httpd-2.2.9]# ./configure --prefix=/usr/local/apache2/
### --- 编译:make [root@server11 httpd-2.2.9]# make ~~~ ./config和make只有在硬盘或系统中不会写入任何数据make install写入数据, ~~~ ./config和make报错执行make clean清除缓存,make install若是报错, ~~~ 安装目录需要删除。 [root@server11 httpd-2.2.9]# make install
### --- 启动apache [root@server11 ~]# /usr/local/apache2/bin/apachectl start httpd: Could not reliably determine the server's fully qualified domain name, using fe80::820d:b26d:3507:5834 for ServerName
### --- 报错: ~~~ 无法分析完整的主机名称;可视为正常启动 ~~~ 如何确定启动是rpm或者源码包启动 [root@server11 ~]# ps aux |grep httpd root 25477 0.0 0.1 57432 2008 ? Ss 22:25 0:00 /usr/local/apach2//bin/httpd -k start
daemon 25478 0.0 0.0 59516 1356 ? S 22:25 0:00 /usr/local/apache2//bin/httpd -k start
daemon 25479 0.0 0.0 59516 1356 ? S 22:25 0:00 /usr/local/apache2//bin/httpd -k start
daemon 25480 0.0 0.0 59516 1356 ? S 22:25 0:00 /usr/local/apache2//bin/httpd -k start
daemon 25481 0.0 0.0 59516 1356 ? S 22:25 0:00 /usr/local/apache2//bin/httpd -k start
daemon 25482 0.0 0.0 59516 1356 ? S 22:25 0:00 /usr/local/apache2//bin/httpd -k start
root 25494 0.0 0.0 112816 976 pts/0 S+ 22:27 0:00 grep --color=auto httpd
### --- 访问一下apache
http://10.10.10.11/ // 输出:It works!
### --- 查看网页文件是
[root@server11 ~]# cat /usr/local/apache2/htdocs/index.html
<html><body><h1>It works!</h1></body></html> // It works!的编译规则
### --- 删除
~~~ 源码包没有删除命令,如果需要删除,直接删除安装目录即可。
四、打入补丁
### --- 补丁的生成
### --- 比较 old 和 new 文件的不同
~~~ 选项:
~~~ -a 将任何文档当做文本文档处理
~~~ -b 忽略空格造成的不同
~~~ -B 忽略空白行造成的不同
~~~ -I 忽略大小写造成的不同
~~~ -N 当比较两个目录时,如果某个文件只在一个目录中,则在另一个目录中视作空文件
~~~ -r 当比较目录时,递归比较子目录
~~~ -u 使用同一的输出格式
[root@localhost ~]# diff 选项 old new
### --- 举例
[root@localhost ~]# mkdir test
~~~ 建立测试目录
[root@localhost ~]# cd test
### --- 进入测试目录
[root@localhost test]# vi old.txt
our
school
is
atguigu
### --- 文件 old.txt,为了一会输出便于比较,每行分开
[root@localhost test]# vi new.txt
our
school
is
atguigu
in
Beijing
~~~ 文件 new.txt
~~~ 比较下两个文件的不同,并生成补丁文件“txt.patch”,命令如下:
[root@localhost test]# diff -Naur /root/test/old.txt /root/test/new.txt > txt.patch
### --- 比较两个文件的不同,同时生成 txt.patch 补丁文件
[root@localhost test]# vi txt.patch
~~~ 查看下这个文件
--- /root/test/old.txt 2012-11-23 05:51:14.347954373 +0800
~~~ 前一个文件
+++ /root/test/new.txt 2012-11-23 05:50:05.772988210 +0800
~~~ 后一个文件
~~~ 后一个文件比前一个文件多两行(+表示)
@@ -2,3 +2,5 @@
school
is
atguigu
+in
+beijing
五、打入补丁
### --- 按照补丁文件进行更新
~~~ 选项:
~~~ -pn n 为数字。代表按照补丁文件中的路径,指定更新文件的位置。
~~~ “-pn”不好理解,我们说明下。补丁文件是要打入旧文件的,
~~~ 但是你当前所在的目录和补丁文件中的记录的目录是不一定匹配的,
~~~ 所以就需要“-pn”来同步两个目录。
~~~ 比如我当前是在“/root/test”目录中(我要打补丁的旧文件就在当前目录下),
~~~ 补丁文件中记录的文件目录为“/root/test/old.txt”,
~~~ 这时如果写入“-p1”(在补丁文件目录中取消一级目录)
~~~ 那么补丁文件就会打入“/root/test/root/test/old.txt”文件中,这显然是不对的。
~~~ 那如果写入的是“-p2”(在补丁文件目录中取消二级目录)
~~~ 那么补丁文件打入的就是“/root/test/test/old.txt”,
~~~ 这显然也不对。如果写入的是“-p3”(在补丁文件目录中取消三级目录)
~~~ 那么补丁文件就是打入的“/root/test/old.txt”,
~~~ 我们的 old.txt 文件就在这个目录下,所以就应该是“-p3”。
~~~ 那么我们更新下“old.txt”文件,命令如下:
[root@localhost test]# patch –pn < 补丁文件
[root@localhost test]# patch -p3 < txt.patch
patching file old.txt
### --- 给 old.txt 文件打补丁
[root@localhost test]# cat old.txt
### --- 查看下 old.txt 的内容吧。
### --- 多出来了 in Beijing 两行
our
school
is
atguigu
in
Beijing
六、实验专题
### --- 准备实验
[root@server11 ~]# mkdir test
[root@server11 ~]# cd test/
[root@server11 test]# vim old.txt
[root@server11 test]# cp -a old.txt new.txt
[root@server11 test]# ls
new.txt old.txt
[root@server11 test]# vim new.txt
### --- 对比新旧文件生成补丁文件
[root@server11 test]# diff -Naur /root/test/old.txt /root/test/new.txt >pat.txt
[root@server11 test]# cat pat.txt
--- /root/test/old.txt 2021-03-09 22:36:34.266894477 +0800 // 文件的内容少,用减号
+++ /root/test/new.txt 2021-03-09 22:37:02.720893976 +0800 // 文件的内容多,用加号
@@ -2,3 +2,5 @@ // 对比结果,新文件多出两行用加号表示
111111111111111111111
222222222222222222222
333333333333333333333
+444444444444444444444
+555555555555555555555
### --- 打入必定文件
[root@server11 test]# patch -p3 < pat.txt // -pn:是调整路径
patching file old.txt
### --- 查看old.txt文件
[root@server11 test]# cat old.txt;和new文件一致
aaaaaaaaaaaaaaaaaaaaa
111111111111111111111
222222222222222222222
333333333333333333333
444444444444444444444
555555555555555555555