nagios系列(一)centos6.5环境部署nagios服务端


nagios软件安装包存放目录:/home/oldboy/tools
nagios服务安装目录:/usr/local/nagios


1、配置yum源
echo "------ step 1: config yum ------"
cd /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo


报错:
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
--2016-07-21 09:10:05--  http://mirrors.aliyun.com/repo/Centos-6.repo
Resolving mirrors.aliyun.com... failed: Name or service not known.
wget: unable to resolve host address “mirrors.aliyun.com”
是不能解析域名,编辑DNS即可
[root@node4 yum.repos.d]# vim /etc/resolv.conf 
nameserver 192.168.8.251


2、配置profile文件
echo "------ step 2: config  profile------"
echo 'export LC_ALL=C'>> /etc/profile
source /etc/profile


3、停用防火墙和selinux
echo "------ step 3: stop iptables and selinux------"
/etc/init.d/iptables stop
chkconfig iptables off
setenforce 0
也可以用脚本
if [ -f /etc/selinux/config ]; then
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
setenforce 0
fi


4、时间同步
echo "------ step 4: config time sync------"
/usr/sbin/ntpdate pool.ntp.org
echo '#time sync by jack at 2016-7-21'>>/var/spool/cron/root
echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1'>>/var/spool/cron/root
crontab -l


5、安装依赖包
echo "------ step 5: install gcc and lamp env etc------"
yum install gcc glibc glibc-common -y
yum install gd gd-devel -y
yum install httpd php php-gd -y
yum install mysql* -y


6、添加nagios用户和组
echo "------ step 6: add nagios  user and group------"
/usr/sbin/useradd -m nagios
#/usr/sbin/useradd apache
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache


7、安装服务端软件
echo "------ step 7: download and install nagios------"
[ ! -f oldboy_training_nagios_soft.zip ] && exit 1
unzip oldboy_training_nagios_soft.zip 
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
cd ../
echo "------ step 8: config web auth------"
htpasswd -cb /usr/local/nagios/etc/htpasswd.users jack jack


9、安装插件
echo "------ step 9: install 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
cd ../
ls /usr/local/nagios/libexec/|wc -l


报错:
check_http.c:312: error: ‘ssl_version’ undeclared (first use in this function)
check_http.c:312: error: (Each undeclared identifier is reported>


解决办法:
yum install -y openssl*


echo "------ step 10: install 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 ..


10、启动nagios和apache
echo "------ step 11: startup service and check------"
/etc/init.d/nagios start
/etc/init.d/httpd start
echo -----------
lsof -i tcp:80
echo ----------
ps -ef|grep nagios
echo "NAGIOS is successfully installed."

echo ok


hosts.cfg文件定义:


services.cfg文件说明:









原文地址:https://www.cnblogs.com/reblue520/p/6239771.html