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安全功能
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
二、準備安裝環境,進行yum的安裝,安裝環境依賴包html
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
三、配置軟件模塊前端
(1)對三個軟件進行解壓linux
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
(2)將 apr 的兩個包移動到 httpd 的 子目錄srclib 中 並更名c++
![](http://static.javashuo.com/static/loading.gif)
(3)切換到 httpd-2.4.29 目錄中,執行 configure 文件正則表達式
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
四、編譯與原裝shell
(-j 指定多少核數,本虛擬機cpu是 2 核,可根據本身機子的性能添加,核數越大編譯越;)注:千萬不要超過你當前編譯使用虛擬機的核數,否則會報錯。數據庫
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
五、優化配置文件路徑,並把httpd服務的可執行程序文件放入路徑環境變量的目錄中便於系統識別apache
(1)建立軟連接編程
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
六、添加 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
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
(2)複製apachectl 到init.d 目錄中,並修更名稱爲 httpd
![](http://static.javashuo.com/static/loading.gif)
(3)將httpd服務加入到service管理器,並啓動服務
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
(4)啓動成功了
![](http://static.javashuo.com/static/loading.gif)
(5)一樣的,用systemctl 也能啓動起來
![](http://static.javashuo.com/static/loading.gif)
方法二:
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
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)