了Centos7.4服務器安裝apache

本文實例講述了Centos7.4服務器安裝apache及安裝過程出現的問題解決方法。分享給你們供你們參考,具體以下:java

1、安裝httpdapache

1. 安裝以前,先查看系統中是否存在已經安裝了的httpd.rpm包,若是,沒有就是沒安裝,有的話rpm -e 對應的rpm包名進行刪除bash

?
1
#rpm -qa | grep httpd

2. 使用yum安裝(自動安裝依賴包),簡單方便服務器

?
1
#yum -y install httpd

3. 安裝成功後,httpd-v 查看安裝的apache版本,查找apache的配置文件位置dom

?
1
#find / -name "httpd.conf"

4. 將找到的源配置文件備份一份,防止錯誤後沒法恢復socket

?
1
#cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

5. 啓動Apache服務tcp

?
1
#systemctl start httpd.service

6. 開機自動啓動Apache服務spa

?
1
2
#systemctl enable httpd.service 開機自啓httpd
#systemctl disable httpd.service 開機不啓動httpd

7. 查看httpd的狀態.net

?
1
#systemctl status httpd.service

2、安裝過程出現的問題rest

1. Apache啓動失敗,Job for httpd.service failed because the control process exited with error code. See 「systemctl status httpd.service」 and 「journalctl -xe」 for details

執行命令,查看報錯提示

?
1
#systemctl status httpd.service
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@cloud1 bin] # systemctl status httpd.service
   httpd.service - The Apache HTTP Server
   Loaded: loaded ( /usr/lib/systemd/system/httpd .service; disabled; vendor preset: disabled)
   Active: failed (Result: exit -code) since 五 2018-11-26 11:13:09 CST; 6min ago
    Docs: man :httpd(8)
       man :apachectl(8)
  Process: 9915 ExecStop= /bin/kill -WINCH ${MAINPID} (code=exited, status=1 /FAILURE )
  Process: 9913 ExecStart= /usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1 /FAILURE )
  Main PID: 9913 (code=exited, status=1 /FAILURE )
11月 26 11:13:09 cloud1.localdomain httpd[9913]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
11月 26 11:13:09 cloud1.localdomain httpd[9913]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
11月 26 11:13:09 cloud1.localdomain httpd[9913]: no listening sockets available, shutting down
11月 26 11:13:09 cloud1.localdomain httpd[9913]: AH00015: Unable to open logs
11月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1 /FAILURE
11月 26 11:13:09 cloud1.localdomain kill [9915]: kill : cannot find process ""
11月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service: control process exited, code=exited status=1
11月 26 11:13:09 cloud1.localdomain systemd[1]: Failed to start The Apache HTTP Server.
11月 26 11:13:09 cloud1.localdomain systemd[1]: Unit httpd.service entered failed state.
11月 26 11:13:09 cloud1.localdomain systemd[1]: httpd.service failed.

問題是80端口被佔用

解決辦法:

查看80端口的使用狀況

① .netstat -lnp|grep 80

tcp        0      0 192.168.180.68:61027        0.0.0.0:*                   LISTEN      6289/oproxyd
tcp        0      0 :::80                       :::*                        LISTEN      846/httpd
tcp        0      0 ::ffff:192.168.180.68:7001 :::*                        LISTEN      32015/java

殺掉佔用80端口的進程

② .kill -9 846

③ .如果前兩個方法不行的話,則重啓後再啓動httpd服務

2.Apache啓動失敗,httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName

① .進入apache的配置文件

?
1
vi /etc/httpd/conf/httpd .conf

② ./ServerName 查找ServerName

?
1
#ServerName www.example.com:80

將其前面的#去掉

:wq保存並退出

③ .重啓服務

?
1
systemctl restart httpd.service

但願本文所述對你們CentOS服務器配置有所幫助。

相關文章
相關標籤/搜索