关闭防火墙和selinux:
[root@localhost ~]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
[root@localhost ~]# setenforce 0
[root@localhost ~]#
环境准备工作:
[root@localhost ~]# yum repolist
已加载插件:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
仓库标识 仓库名称 状态
base CentOS-6 - Base 6,713
extras CentOS-6 - Extras 47
updates CentOS-6 - Updates 1,004
repolist: 7,764
[root@localhost ~]#
搭建LAMP环境并安装所需要的工具和库:
[root@localhost ~]# yum -y install httpd mysql mysql-server php php-devel php-mysql openssl-devel gcc gcc-c++
整合Apache和PHP:
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
[root@localhost ~]# cat /etc/httpd/conf/httpd.conf | grep -v "^#" | grep DirectoryIndex
DirectoryIndex index.html index.php index.html.var
[root@localhost ~]#
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
[root@localhost ~]# cat /etc/httpd/conf/httpd.conf | grep -v "^#" | grep httpd-php
AddType application/x-httpd-php .php
[root@localhost ~]#
编写php测试页面
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.php
[root@localhost html]# cat index.php
<?php
phpinfo();
?>
[root@localhost html]#
重启httpd
[root@localhost ~]# service httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[确定]
[root@localhost ~]#
浏览器访问:
安装Nagios------安装Nagios核心程序
创建组和用户:
[root@localhost ~]# groupadd nagios
[root@localhost ~]# useradd -g nagios nagios
[root@localhost ~]# id nagios
uid=501(nagios) gid=501(nagios) 组=501(nagios)
[root@localhost ~]#
上传nagios相关安装包:
[root@localhost ~]# ls
anaconda-ks.cfg install.log.syslog nrpe-2.15.tar.gz 视频 下载
Firefox_wallpaper.png nagios-4.2.4.tar.gz 公共的 图片 音乐
install.log nagios-plugins-2.2.1.tar.gz 模板 文档 桌面
[root@localhost ~]#
解压nagios:
[root@localhost ~]# tar zxf nagios-4.2.4.tar.gz
切换目录
[root@localhost ~]# cd nagios-4.2.4
[root@localhost nagios-4.2.4]#
检测环境并指定安装路径
[root@localhost nagios-4.2.4]# mkdir -p /usr/local/nagios
[root@localhost nagios-4.2.4]# ./configure --prefix=/usr/local/nagios
编译
[root@localhost nagios-4.2.4]# make all
安装Nagios程序的主要文件
[root@localhost nagios-4.2.4]# make install
安装Nagios服务init脚本
[root@localhost nagios-4.2.4]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
*** Init script installed ***
[root@localhost nagios-4.2.4]#
安装Nagios配置文件目录
[root@localhost nagios-4.2.4]# make install-config
安装Nagios网页配置文件
[root@localhost nagios-4.2.4]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
if [ 0 -eq 1 ]; then \
ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \
fi
*** Nagios/Apache conf file installed ***
[root@localhost nagios-4.2.4]#
安装nagios权限相关
[root@localhost nagios-4.2.4]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
[root@localhost nagios-4.2.4]#
生成Nagios网页认证文件并创建用户
方法一(比较直接简单):
[root@localhost nagios-4.2.4]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@localhost nagios-4.2.4]#
方法二:
为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf 文件最后添加如下信息:
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
#用于此目录访问身份文件
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
重启httpd
[root@localhost nagios-4.2.4]# htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@localhost nagios-4.2.4]# service httpd
重新启动nagios和Apache
[root@localhost nagios-4.2.4]# service httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[确定]
[root@localhost nagios-4.2.4]# service nagios restart
Running configuration check...
Stopping nagios:No lock file found in /usr/local/nagios/var/nagios.lock
Starting nagios: done.
[root@localhost nagios-4.2.4]#
安装nagios-plugins
解压
[root@localhost ~]# tar zxf nagios-plugins-2.2.1.tar.gz
[root@localhost ~]# cd nagios-plugins-2.2.1
[root@localhost nagios-plugins-2.2.1]#
检查环境并指定安装路径
[root@localhost nagios-plugins-2.2.1]# ./configure --prefix=/usr/local/nagios
编译安装
[root@localhost nagios-plugins-2.2.1]# make && make install
浏览器访问: