2、编译安装Apache httpd服务
操做步骤流程:
1.关闭防火墙,将安装Apache所需软件包传到/opt目录下
systemctl stop firewalld systemctl disable firewalld setenforce 0
httpd-2.4.29.tar.gz apr-1.6.2.tar.gz apr-util-1.6.0.tar.gz
#apr组件包用于支持Apache上层应用跨平台,提供底层接口库,能有效的下降并发链接数、下降进程和减小访问堵塞。
2.安装环境依赖包
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl
------------------------------------------------------------------------------------------
各程序做用解释以下:
gcc #C语言的编译器
gcc-c++ #C++的编译器
make #源代码编译器(源代码转换成二进制文件)
pcre #pcre是一个Perl函数库,包括perl 兼容的正则表达式库
pcre-devel #perl的接口开发包
expat-devel #用于支持网站解析HTML、XML文件
perl #perl语言编译器
3.配置软件模块
cd /opt/
tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2
mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util
cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
------------------------------------------------------------------------------------------------------
各配置命令做用解释以下:
--enable-so \ #启用动态加载模块支持,使 httpd 具有进一步扩展功能的能力
--enable-rewrite \ #启用网页地址重写功能,用于网站优化、防盗链及目录迁移维护
--enable-charset-lite \ #启动字符集支持,以便支持使用各类字符集编码的页面
--enable-cgi #启用CGI(通用网关接口)脚本程序支持,便于网站的外部扩展应用访问能力
4.编译及安装
make #make -j 2 表示开2核同时进行编译
make install
5.优化配置文件路径,并把httpd服务的可执行程序文件放入路径环境变量的目录中便于系统识别
ln -s /usr/local/httpd/conf/httpd.conf /etc/ #作个软连接
ln -s /usr/local/httpd/bin/* /usr/local/bin/ #作个软连接
6.添加httpd系统服务
方法一:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #用于service服务管理
chmod +x /etc/init.d/httpd
vi /etc/init.d/httpd
#!/bin/bash #在第一行前插入新行,添加此三行内容
# chkconfig: 35 85 21 #35级别自动运行 第85个启动 第21个关闭
# description: Apache is a World Wide Web server
chkconfig --add httpd #将httpd服务加入到service管理器
systemctl start httpd.service #开启http服务(关闭和开启要使用相同的方式)
或
service httpd start #开启http服务(关闭和开启要使用相同的方式)
方法二:
vim /lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server #描述
After=network.target #描述服务类别
[Service]
Type=forking #后台运行方式
PIDFile=/usr/local/httpd/logs/httpd.pid #PID文件位置
ExecStart=/usr/local/bin/apachectl $OPTIONS #启动服务
ExecReload=/bin/kill -HUP $MAINPID #根据PID重载配置
[Install]
WantedBy=multi-user.target
systemctl start httpd.service #开启http服务(关闭和开启要使用相同的方式)
systemctl enable httpd.service #设为开机自启动
7.修改httpd 服务配置文件
vim /etc/httpd.conf
--52行--修改
Listen 20.0.0.13:80
--197行--取消注释,修改
ServerName www.xxx.com:80
--221行--默认首页存放路径
DocumentRoot "/usr/local/httpd/htdocs"
--255行--默认首页文件名设置
DirectoryIndex index.html
httpd -t 或 apachectl -t #检查配置文件的配置项是否有误
cat /usr/local/httpd/htdocs/index.html #查看html的内容
systemctl restart httpd.service
8.浏览器访问验证
netstat -anpt | grep 80
echo "20.0.0.13 www.xxx.com" >> /etc/hosts
操做具体步骤(图文)
一、将三个压缩文件拖入到xshell内,而后关闭防火墙和selinux安全功能


二、准备安装环境,进行yum的安装,安装环境依赖包html




三、配置软件模块前端
(1)对三个软件进行解压linux




(2)将 apr 的两个包移动到 httpd 的 子目录srclib 中 并更名c++

(3)切换到 httpd-2.4.29 目录中,执行 configure 文件正则表达式



四、编译与原装shell
(-j 指定多少核数,本虚拟机cpu是 2 核,可根据本身机子的性能添加,核数越大编译越;)注:千万不要超过你当前编译使用虚拟机的核数,否则会报错。数据库


五、优化配置文件路径,并把httpd服务的可执行程序文件放入路径环境变量的目录中便于系统识别apache
(1)建立软连接编程


六、添加 httpd 系统服务vim
方法一:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #用于service服务管理
chmod +x /etc/init.d/httpd
vi /etc/init.d/httpd
#!/bin/bash #在第一行前插入新行,添加此三行内容
# chkconfig: 35 85 21 #35级别自动运行 第85个启动 第21个关闭
# description: Apache is a World Wide Web server
chkconfig --add httpd #将httpd服务加入到service管理器
systemctl start httpd.service
或
service httpd start
(1)作个启动脚本,启动脚本在 bin 目录中的 apachectl


(2)复制apachectl 到init.d 目录中,并修更名称为 httpd

(3)将httpd服务加入到service管理器,并启动服务







(4)启动成功了

(5)一样的,用systemctl 也能启动起来

方法二:
vim /lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server #描述
After=network.target #描述服务类别
[Service]
Type=forking #后台运行方式
PIDFile=/usr/local/httpd/logs/httpd.pid #PID文件位置
ExecStart=/usr/local/bin/apachectl $OPTIONS #启动服务
ExecReload=/bin/kill -HUP $MAINPID #根据PID重载配置
[Install]
WantedBy=multi-user.target
systemctl start httpd.service
systemctl enable httpd.service

