一、LAMP環(huán)境部署
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),大邑縣企業(yè)網(wǎng)站建設(shè),大邑縣品牌網(wǎng)站建設(shè),網(wǎng)站定制,大邑縣網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,大邑縣網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
1、安裝php
1.安裝yum源
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2.執(zhí)行yum安裝
yum --enablerepo=remi,remi-php55 install php php-devel php-common php-fpm php-opcache \
php-cli php-pear php-pdo php-MySQLnd php-sqlite php-pecl-memcached php-gd \
php-mbstring php-mcrypt php-xml php-openssl php-intl php-zmq -y
3.查看版本
php -v
2、安裝mysql(安裝之前先卸載掉系統(tǒng)自帶的版本)
1.安裝oracle官方y(tǒng)um源
rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
2.yum安裝
yum -y install mysql-server mysql
3.查看版本
mysql -V
3、Apache默認(rèn)系統(tǒng)已經(jīng)安裝,開(kāi)啟支持php頁(yè)面解析即可
1.修改配置文件
vim /etc/httpd/conf/httpd.conf
DirectoryIndex index.html index.php index.html.var
/etc/init.d/httpd restart
2.編輯測(cè)試頁(yè)進(jìn)行測(cè)試
cat index.php
phpinfo();
?>
二、nagios環(huán)境部署
1、下載源碼包
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz#_ga=1.84131165.51197378.1492996402
2、安裝依賴環(huán)境
yum install gcc gd gd-devel libpng libpng-devel libjpeg libjpeg-devel zlib zlib-devel openssl-devel -y
3、創(chuàng)建用戶
/usr/sbin/useradd -m -s /sbin/nologin nagios
4、編輯安裝主程序包
1.安裝
tar zxvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios
make all
make install //安裝nagios的主程序,CGI和HTML文件
make install-init //生成/etc/rc.d/init.d/nagios啟動(dòng)腳本
make install-config //安裝示例配置文件,路徑/usr/local/nagios/etc
make install-commandmode//設(shè)定相應(yīng)nagios工作目錄的權(quán)限
make install-webconf //安裝Nagios的WEB配置文件到Apache的conf.d目錄下
2.查看安裝是否成功
ls /usr/local/nagios/
bin etc libexec sbin share var
5、安裝插件包
1.安裝
tar zxvf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1/
./configure
make && make install
2.檢查安裝是否成功(如果下面有很多東西,說(shuō)明成功)
ls /usr/local/nagios/libexec/
6、創(chuàng)建nagios用戶,進(jìn)行web登錄(用戶必須是nagiosadmin,不然web頁(yè)面有的功能不能用)
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
7、web登錄測(cè)試
http://ip/nagios/
8、安裝NRPE(監(jiān)控別的主機(jī)需要的插件)
1.安裝
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12/
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
2.啟動(dòng)nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3.檢查是否成功(查看端口并連接自己測(cè)試,如果返回版本號(hào)說(shuō)明正常)
netstat -antp |grep nrpe
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 43336/nrpe
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.12
4.修改配置文件,讓監(jiān)控主機(jī)可以連接(修改客戶機(jī),服務(wù)端連接測(cè)試)
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,122.200.94.29
5.重啟nrpe
killall nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
6.在監(jiān)控端進(jìn)行測(cè)試,是否能成功連接被監(jiān)控端的nrpe
/usr/local/nagios/libexec/check_nrpe -H 122.200.94.43
NRPE v2.12
7.如果返回
Connection refused by host
8.解決:編輯客戶端的ssh文件,允許root可以直接登錄(一般ubuntu系統(tǒng)會(huì)出現(xiàn)這個(gè)問(wèn)題,centos默認(rèn)root可以登錄)
vim /etc/ssh/sshd_config
PermitRootLogin yes
/etc/init.d/ssh restart
注意:
在ubuntu下安裝nrpe之前需要安裝ssl(監(jiān)控端和被監(jiān)控端版本需要保持一致)
apt-get install libssl-dev libssl0.9.8
三:添加監(jiān)控
NRPE實(shí)際上是使用check_nrpe來(lái)遠(yuǎn)程調(diào)用NRPE,然后再由NRPE調(diào)用本地的插件,所以,一部分是在監(jiān)控機(jī)配置,用于加載定義NRPE要監(jiān)測(cè)的服務(wù),另一部分是在被監(jiān)控機(jī)配置,主要定義監(jiān)控的命令,具體操作如下
1.定義NRPE插件需要使用的命令(文件末尾添加如下內(nèi)容)
vim /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
2.一般監(jiān)控都定義在servers下面,所以在配置文件中開(kāi)啟一項(xiàng)參數(shù),將servers下的文件包含進(jìn)來(lái)
vim /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers
3.添加監(jiān)控主機(jī)及監(jiān)控的服務(wù)(servers默認(rèn)沒(méi)有,手動(dòng)創(chuàng)建)
cd servers
cat 200.cfg
#監(jiān)控的主機(jī)
define host{
use linux-server //調(diào)用的/usr/local/nagios/etc/objects/templates.cfg中已經(jīng)定義好的模塊(可以根據(jù)需求自己定義)
host_name122.200.94.200
alias 122.200.94.200
address 122.200.94.200
}
#監(jiān)控ping
define service{
use local-service
host_name 122.200.94.200
service_description Ping //web頁(yè)面展示的名稱
check_command check_nrpe!check_ping//使用check_nrpe模塊遠(yuǎn)程調(diào)用被監(jiān)控主機(jī)中定義好的命令,然后再調(diào)用本地的check_ping插件進(jìn)行監(jiān)控
}
#負(fù)載情況
define service{
use local-service
host_name 122.200.94.200
service_descriptionLoad
check_command check_nrpe!check_load
}
#所有進(jìn)程
define service{
use local-service
host_name 122.200.94.200
service_descriptionProcesses
check_command check_nrpe!check_total_procs
}
#當(dāng)前登錄的用戶
define service{
use local-service
host_name 122.200.94.200
service_description Users
check_command check_nrpe!check_users
}
#僵死的進(jìn)程
define service{
use local-service
host_name 122.200.94.200
service_descriptionZombie procs
check_command check_nrpe!check_zombie_procs
}
#swap使用
define service{
use local-service
host_name 122.200.94.200
service_descriptionSwap
check_command check_nrpe!check_swap
}
#Apache服務(wù)
define service{
use local-service
host_name 122.200.94.200
service_descriptionHTTP
check_command check_nrpe!check_http
}
#mysql服務(wù)
define service{
use local-service
host_name 122.200.94.200
service_description Mysql
check_command check_mysql!122.200.94.200!3306!root!passw0rd //check_mysql模塊,IP,端口,被監(jiān)控端授權(quán)用戶,授權(quán)密碼
}
#用以上方法監(jiān)控mysql,需要更改另外一個(gè)文件,定義mysql監(jiān)控命令,客戶端需要授權(quán)用戶
vim /usr/local/nagios/etc/objects/commands.cfg(文件末尾添加一下內(nèi)容)
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$
}
4.客戶端修改(被監(jiān)控端,監(jiān)控端監(jiān)控的各項(xiàng)服務(wù),都需要再此文件中指定具體命令,否則無(wú)法執(zhí)行)
vim /usr/local/nagios/etc/nrpe.cfg
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1
command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100%、
#服務(wù)端監(jiān)控客戶端的這些服務(wù),都需要在客戶端的nrpe.cfg文件中添加這些命令,daemon只運(yùn)行nrpe.cfg中所定義的命令
四、郵件報(bào)警
因?yàn)橄到y(tǒng)自帶的sendmail發(fā)送郵件延遲很大,所以使用sendEmail進(jìn)行發(fā)送郵件
1.下載
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
tar zxvf sendEmail-v1.56.tar.gz
cd sendEmail-v1.56
cp sendEmail /usr/bin/
chmod +x /usr/bin/sendEmail
2.在本地進(jìn)行發(fā)送測(cè)試
sendEmail -f hulin_yu@sina.com -t hulin_yu@126.com -s smtp.sina.com -u 'This is title' -m 'This is body' -xu 'hulin_yu@sina.com' -xp '123456'
Apr 27 16:02:17 nagios sendEmail[2413]: Email was sent successfully!
3.修改配置文件
vim /usr/local/nagios/etc/objects/commands.cfg
#將發(fā)送郵件部分更改為如下(這樣修改用Foxmail接受郵件不會(huì)出現(xiàn)亂碼問(wèn)題,否則會(huì)有亂碼)
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "----- 監(jiān)控通知 -----
告警類型: $NOTIFICATIONTYPE$
主機(jī)狀態(tài): $HOSTSTATE$
告警地址: $HOSTADDRESS$
告警時(shí)間: `date +%F_%H:%M:%S`
詳細(xì)信息:
$HOSTOUTPUT$" | /usr/bin/sendEmail -f hulin_yu@sina.com -t $CONTACTEMAIL$ -s smtp.sina.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu hulin_yu@sina.com -xp yhl940519! -o message-content-type=html -o message-charset=utf8
}
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "----- 監(jiān)控通知 -----
告警類型: $NOTIFICATIONTYPE$
告警服務(wù): $SERVICEDESC$
告警地址: $HOSTADDRESS$
服務(wù)狀態(tài): $SERVICESTATE$
告警時(shí)間: `date +%F_%H:%M:%S`
詳情信息:
$SERVICEOUTPUT$
" | /usr/bin/sendEmail -f hulin_yu@sina.com -t $CONTACTEMAIL$ -u "Nagios Warning" -s smtp.sina.com -xu hulin_yu@sina.com -xp yhl940519! -o message-content-type=html -o message-charset=utf8
}
此時(shí),基本的配置都已完成。