环境:A 2.6.32-431.el6.x86_64
安装准备:
修改yum源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
调整字符集:
echo "export LC_ALL=C">>/etc/profile
source /etc/profile
关闭iptables:
/etc/init.d/iptables stop
chkconfig iptables off
关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0 — SELinux以警告(permissive)模式运行
设定时间同步:
echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
crontab -l
安装web 程序:
yum install gcc glibc-common -y
yum install gd gd-devel -y
yum install httpd php php-gd mysql* -y
#有lamp就无需安装
创建用户和组:
useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www
注意:nagios和apache授权同一个用户组
上传相关软件包:
nagios-3.5.1.tar.gz 主程序
nagios-plugins-1.4.16.tar.gz 插件程序
nrpe-2.12.tar.gz 客户端nrpe守护进程
pnp-0.4.14.tar.gz rrdtool-1.2.14.tar.gz 画图web程序
check_iostat check_mysql ..等插件,默认没有
编译安装主程序:
tar xzf nagios-3.5.1.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
#初始化,生成启动脚本
make install-config
#安装目录许可,web文件
make install-commandmode
#安装配置文件模版
make install-webconf
#生成web.conf,等同于nagios在web界面登录的配置文件。
htpasswd -cb /usr/local/nagios/etc/htpasswd.users admin 123456
#生成用户,htpasswd -cb -c指定文件 -b非交互
#如果web是编译安装make install-webconf 执行会失败报错,且提示路径错误。
需手动配置:cp -ap sample-config/httpd.conf /application/apache/conf/extra/nagios.conf
echo "include /application/apache/conf/extra/nagios.conf" >>/application/apache/conf/httpd.conf
/application/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
注意:观察sample-config/httpd.conf配置文件的信息! 生成htpasswd.users 与httpd.conf 里的名要一致,且nagiosadmin与/usr/local/nagios/etc、cgi.cfg里的用户要一致!否则报错查看详细日志。
安装插件nagios-plugins-1.4.16.tar.gz
yum -y install perl-devel
#perl-devel是必须的
tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make && make install
cd ../
ls /usr/local/nagios/libexec/|wc -l
#根据环境安装不等的插件,多少没关系。
安装nrpe
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
cd ..
生产用于检测客户端的nrpe, 当然也用来检测自己
ls /usr/local/nagios/libexec/check_nrpe
启动apache nagios
/etc/init.d/nagios start
ps -ef | grep nagios
lsof -i :80
#注意nagios主进程没有端口,都是通过插件探测!
chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --list nagios
网页登录即可
转载于:https://blog.51cto.com/linuxboys/1595559