准备工作
-
设置yum安装源
yum默认会从国外站点下载,速度慢,需要更换为国内提供的yum源站点,设置步骤参考博文:https://mp.csdn.net/mdeditor/90738423# -
调整字符集
echo 'export LC_ALL=C' >> /etc/profile source /etc/profile
-
关闭防火墙
/etc/init.d/iptables stop chkconfig iptables off
-
关闭selinux
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config setenforce 0
-
定时时间同步
yum -y install ntp ntpdate /usr/sbin/ntpdate pool.ntp.org echo '#time sync by silly at 20190602'>> /var/spool/cron/root echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1'>>/var/spool/cron/root crontab -l
-
安装编译环境
安装的时候使用阿里云的yum源,无法安装gd gd-devel ,后来换成163的yum源可正常安装yum install gcc glibc glibc-common -y yum install gd gd-devel -y yum install httpd php php-gd -y yum install mysql* -y #非必须,不装的话 nagios安装完后不会产生数据库监控插件
安装nagios
-
创建用户和组
/usr/sbin/useradd -m nagios /usr/sbin/groupadd nagcmd /usr/sbin/usermod -a -G nagcmd nagios /usr/sbin/usermod -a -G nagcmd apache
-
安装nagios主程序
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 make install-commandmode make install-webconf
-
配置web的用户名和密码
htpasswd -cb /usr/local/nagios/etc/htpasswd.users silly 123456
-
安装nagios-plugins
yum -y install 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
查看插件个数
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
-
开启服务
/etc/init.d/nagios start /etc/init.d/httpd start
-
检查
lsof -i tcp:80 ps -ef|grep nagios
-
登录nagios界面
http://192.168.47.156/nagios