通过rz或sftp命令将CentOS-Base.repo.oldboy上传到linux上
/bin/cp CentOS-Base.repo.oldboy /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.save
/bin/cp CentOS-Base.repo.oldboy CentOS-Base.repo
这样yum安装源就配好了
解决perl编译问题:
echo 'export LC_ALL=C'>> /etc/profile
source /etc/profile #←使修改生效
关闭nagios server iptables防火墙
/etc/init.d/iptables stop
禁止自启动
chkconfig iptables off
解决时间同步
/usr/sbin/ntpdate pool.ntp.org
安装nagios需要的基础软件包
yum install gcc glibc glibc-common -y
yum install gd gd-devel -y
yum install httpd php -y
vi /etc/yum.conf
more /etc/yum.repos.d/CentOS-Base.repo
创建nagios需要的用户及组
/usr/sbin/useradd -m nagios
/usr/sbin/useradd apache -M -s /sbin/nologin
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
上传软件包到指定目录或通过URL下载
mkdir -p /home/rhy/tools/nagios
cd /home/rhy/tools/nagios
rz -y #从本地上传oldboytraining_nagiossoft.zip
安装nagios软件包
cd /home/rhy/tools/nagios
unzip oldboytraining_nagiossoft.zip #←使用unzip解压
tar xzf nagios-
cd nagios-
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
安装nagios web配置文件及创建登陆用户
#安装nagios web配置文件
make install-webconf
cd ../
注:如果为单独的apache源代码编译,则操作如下
mkdir -p /etc/httpd/conf.d/
make install-webconf
cp /etc/httpd/conf.d/nagios.conf /usr/local/apache2/conf/extra/
假定apache安装路径/usr/local/apache2,以下同,不在提及。
编辑vi /usr/local/apache2/conf/httpd.conf 增加
Include conf/extra/nagios.conf
;如果为yum安装的httpd 上面几行绿色的不需要操作。
#创建nagios监控界面登入需要的用户名及密码
htpasswd -c /usr/local/nagios/etc/htpasswd.users oldboy
添加监控报警的接收email
vi /usr/local/nagios/etc/objects/contacts.cfg +35
修改如下行:
email nagios@localhost
改为:
email hyran@126.com
保存,退出。
注意:此功能依赖本机的sendmail服务,可执行service sendmail start 开启。(
可稍后再启动)
配置apache服务
vi /etc/httpd/conf/httpd.conf +231
启动apache并加入系统自启动:
service httpd start
chkconfig httpd on
检查apache port:
netstat -lntup|grep 80
tcp 0 0 :::80 :::* LISTEN
安装nagios插件软件包
tar zxzf nagios-plugins-
cd nagios-plugins-
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make
make install
cd ..
#此编译如遇到make: *** [all] Error 2 则configure加--with-mysql=/usr/local/mysql解决
检查插件个数:
ls /usr/local/nagios/libexec/|wc -l
63
#
添加到系统开机自启动
chkconfig --add nagios
chkconfig nagios on
验证nagios配置文件(检查语法)
/etc/init.d/nagios checkconfig #←用此方法检查需要需要做下特殊处理详见附录九
[root@linux training_soft]# /etc/init.d/nagios checkconfig
Running configuration check... OK.
不显示错误 用
vim /etc/init.d/nagios +178
把>后面的删掉即可
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
启动nagios
service nagios start或/etc/init.d/nagios start
出现问题
[root@linux ~]# /etc/init.d/nagios start
Starting nagios:su: warning: cannot change directory to /home/nagios: No such file or directory
需要建立目录
#mkdir –p /home/nagios
检查进程:
[root@nagiosserver nagios-plugins-
nagios 17686 1 0 21:29 ? 00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
关闭服务器开启的SElinux
setenforce 0 #使之直接生效,
然后编辑文件
vi /etc/selinux/config #修改SELINUX项为disabled
SELINUX=disabled #重起生效
或者
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
打开网页输入 虚拟机ip/nagios
安装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 ..