apache編譯安裝與做nagios前端展示-創(chuàng)新互聯(lián)

一.apache編譯安裝篇

創(chuàng)新互聯(lián)不只是一家網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司;我們對營銷、技術(shù)、服務(wù)都有自己獨特見解,公司采取“創(chuàng)意+綜合+營銷”一體化的方式為您提供更專業(yè)的服務(wù)!我們經(jīng)歷的每一步也許不一定是最完美的,但每一步都有值得深思的意義。我們珍視每一份信任,關(guān)注我們的成都網(wǎng)站設(shè)計、做網(wǎng)站質(zhì)量和服務(wù)品質(zhì),在得到用戶滿意的同時,也能得到同行業(yè)的專業(yè)認(rèn)可,能夠為行業(yè)創(chuàng)新發(fā)展助力。未來將繼續(xù)專注于技術(shù)創(chuàng)新,服務(wù)升級,滿足企業(yè)一站式全網(wǎng)營銷推廣需求,讓再小的品牌網(wǎng)站建設(shè)也能產(chǎn)生價值!

1.安裝apache需安裝以下的幾個包,apr 、apr-util、pcre等。

2.下載安裝apr

把文件放到/usr/local/src目錄下,

tar -zxvf  apr-1.5.2.tar.gz

cd  apr-1.5.2

./configure --prefix=/usr/local/apr

make

make install

3.下載安裝apr-util

tar -zxvf apr-util-1.5.4.tar.gz

cd apr-util-1.5.4

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr#這里配置的時候要指定apr的安裝路徑。

make

make install

4.安裝pcre

tar -zxvf pcre

cd pcre

./configure --prefix=/usr/local/pcre

make && make install

5.安裝apache 這里安裝的版本是2.4.18,比較新的版本

tar -zxvf httpd-2.4.18.tar.gz

cd httpd-2.4.18

./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-cgid --enable-rewrite --enable-deflate --with-z --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-openssl=/usr/local/ssl --enable-modules=most --enable-mpms-shared=all --with-mpm=event

#各編譯參數(shù)說明

--prefix=/usr/local/apache2 # 家目錄

--sysconfdir=/etc/httpd #配置文件目錄

--enable-so #加載動態(tài)共享對象,可實現(xiàn)模塊動態(tài)生效

--enable-ssl #支持SSL/TLS,可實現(xiàn)https訪問

--enable-ssl #支持CGI腳本(默認(rèn)對非線程的MPM模式開啟)

--enable-rewrite #啟用Rewirte功能

--enable-deflate #支持壓縮

--with-zlib#指定zlib庫,不指定自動尋找

--with-apr=/usr/local/apr #指定apr路徑

--with-apr-util=/usr/local/apr-util #指定apr-util路徑

--with-pcre=/usr/local/pcre #指定pcre路徑

--with-openssl=/usr/local/ssl #指定openssl的路徑

--enable-modules=most#指定動態(tài)啟用的模塊

--enable-mpms-shared=all #支持動態(tài)加載的MPM模塊,可選"all"

--with-mpm=event#設(shè)置默認(rèn)啟用的MPM模式

make

make install

6.安裝完成后安裝目錄下會有以下的幾個目錄

bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

[root@sever9 ~]# tree -d /usr/local/apache2#安裝目錄樹
/usr/local/apache2
├── bin#主程序目錄
├── build
├── cgi-bin#cgi文件存放目錄
├── error#發(fā)生錯誤時返回給客戶端的信息
│  └── include
├── htdocs
├── icons#httpd圖標(biāo)文件
│  └── small
├── include#頭文件
├── logs#日志文件
├── man#幫助手冊
│  ├── man1
│  └── man8
├── manual
│  ├── developer
│  ├── faq
│  ├── howto
│  ├── p_w_picpaths
│  ├── misc
│  ├── mod
│  ├── platform
│  ├── programs
│  ├── rewrite
│  ├── ssl
│  ├── style
│  │  ├── css
│  │  ├── lang
│  │  ├── latex
│  │  ├── scripts
│  │  └── xsl
│  │      └── util
│  └── vhosts
└── modules#模塊文件

7.配置目錄下的文件

[root@sever9 httpd]# tree /etc/httpd
/etc/httpd
├── extra#擴(kuò)展的配置文件
│  ├── httpd-autoindex.conf
│  ├── httpd-dav.conf
│  ├── httpd-default.conf
│  ├── httpd-info.conf
│  ├── httpd-languages.conf
│  ├── httpd-manual.conf
│  ├── httpd-mpm.conf
│  ├── httpd-multilang-errordoc.conf
│  ├── httpd-ssl.conf
│  ├── httpd-userdir.conf
│  ├── httpd-vhosts.conf
│  └── proxy-html.conf
├── httpd.conf#主配置文件
├── magic
├── mime.types
└── original
   ├── extra
   │  ├── httpd-autoindex.conf
   │  ├── httpd-dav.conf
   │  ├── httpd-default.conf
   │  ├── httpd-info.conf
   │  ├── httpd-languages.conf
   │  ├── httpd-manual.conf
   │  ├── httpd-mpm.conf
   │  ├── httpd-multilang-errordoc.conf
   │  ├── httpd-ssl.conf
   │  ├── httpd-userdir.conf
   │  ├── httpd-vhosts.conf
   │  └── proxy-html.conf
   └── httpd.conf

8.修改配置文件

vim /etc/httpd/httpd.conf

找到下面的該行,把監(jiān)聽端口改成本地的80

#ServerName www.example.com:80

ServerName  localhost:80

修改httpd的主配置文件,設(shè)置Pid文件的路徑

PidFile "/var/run/httpd.pid"
修改系統(tǒng)的PATH環(huán)境變量,讓/usr/local/apache2/bin目錄下的命令都可以執(zhí)行:

vim /etc/profile.d/httpd.sh

export PATH=/usr/local/apache2/bin:$PATH

source /etc/profile.d/httpd.sh

檢查下語法

[root@sever9 ~]# httpd -t
Syntax OK
導(dǎo)出頭文件

ln -sv /usr/local/apache2/include /usr/local/include/httpd

`/usr/local/include/httpd' -> `/usr/local/apache2/include'

導(dǎo)出man手冊,可以用man httpd查看http的命令

vim /etc/man.config

MANPATH /usr/local/apache2/man

9.編輯服務(wù)腳本

vim /etc/init.d/httpd

#!/bin/bash
#
# httpd  Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
#  HTML files and CGI.
# processname: httpd
# config: /etc/httpd/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
   . /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl#apache 控制腳本路徑httpd=${HTTPD-/usr/local/apache2/bin/httpd}#apache 主程序的路徑

prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}#注意該http.pid文件的路徑lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
 echo -n $"Starting $prog: "
 LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && touch ${lockfile}
 return $RETVAL
}
stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $httpd
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
 echo -n $"Reloading $prog: "
 if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
   RETVAL=$?
   echo $"not reloading due to configuration syntax error"
   failure $"not reloading $httpd due to configuration syntax error"
 else
   killproc -p ${pidfile} $httpd -HUP
   RETVAL=$?
 fi
 echo
}
# See how we were called.
case "$1" in
start)
 start;;
stop)
 stop;;
status)
 status -p ${pidfile} $httpd
 RETVAL=$?;;
restart)
 stop
 start;;
condrestart)
 if [ -f ${pidfile} ] ; then
   stop
   start
 fi;;
reload)
 reload;;
graceful|help|configtest|fullstatus)
 $apachectl $@
 RETVAL=$?;;
*)
 echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
 exit 1
esac
exit $RETVAL

10.為腳本加執(zhí)行權(quán)限,并啟動測試

chmod +x /etc/init.d/httpd

[root@sever9 ~]# chmod +x /etc/rc.d/init.d/httpd
[root@sever9 ~]# service httpd start
Starting httpd:                                           [ OK ]
查看監(jiān)聽的端口

[root@sever9 ~]# ss -tnlp

LISTEN     0     128                                                                     :::80                                                                     :::*     users:(("httpd",16817,4),("httpd",16819,4),("httpd",16820,4),("httpd",16821,4))

顯示效果如下圖

apache 編譯安裝與做nagios前端展示

加為系統(tǒng)服務(wù)并設(shè)置自動啟動

chkconfig --add httpd

chkconfig httpd on

二.做nagios前端展示篇

1.編譯安裝php

這里我們安裝的版本是5.6.11,

tar -jxvf php-5.6.11.tar.bz2

cd php-5.6.11

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs

make && make install

2.配置apache支持nagios

修改/etc/httpd/httpd.conf的文件

把 User deamon
Group deamon

改為

User nagios

Group nagios

然后找到

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

修改為

<IfModule dir_module>

DirectoryIndex index.html index.php

AddType application/x-httpd-php .php

</IfModule>

再找到模塊項,把下面的幾個模塊選項注釋去掉。

LoadModule cgid_module modules/mod_cgid.so

LoadModule actions_module modules/mod_actions.so

為了安全起見,一般情況下要讓nagios 的web監(jiān)控頁面必須經(jīng)過授權(quán)才能訪問,這需要增加驗證配置,即在httpd.conf文件最后添加如下信息:

定義別名:

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"#nagiosCGI腳本位置

<Directory "/usr/local/nagios/sbin">

#  SSLRequireSSL

  Options ExecCGI

  AllowOverride None

   Require all granted

#  Allow from 127.0.0.1

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.users#nagios用戶認(rèn)證文件

  Require valid-user

</Directory>

Alias /nagios "/usr/local/nagios/share"#訪問網(wǎng)頁文件路徑別名

<Directory "/usr/local/nagios/share">

#  SSLRequireSSL

  Options None

  AllowOverride None

  Require all granted

#  Order deny,allow

#  Deny from all

#  Allow from 127.0.0.1

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.users

  Require valid-user

</Directory>

3.創(chuàng)建apache目錄驗證文件

在上面的配置中,指定了目錄驗證文件htpasswd,下面要創(chuàng)建這個文件:

/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin

4.關(guān)閉并重啟apache

service httpd restart

啟動apache,報403拒絕訪問,這里是2.4*的版本

要在httpd.conf里改配置文件

<Directory />

  AllowOverride none

  Require all denied

</Directory>

改為

<Directory />

  AllowOverride none

  Require all granted

</Directory>

并重啟apache

nagios展示效果:

打開

http://172.30.65.169/nagios/的頁面,輸入nagios認(rèn)證用戶名nagiosadmin,和剛設(shè)置的密碼

頁面會顯示如下圖所示

apache 編譯安裝與做nagios前端展示

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站名稱:apache編譯安裝與做nagios前端展示-創(chuàng)新互聯(lián)
文章出自:http://bm7419.com/article18/djhogp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站品牌網(wǎng)站建設(shè)、網(wǎng)站收錄、電子商務(wù)、商城網(wǎng)站、響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司