本文共 6755 字,大约阅读时间需要 22 分钟。
前置准备:
yum install -y gcc gcc-c++ gcc-devel cmake
安装apr:
tar xvf apr-1.5.0.tar.gzcd apr-1.5.0./configure --prefix=/usr/local/aprmake && make install
安装apr-util:
tar xvf apr-util-1.5.3.tar.gzcd apr-util-1.5.3./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install
安装pcre:
tar xvf pcre-8.33.tar.gzcd pcre-8.33./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-utilmake && make install
安装Apache:
tar xvf httpd-2.4.7.tar.gzcd httpd-2.4.7./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewritemake && make install
启动Apache:
cd /usr/local/httpd/bin/./apachectl start
验证Apache:
netstat -antl | grep 80
解压并编译安装:
tar xf mysql-5.6.10.tar.gzcd mysql-5.6.10cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql -DMYSQL_DATADIR:PATH=/database -DWITH_DEBUG:BOOL=on -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_INNOBASE_STORAGE_ENGINE:BOOL=on -DWITH_PARTITION_STORAGE_ENGINE:BOOL=onmake && make install
解决常见错误:
yum install -y ncurses-develrm CMakeCache.txtmake && make install
新建MySQL用户及目录:
mkdir /databasemkdir /usr/local/mysql/var/log -pmkdir /usr/local/mysql/var/run -pmkdir /usr/local/mysql/etcmkdir /usr/local/mysql/binloguseradd mysqlchown -R mysql:mysql /database /usr/local/mysql/
修改MySQL配置文件:
cp support-files/my-default.cnf /usr/local/mysql/etc/my.cnfvim /usr/local/mysql/etc/my.cnf
初始化数据库:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/database --user=mysql
添加MySQL自启动:
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql5.6dchkconfig --add mysql5.6dchkconfig mysql5.6d onservice mysql5.6d start
设置root密码:
/usr/local/mysql/bin/mysql -urootmysql> update user set password='123654' where user='root';
安装mhash:
tar jxvf mhash-0.9.9.9.tar.bz2cd mhash-0.9.9.9./configuremake && make install
安装libmcrypt:
tar xf libmcrypt-2.5.6.tar.gzcd libmcrypt-2.5.6./configuremake && make install
安装zlib:
tar xf zlib-1.2.5.1.tar.gzcd zlib-1.2.5.1CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/zlibmake && make install
安装libpng:
tar xf libpng-1.2.47.tar.xzcd libpng-1.2.47CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/libpngmake && make install
安装jpeg:
tar xf jpeg-6b.tar.gzcd jpeg/src/cp /usr/share/libtool/config/config.guess config.guesscp /usr/share/libtool/config/config.sub config.subCFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/jpeg --enable-shared --enable-staticmake && make install
安装freetype:
tar jxvf freetype-2.3.11.tar.bz2cd freetype-2.3.11./configure --prefix=/usr/local/freetype --enable-sharedmake && make install
安装GD库:
tar xf gd-2.0.35.tar.gzcd gd/2.0.35/./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetypemake && make install
在监控主机上安装Nagios:
tar xvf nagios-3.4.3.tar.gzcd nagios./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/local/gd/lib --with-gd-inc=/usr/local/gd/includemake all && make installmake install-initmake install-commandmodemake install-config
安装Nagios插件:
tar xvf nagios-plugins-1.4.16.gzcd nagios-plugins-1.4.16./configure --prefix=/usr/local/nagios/make && make install
安装NRPE:
tar xf nrpe-2.14.tar.gzcd nrpe-2.14./configuremake all && make install-pluginmake install-daemonmake install-daemon-config
Apache配置:
vim /usr/local/httpd/conf/httpd.conf
添加Nagios CGI路径:
# settings for nagiosScriptAlias /nagios/cgi-bin /usr/local/nagios/sbinAuthType Basic Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user Alias /nagios /usr/local/nagios/shareAuthType Basic Options None AllowOverride None Order allow,deny Allow from all AuthName "nagios Access" AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user
创建admin用户并设置密码:
/usr/local/httpd/bin/htpasswd -c /usr/local/nagios/etc/htpasswd admin
在被监控机上安装Nagios插件:
tar xvf nagios-plugins-1.4.16.gzcd nagios-plugins-1.4.16./configure --prefix=/usr/local/nagios/make && make install
安装NRPE:
tar xf nrpe-2.14.tar.gzcd nrpe-2.14./configuremake all && make install-pluginmake install-daemonmake install-daemon-config
配置NRPE:
vim /usr/local/nagios/etc/nrpe.cfg
启动NRPE:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
修改SNMP配置文件:
vim /usr/local/nagios/etc/snmp/snmp.conf
添加监控主机:
com2sec notConfigUser 192.168.1.124 publicview all .1 80access notConfigGroup "" any noauth exact all none none
重启SNMP服务:
service snmpd restart
创建自定义配置文件:
cd /usr/local/nagios/etc/objects/vim hosts.cfg
定义主机:
define host { use linux-server host_name linux-43 alias test address 192.168.1.43} 创建主机组:
vim hostgroups.cfgdefine hostgroup { hostgroup_name zj-servers alias zj-servers members linux-43} 创建服务:
vim services.cfgdefine service { use local-service host_name linux-43 service_description check-host-alive check_command check-host-alive} 修改Nagios主配置文件:
vim /usr/local/nagios/etc/nagios.cfg
添加配置文件路径:
cfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/nagios/etc/objects/hostgroups.cfgcfg_file=/usr/local/nagios/etc/objects/services.cfg
安装依赖软件:
yum install rrdtool* -y
创建数据库:
mysql -uroot -p123654create database cacti;grant all privileges on cacti.* to "cactier"@"localhost' identified by '123654';flush privileges;
安装Cacti:
tar xvf cacti-0.8.8b.tar.gzcd cacti-0.8.8bmv cacti-0.8.8b /usr/local/httpd/htdocs/cacticd /usr/local/httpd/htdocs/cacti/mysql -ucactier -p123654 cacti < cacti.sql
修改Cacti配置文件:
vim include/config.php
启动Cacti服务:
crontab -e*/5 * * * * /usr/local/php/bin/php /usr/local/httpd/htdocs/cacti/poller.php > /dev/null
安装ntop:
tar xvf ntop-4.0.1.tar.gzcd ntop-4.0.1./autogen.sh
编译安装:
./configure --prefix=/usr/local/ntopmake && make install
设置ntop密码:
/usr/local/ntop/bin/top -u ntop -c -d
添加开机自启动:
echo "/usr/local/ntop/bin/top -u ntop -c -d" >> /etc/rc.local
安装设置插件:
tar xf settings-v0.7-1.tgz -C /usr/local/httpd/htdocs/cacti/pluginsvim /usr/local/httpd/htdocs/cacti/include/config.php$plugins[] = "settings";
激活插件:
Console > Settings > settings
安装monitor插件:
tar xf monitor-v1.3-1.tgz -C /usr/local/httpd/htdocs/cacti/pluginsvim /usr/local/httpd/htdocs/cacti/include/config.php$plugins[] = "monitor";
安装thold插件:
tar xf thold-v0.5.0.tgz -C /usr/local/httpd/htdocs/cacti/pluginsvim /usr/local/httpd/htdocs/cacti/include/config.php$plugins[] = "thold";
通过以上步骤,您已经成功搭建了一个基于 CentOS 6.5 的LAMP环境,并完成了Nagios、Cacti、ntop等监控工具的安装与配置。系统已实现对多台服务器的全面监控,并通过邮件报警等方式实现了自动化监控。
转载地址:http://jzcfk.baihongyu.com/