|
| 1 | +#!/bin/bash |
| 2 | +yum install -y make gcc bc openssl-devel net-snmp net-snmp-devel net-snmp-utils |
| 3 | + |
| 4 | +/usr/sbin/useradd -s /sbin/nologin nagios |
| 5 | + |
| 6 | +tar zxvf nagios-plugins-2.1.1.tar.gz |
| 7 | +cd nagios-plugins-2.1.1 |
| 8 | +./configure && make && make install |
| 9 | +cd .. |
| 10 | +chown nagios.nagios /usr/local/nagios |
| 11 | +chown -R nagios.nagios /usr/local/nagios/libexec |
| 12 | + |
| 13 | +tar zxvf nrpe-2.15.tar.gz |
| 14 | +cd nrpe-2.15 |
| 15 | +./configure && make all && make install-plugin && make install-daemon && make install-daemon-config |
| 16 | +cd .. |
| 17 | + |
| 18 | +Network_Card1=`/sbin/ip a|grep -B1 221.111 |grep inet | awk -F ' ' '{print $7}'` |
| 19 | +Network_Card2=`/sbin/ip a|grep -B1 192.168 |grep inet | awk -F ' ' '{print $7}'` |
| 20 | + |
| 21 | + |
| 22 | +cat >/usr/local/nagios/etc/nrpe.cfg<<EOF |
| 23 | +log_facility=daemon |
| 24 | +pid_file=/var/run/nrpe.pid |
| 25 | +server_port=5666 |
| 26 | +nrpe_user=nagios |
| 27 | +nrpe_group=nagios |
| 28 | +allowed_hosts=127.0.0.1,192.168.1.12 |
| 29 | +dont_blame_nrpe=0 |
| 30 | +allow_bash_command_substitution=0 |
| 31 | +debug=0 |
| 32 | +command_timeout=60 |
| 33 | +connection_timeout=300 |
| 34 | +command[check_users]=/usr/local/nagios/libexec/check_users -w 2 -c 6 |
| 35 | +command[check_load]=/usr/local/nagios/libexec/check_load -w 19,15,12 -c 30,25,20 |
| 36 | +command[check_/]=/usr/local/nagios/libexec/check_disk -w 12% -c 10% -p / |
| 37 | +command[check_/data]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /data |
| 38 | +command[check_/opt]=/usr/local/nagios/libexec/check_disk -w 12% -c 10% -p /opt |
| 39 | +command[check_ss]=/usr/local/nagios/libexec/check_ss.sh 1000 3000 |
| 40 | +command[check_$Network_Card1]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C nagios_test@1128 -H 127.0.0.1 -N $Network_Card1 -w 5000,5000 -c 10000,10000 -K -B |
| 41 | +command[check_$Network_Card2]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C nagios_test@1128 -H 127.0.0.1 -N $Network_Card2 -w 15000,15000 -c 30000,30000 -K -B |
| 42 | +command[check_disk]=/usr/local/nagios/libexec/check_disk.sh 90 90 95 |
| 43 | +command[check_secure]=/usr/local/nagios/libexec/check_secure.sh 15 |
| 44 | +EOF |
| 45 | + |
| 46 | + |
| 47 | +###系统判断 |
| 48 | +if [ -f /etc/redhat-release ];then |
| 49 | + OS=CentOS |
| 50 | +check_OS1=`cat /etc/redhat-release | awk -F '[ ]+' '{print $3}' | awk -F '.' '{print $1}'` |
| 51 | +check_OS2=`cat /etc/redhat-release | awk -F '[ ]+' '{print $4}' | awk -F '.' '{print $1}'` |
| 52 | +if [ "$check_OS1" == "6" ];then |
| 53 | + OS=CentOS6 |
| 54 | +fi |
| 55 | +if [ "$check_OS2" == "7" ];then |
| 56 | + OS=CentOS7 |
| 57 | +fi |
| 58 | +elif [ ! -z "`cat /etc/issue | grep bian`" ];then |
| 59 | + OS=Debian |
| 60 | +elif [ ! -z "`cat /etc/issue | grep Ubuntu`" ];then |
| 61 | + OS=Ubuntu |
| 62 | +else |
| 63 | + echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m" |
| 64 | +fi |
| 65 | + |
| 66 | +if [ $OS == 'CentOS6' ];then |
| 67 | +cat >/etc/snmp/snmpd.conf<<EOF |
| 68 | +com2sec notConfigUser 127.0.0.1 nagios_test@1128 |
| 69 | +com2sec notConfigUser 192.168.1.12 nagios_test@1128 |
| 70 | +group notConfigGroup v1 notConfigUser |
| 71 | +group notConfigGroup v2c notConfigUser |
| 72 | +view systemview included .1.3.6.1.2.1.1 |
| 73 | +view systemview included .1.3.6.1.2.1.2 |
| 74 | +view systemview included .1.3.6.1.2.1.25.1.1 |
| 75 | +view all included .1 80 |
| 76 | +access notConfigGroup "" any noauth exact all none none |
| 77 | +dontLogTCPWrappersConnects yes |
| 78 | +EOF |
| 79 | + |
| 80 | + |
| 81 | +fi |
| 82 | + |
| 83 | + |
| 84 | +if [ $OS == 'CentOS7' ];then |
| 85 | +cat >/etc/snmp/snmpd.conf<<EOF |
| 86 | +com2sec notConfigUser 127.0.0.1 nagios_test@1128 |
| 87 | +com2sec notConfigUser 192.168.1.12 nagios_test@1128 |
| 88 | +group notConfigGroup v1 notConfigUser |
| 89 | +group notConfigGroup v2c notConfigUser |
| 90 | +view systemview included .1.3.6.1.2.1.1 |
| 91 | +view systemview included .1.3.6.1.2.1.25.1.1 |
| 92 | +access notConfigGroup "" any noauth exact all none none |
| 93 | +view all included .1 80 |
| 94 | +syslocation Unknown (edit /etc/snmp/snmpd.conf) |
| 95 | +syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) |
| 96 | +dontLogTCPWrappersConnects yes |
| 97 | +smuxpeer .1.3.6.1.4.1.674.10892.1 |
| 98 | +EOF |
| 99 | +chmod 755 /bin/which |
| 100 | + |
| 101 | + |
| 102 | +fi |
| 103 | + |
| 104 | +#############snmp##################### |
| 105 | +##cp -rf snmpd.conf /etc/snmp/ |
| 106 | +service snmpd restart |
| 107 | +chkconfig snmpd on |
| 108 | +##systemctl enable snmpd.service |
| 109 | +cp -rf sh/*.sh /usr/local/nagios/libexec/ |
| 110 | +chown nagios.nagios /usr/local/nagios/libexec/*.sh |
| 111 | +chmod -R 777 /usr/local/nagios/libexec/*.sh |
| 112 | +########################nagios############################ |
| 113 | +ps -ef | grep 'nagios' | grep 'nrpe' | grep -v 'grep' | awk '{print $2}' | xargs kill |
| 114 | +/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d |
| 115 | +echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local |
| 116 | + |
| 117 | +mkdir -p /opt/sh/ |
| 118 | +cat >/opt/sh/ssh_secure.sh<<EOF |
| 119 | +echo "Nov 10 18:07:37 test sshd[11079]: Accepted password for root from 192.168.1.1 port 59557 ssh2" > /tmp/ssh.log |
| 120 | +tail -n 99 /var/log/secure | grep sshd | grep ssh2 >> /tmp/ssh.log |
| 121 | +echo "\$(date)" |
| 122 | +EOF |
| 123 | + |
| 124 | +cat >> /var/spool/cron/root << EOF |
| 125 | +*/3 * * * * /opt/sh/ssh_secure.sh |
| 126 | +EOF |
| 127 | +chmod 777 /opt/sh/ssh_secure.sh |
| 128 | +chmod 600 /var/spool/cron/root |
| 129 | +/sbin/service crond restart |
| 130 | + |
| 131 | + |
| 132 | + |
0 commit comments