apache 编译安装与做nagios前端展示

简介:

一.apache编译安装篇


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

#各编译参数说明

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

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

--enable-so #加载动态共享对象,可实现模块动态生效

--enable-ssl #支持SSL/TLS,可实现https访问

--enable-ssl #支持CGI脚本(默认对非线程的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#指定动态启用的模块

--enable-mpms-shared=all #支持动态加载的MPM模块,可选"all"

--with-mpm=event#设置默认启用的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#发生错误时返回给客户端的信息
│   └── include
├── htdocs
├── icons#httpd图标文件
│   └── small
├── include#头文件
├── logs#日志文件
├── man#帮助手册
│   ├── man1
│   └── man8
├── manual
│   ├── developer
│   ├── faq
│   ├── howto
│   ├── images
│   ├── 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#扩展的配置文件
│   ├── 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

找到下面的该行,把监听端口改成本地的80

#ServerName www.example.com:80

ServerName  localhost:80

修改httpd的主配置文件,设置Pid文件的路径

PidFile "/var/run/httpd.pid"
修改系统的PATH环境变量,让/usr/local/apache2/bin目录下的命令都可以执行:

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
导出头文件

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

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

导出man手册,可以用man httpd查看http的命令

vim /etc/man.config

MANPATH /usr/local/apache2/man

 

9.编辑服务脚本

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.为脚本加执行权限,并启动测试

chmod +x /etc/init.d/httpd

[root@sever9 ~]# chmod +x /etc/rc.d/init.d/httpd
[root@sever9 ~]# service httpd start
Starting httpd:                                            [  OK  ]
查看监听的端口

[root@sever9 ~]# ss -tnlp

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

显示效果如下图

wKiom1cCQNGAKYzBAABEgCFukzM915.png

加为系统服务并设置自动启动

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监控页面必须经过授权才能访问,这需要增加验证配置,即在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用户认证文件

   Require valid-user

</Directory>

Alias /nagios "/usr/local/nagios/share"#访问网页文件路径别名

<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.创建apache目录验证文件 

在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:

/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.关闭并重启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认证用户名nagiosadmin,和刚设置的密码


页面会显示如下图所示


wKiom1biN7SQVCcQAAI1MtLLlsA402.png

本文转自服务器运维博客51CTO博客,原文链接http://blog.51cto.com/shamereedwine/1749865如需转载请自行联系原作者



neijiade10000

相关文章
|
7月前
|
Linux Apache
百度搜索:蓝易云【Cnetos7编译安装Apache教程。】
现在,您已经成功在CentOS 7上通过编译安装了Apache。请注意,以上步骤提供了基本的指导,实际操作可能会有所差异。如有需要,您可以参考Apache官方文档或社区资源获取更详细的信息和帮助。
59 0
|
4月前
|
Rust 前端开发 JavaScript
Rust 编译为 WebAssembly 在前端项目中使用(二)
Rust 编译为 WebAssembly 在前端项目中使用(二)
113 0
|
1月前
|
前端开发 API 项目管理
云效常见问题之编译前端的时候报了个错说证书过期如何解决
云效(CloudEfficiency)是阿里云提供的一套软件研发效能平台,旨在通过工程效能、项目管理、质量保障等工具与服务,帮助企业提高软件研发的效率和质量。本合集是云效使用中可能遇到的一些常见问题及其答案的汇总。
22 0
|
7月前
|
Linux Apache 开发工具
百度搜索:蓝易云【Centos8 stream系统编译安装Apache教程。】
以上是在CentOS 8 Stream系统上编译安装Apache的基本教程。请注意,具体的配置和参数可能因您的需求而有所不同,您可以根据自己的情况进行调整。同时,请确保在执行任何操作之前备份重要的文件和配置。
385 0
|
4月前
|
Rust 前端开发 JavaScript
Rust 编译为 WebAssembly 在前端项目中使用(一)
Rust 编译为 WebAssembly 在前端项目中使用(一)
|
6月前
|
编解码 前端开发 JavaScript
运行时💎?还是编译时🚀?前端框架的角斗场🛡
运行时💎?还是编译时🚀?前端框架的角斗场🛡
|
7月前
|
Ubuntu Apache
百度搜索:蓝易云【Ubuntu 18.04系统编译安装Apache教程。】
现在,您已经成功地在Ubuntu 18.04上编译和安装了Apache。您可以通过在浏览器中访问服务器的IP地址来验证Apache是否正常运行。请确保在实际操作中根据您的需求进行适当的配置和调整。请注意,通过编译安装方式安装的Apache不会自动更新,您需要手动更新版本或进行维护。
88 1
|
7月前
|
Ubuntu Apache
百度搜索:蓝易云【Ubuntu 20.04系统编译安装Apache教程。】
请注意,以上是一个基本的编译安装Apache的示例,您可能需要根据您的特定需求进行进一步配置和调整。
61 0
|
7月前
|
Apache
百度搜索:蓝易云【Debian11系统编译安装Apache教程。】
以上是在Debian 11系统上编译安装Apache的基本步骤。请根据实际情况进行相应的调整和配置。
55 0
|
8月前
|
前端开发
前端学习笔记202306学习笔记第四十七天-vue-模板编译1
前端学习笔记202306学习笔记第四十七天-vue-模板编译1
32 0

推荐镜像

更多