|NO.Z.00036|——————————|^^ 构建 ^^|——|Nagios构建.V2|——|3台server|
一、构建Nagios:实验环境
### --- 硬件环境
~~~ HA-server1:10.10.10.11:nagios服务端
### --- 在HA-server1下:10.10.10.11下配置
### --- 解决安装Nagios的依赖关系: // 需要注意*gb*必须按照视屏的方式进行后安装
[root@server11 ~]# yum install -y httpd gcc glibc glibc-common php php-mysql //没有安装mysql,把gd库去掉,因为gd库的分支是比较多多的,在nagios只需要放入cd1里的gd库即可,cd2里也是有一定固定gd库的,若在这里都是用新的gd库的话,会使用cd1 cd2都会调取安装。这里yum源里只采用了cd1的光盘,cd2是没有的,所以它会报错。
Install 5 Package(s)
Total download size: 4.0 M
Installed size: 13 M
Installed:
php.x86_64 0:5.3.3-47.el6 php-mysql.x86_64 0:5.3.3-47.el6
Dependency Installed:
php-cli.x86_64 0:5.3.3-47.el6 php-common.x86_64 0:5.3.3-47.el6 php-pdo.x86_64 0:5.3.3-47.el6
### --- 安装gd库
[root@server11 ~]# cd /mnt/cdrom/Packages/
[root@server11 Packages]# yum install -y *gd*
Install 31 Package(s)
Total size: 19 M
Total download size: 11 M
Installed size: 57 M
Installed:
cgdcbxd.x86_64 0:1.0.1-2.el6 gd.x86_64 0:2.0.35-11.el6 gdb-gdbserver.x86_64 0:7.2-90.el6
gdisk.x86_64 0:0.8.10-1.el6 gdk-pixbuf2-devel.x86_64 0:2.24.1-6.el6_7 gdm-plugin-smartcard.x86_64 1:2.30.4-64.el6
hunspell-gd.noarch 0:1.0.0-0.3.rc.2.el6 libgdata-devel.x86_64 0:0.6.4-2.el6 php-gd.x86_64 0:5.3.3-47.el6
Dependency Installed:
autoconf.noarch 0:2.63-5.1.el6 automake.noarch 0:1.11.1-4.el6 docbook-style-dsssl.noarch 0:1.79-10.el6 docbook-style-xsl.noarch 0:1.75.2-6.el6
docbook-utils.noarch 0:0.6.14-25.el6 glib2-devel.x86_64 0:2.28.8-5.el6 gnutls-devel.x86_64 0:2.8.5-19.el6_7 gtk-doc.noarch 0:1.11-5.1.el6
libXpm.x86_64 0:3.5.10-2.el6 libcgroup.x86_64 0:0.40.rc1-17.el6_7 libgcrypt-devel.x86_64 0:1.4.5-11.el6_4 libgpg-error-devel.x86_64 0:1.7-4.el6
libmnl.x86_64 0:1.0.2-3.el6 libpng-devel.x86_64 2:1.2.49-2.el6_7 libsoup-devel.x86_64 0:2.34.3-5.el6 libxml2-devel.x86_64 0:2.7.6-21.el6
lynx.x86_64 0:2.8.6-27.el6 openjade.x86_64 0:1.3.2-36.el6 opensp.x86_64 0:1.5.2-12.1.el6 pam_pkcs11.x86_64 0:0.6.2-15.el6
perl-SGMLSpm.noarch 0:1.03ii-21.el6 zlib-devel.x86_64 0:1.2.3-29.el6
Complete!
二、创建运行身份
### --- 创建运行身份
[root@server11 ~]# groupadd nagcmd // 创建运行组 //在nagios下它的用户名和组名必须为它,而cacti下可以自定义。因为在后期运行的脚本中,调用的组名和用户必须为它
[root@server11 ~]# useradd -m nagios // 创建运行用户nagios
[root@server11 ~]# usermod -a -G nagcmd nagios // 将nagios用户添加到nagcmd组中
[root@server11 ~]# usermod -a -G nagcmd apache // 将Apache用户添加到nagcmd组中
三、编译安装nagios
### --- 将nagios.iso上传到服务器
[root@server11 ~]# mkdir /iso
[root@server11 ~]# mount -o loop nagios.iso /iso/
[root@server11 ~]# cp -a /iso/* .
[root@server11 ~]# ls
nagios.iso nrpe-2.12.tar.gz NSClient++-0.3.8-Win32.msi
nagios-3.3.1.tar.gz nagios-plugins-1.4.14.tar.gz nrpe-2.8.1.tar.gz NSClient++-0.3.8-x64.msi
### --- 编译安装nagios
[root@server11 ~]# tar -zxvf nagios-3.3.1.tar.gz // 解压Nagios源码包
[root@server11 ~]# cd nagios
### --- Nagios Makefile文件--with-command-group=nagcmd定义到之前的组为nagcmd --enable-event-broke:输出当前重定向把它打断;后期需要把它数据写入数据库的话,需要重新编译核心组件的,所以提前开启
[root@server11 nagios]# ./configure --with-command-group=nagcmd --enable-event-broker
*** Configuration summary for nagios 3.3.1 07-25-2011 ***:
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs. // 提示:需要make all 安装主程序和CGIst
[root@server11 nagios]# make all // 安装主程序和CGIst
make install
- This installs the main program, CGIs, and HTML files // 安装主程序CGIst和HEML网页文件
make install-init
- This installs the init script in /etc/rc.d/init.d // 安装install-init位置/etc/rc.d/init.dnagios的启动脚本
make install-commandmode // 安装配置文件权限和目录权限
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc // 安装了一些配置模板的权限到/usr/local/nagios/etc目录下
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
make install-webconf // 为nagios网页接口安装了Apache的配置文件
- This installs the Apache config file for the Nagios
web interface
make install-exfoliation
- This installs the Exfoliation theme for the Nagios
web interface
make install-classicui
- This installs the classic theme for the Nagios
web interface
*** Support Notes *******************************************
Enjoy.
[root@server11 nagios]# make install
[root@server11 nagios]# make install-init
[root@server11 nagios]# make install-commandmode
[root@server11 nagios]# make install-config
[root@server11 nagios]# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost // 报警邮件的收件地址;写入个人邮箱,配置邮箱域;暂时不修改
}
[root@server11 nagios]# make install-webconf // 安装web的模板
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf //在这个目录下/etc/httpd/conf.d/nagios.conf
[root@server11 nagios]# vim /etc/httpd/conf.d/nagios.conf // 查看该配置文件,不修改
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" // 定义了一个脚本别名,没有什么意义
<Directory "/usr/local/nagios/sbin"> // 对目录做了权限。
# SSLRequireSSL
Options ExecCGI // 运行轮询CGI脚本
AllowOverride None // 不开启特殊权限
Order allow,deny // 运行方向所有
Allow from all
AuthName "Nagios Access" // 做了一个身份认证
AuthType Basic // 认证类型为basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users // 身份认证文件路径/usr/local/nagios/etc/htpasswd.users,默认不会生成,Apache在做用户访问控制的时候,通过htpasswd生成的一个文件。
Require valid-user
[root@server11 nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin //这个用户必须是nagiosadmin,若是更改的话,后期会出现错误
New password: 123
Re-type new password: 123
Adding password for user nagiosadmin
[root@server11 nagios]# service httpd restart
四、编译安装nagios-plugins(插件管理器)
[root@server11 ~]# tar -zxvf nagios-plugins-1.4.14.tar.gz
[root@server11 ~]# cd nagios-plugins-1.4.14
[root@server11 nagios-plugins-1.4.14]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql --enable-perl-modules // --with-mysql制定允许后期运行mysql --enable-perl-modules:指定允许运行开启库模块
--with-apt-get-command:
--with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: no
--with-openssl: no
--with-gnutls: no
--enable-extra-opts: no
--with-perl: /usr/bin/perl
--enable-perl-modules: yes
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
--enable-libtap: no
[root@server11 nagios-plugins-1.4.14]# make && make install
五、配置并启动Nagios
[root@server11 ~]# chkconfig --add nagios // 添加到开启自启来
[root@server11 ~]# chkconfig nagios on // 设置开机自启
[root@server11 ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //检测一下nagios的配置文件是否正确
Total Warnings: 0 // 为0
Total Errors: 0 // 为0 说明配置正确
Things look okay - No serious problems were detected during the pre-flight check
[root@server11 ~]# service nagios start
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
分类:
cdv001-lbchac
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通