1、更换Yum源163
cd /etc/yum.repos.d/
mv CentOS-Base.repo{,.bak}
wget http://mirrors.163.com/.help/CentOS-Base-163.repo
yum makecache
2、LAMP环境优化编译安装,都加了简单优化选项,可以直接当LAMP环境的网站使用
apache安装
cd /usr/local/src
wget http://mirrors.sohu.com/apache/httpd-2.2.21.tar.bz2
yum -y install openssl openssl-devel
tar jxvf httpd-2.2.21.tar.bz2
cd httpd-2.2.21
./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --enable-rewrite --enable-deflate --enable-expires
make && make install
cd ..
为了方便以后安装其它需要sql的监控服务,装上mysql
wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.57.tar.gz
groupadd mysql
useradd mysql -g mysql -s /sbin/nologin
tar zxvf mysql-5.1.57.tar.gz
yum -y install ncurses ncurses-devel
./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --sysconfdir=/etc --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-unix-socket-path=/tmp/mysql.sock --enable-assembler --without-debug --with-plugins=utf8,gbk --with-plugins=innobase
make && make install
cp my-small.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql.server
chmod 755 /etc/init.d/mysql.server
vi /etc/init.d/mysql.server
46行 basedir=/usr/local/mysql
47行 datadir=/usr/local/mysql/var
nagios3以后版本需要php的支持
PHP的安装
wget http://mirrors.sohu.com/php/php-5.3.6.tar.bz2
因为需要有图片产生,所以先需要php的gd库支持
wget ftp://217.146.241.3/pub/linux/lib/gd-2.0.33.tar.gz
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel libXpm libXpm-devel
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr/local/gd2 --with-png --with-freetype --with-jpeg
make && make install
编译php
tar jxvf php-5.3.6.tar.bz2
cd php-5.3.6
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --enable-mbstring=cn --enable-force-cgi-redirect --enable-ftp -with-gd -with-jpeg -with-zlib -with-png -with-freetype --disable-debug --enable-inline-optimization --enable-sockets --enable-bcmath
make && make install
增加php与apache的关联
vi /usr/local/apache2/conf/httpd.conf
确认有这样一行LoadModule php5_module modules/libphp5.so添加:AddType application/x-httpd-php .php
修改apache的运行用户和组为nagios
phpinfo测试下是否成功
nagios的安装
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.2.3/nagios-3.2.3.tar.gz
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
wget http://cdnetworks-kr-1.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz
groupadd nagios
useradd nagios -g nagios
tar zxvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios
mkdir -p /etc/httpd/conf.d/
make all //编译
make install //安装nagios主要程序,cgi和html文件等
make install-init //安装nagios启动脚本
make install-config //将配置文件的例子复制到nagios配置文件里
make install-commandmode //配置nagios目录权限。
make install-webconf 因为这个命令执行的时候,会在/etc/httpd/conf.d/创建 nagios.conf文件
cat /etc/httpd/conf.d/nagios.conf >>/usr/local/apache2/conf/httpd.conf
安装nagios插件
tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios/
make && make install
安装完成后,会在/usr/local/nagios/ 目录下面生成libexe插件目录,nagios所有的插件都会在这个目录里面。
chown -R nagios.nagios /usr/local/nagios/
安装nrpe
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure && make all
make install-plugin //安装check_nrpe插件
make install-daemon
make install-daemon-config
make install-xinetd //安装xinetd脚本
yum -y install xinetd
vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1 注释掉 allowshosts =192.168.1.221 添加监控主机,一般为nagios服务器的Ip
vi /etc/services
添加两行
nrpe 5666/tcp
nrpe 5666/udp
启动xinetd
/etc/init.d/xinetd start 看看5666端口是否开启
添加apache授权用户 -c选项为创建文件,创建第二个选项不需要
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users itv1
修改cgi.cfg #vi /usr/local/nagios/etc/cgi.cfg
找到这几行,后面添加 erbin用户,可以自己定义用户,使用“,”隔开
authorized_for_system_information=nagiosadmin,itv1
authorized_for_configuration_information=nagiosadmin,itv1
authorized_for_system_commands=nagiosadmin,itv1
authorized_for_all_services=nagiosadmin,itv1
authorized_for_all_hosts=nagiosadmin,itv1
authorized_for_all_service_commands=nagiosadmin,itv1
authorized_for_all_host_commands=nagiosadmin,itv1