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

相关文章
|
Linux Apache
百度搜索:蓝易云【Cnetos7编译安装Apache教程。】
现在,您已经成功在CentOS 7上通过编译安装了Apache。请注意,以上步骤提供了基本的指导,实际操作可能会有所差异。如有需要,您可以参考Apache官方文档或社区资源获取更详细的信息和帮助。
183 0
|
资源调度 前端开发
编译第三方前端项目时候出现Syntax Error: TypeError: Cannot set properties of undefined (setting ‘parent‘)
编译第三方前端项目时候出现Syntax Error: TypeError: Cannot set properties of undefined (setting ‘parent‘)
1190 0
|
Rust 前端开发 JavaScript
Rust 编译为 WebAssembly 在前端项目中使用(二)
Rust 编译为 WebAssembly 在前端项目中使用(二)
482 0
|
Linux Apache 开发工具
百度搜索:蓝易云【Centos8 stream系统编译安装Apache教程。】
以上是在CentOS 8 Stream系统上编译安装Apache的基本教程。请注意,具体的配置和参数可能因您的需求而有所不同,您可以根据自己的情况进行调整。同时,请确保在执行任何操作之前备份重要的文件和配置。
607 0
|
资源调度 前端开发 JavaScript
前端 nodejs 命令行自动调用编译 inno setup 的.iss文件
前端 nodejs 命令行自动调用编译 inno setup 的.iss文件
|
前端开发 开发者
在前端开发中,webpack 作为模块打包工具,其 DefinePlugin 插件可在编译时动态定义全局变量,支持环境变量定义、配置参数动态化及条件编译等功能。
在前端开发中,webpack 作为模块打包工具,其 DefinePlugin 插件可在编译时动态定义全局变量,支持环境变量定义、配置参数动态化及条件编译等功能。本文阐述 DefinePlugin 的原理、用法及案例,包括安装配置、具体示例(如动态加载资源、配置接口地址)和注意事项,帮助开发者更好地利用此插件优化项目。
532 0
|
前端开发 Java Serverless
阿里云云效产品使用问题之前端流水线部署时,在构建环节,编译和打包要分开还是放在一起
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
前端开发 JavaScript 编译器
Svelte框架:编译时优化的高性能前端框架
Svelte是一款由Rich Harris于2016年创建的高性能前端框架,以其编译时优化著称。它将复杂UI逻辑转化为高效的JavaScript,减少运行时开销。Svelte的核心理念是将编译时和运行时的复杂性分离,通过模板语法、组件系统、响应式系统和编译器实现高性能。关键优化策略包括声明式更新、模板内联、计算属性缓存、事件处理优化和代码分割。Svelte提供热模块替换、类型检查和丰富的生态系统,如SvelteKit。其响应式系统基于Reactive Statements,自动更新组件。
604 0
|
缓存 自然语言处理 前端开发
JVM系列8-前端编译与优化
JVM系列8-前端编译与优化
148 0
|
前端开发 API 项目管理
云效常见问题之编译前端的时候报了个错说证书过期如何解决
云效(CloudEfficiency)是阿里云提供的一套软件研发效能平台,旨在通过工程效能、项目管理、质量保障等工具与服务,帮助企业提高软件研发的效率和质量。本合集是云效使用中可能遇到的一些常见问题及其答案的汇总。
231 0

热门文章

最新文章

推荐镜像

更多