1.Expect 非交互批量管理分发
#!/usr/bin/expect
if { $argc !=2} {
send_user "usage: expect expect.exp file host\n "
exit
}
set file [lindex $argv 0]
set host [lindex $argv 1]
set password "666666"
spawn ssh-copy-id -i $file "-p 22 root@$host"
expect {
"yes/no" {send "yes\r";exp_continue}
"*password" {send "$password\r"}
}
expect eof
exit -onexit {
send_user "Oldboy say good bye to you!\n"
}
#使用方法
#!/bin/sh
. /etc/init.d/functions
for ip in 10 11 15 16
do
expect expect.exp ~/.ssh/id_dsa.pub 192.168.1.$ip
done
2.批量配置防火墙
#!/bin/bash
IPT=/sbin/iptables
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -p tcp --dport 22 -s 192.168.1.0/24 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 10.10.0.0/24 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#允许合法的进入
iptables -A INPUT -s 192.168.1.0/24 -p all -j ACCEPT
iptables -A INPUT -s 10.10.0.0/24 -p all -j ACCEPT
#允许PING
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
#others RELATED FTP协议
#允许关联的状态包
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#默认规则
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
#对外开放服务
#http
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#mysql
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 3307 -j ACCEPT
#nagios
iptables -A INPUT -s 10.10.0.0/24 -p tcp --dport 5666 -j ACCEPT
#snmp
iptables -A INPUT -s 10.10.0.0/24 -p tcp --dport 161 -j ACCEPT
#rsync
iptables -A INPUT -s 10.10.0.0/24 -p tcp --dport 873 -j ACCEPT
#nfs 2049,protmap 111
iptables -A INPUT -s 10.10.0.0/24 -p tcp -m multiport --dport 111,892,2049 -j ACCEPT
iptables -A INPUT -s 10.10.0.0/24 -p udp -m multiport --dport 111,892,2049 -j ACCEPT
iptables -A INPUT -s 10.10.0.0/24 -p icmp --icmp-type any -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#使之永久生效
/etc/init.d/iptables save
3.一键系统优化脚本
#!/bin/bash
export PATH=$PATH:/bin:/sbin:/usr/sbin
# Require root to run this script.
if [ "$UID" != "0" ]; then
echo "Please run this script by root."
exit 1
fi
#define cmd var
SERVICE=`which service`
CHKCONFIG=`which chkconfig`
function mod_yum(){
#阿里云源修改
if [ -e /etc/yum.repos.d/CentOS-Base.repo ]
then
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup&&\
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
fi
}
function close_selinux(){
#1.关闭 selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#临时生效
setenforce 0 &>/dev/null
#getenforce
}
function close_iptables(){
#2.关闭防火墙
/etc/init.d/iptables stop
/etc/init.d/iptables stop
chkconfig iptables off
}
function least_service(){
#3.关闭无用服务
chkconfig|awk '{print "chkconfig",$1,"off"}'|bash
chkconfig|egrep "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"on"}'|bash
#export
#chkconfig --list|grep 3:on
}
function adduser(){
#4.添加 qinzc用户,并添加到 sudo
if [ `grep -w qinzc /etc/passwd|wc -l` -lt 1 ]
then
useradd qinzc
echo 123456|passwd --stdin qinzc
\cp /etc/sudoers /etc/sudoers.ori
echo "qinzc ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
tail -1 /etc/sudoers
visudo -c &>/dev/null
fi
}
function charset(){
#5.字符集调整
cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
echo 'LANG="zh_CN.UTF-8"' >/etc/sysconfig/i18n
source /etc/sysconfig/i18n
#echo $LANG
}
function time_sync(){
#6.时间同步
cron=/var/spool/cron/root
if [ `grep -w "ntpdate" $cron|wc -l` -lt 1 ]
then
echo '#time sync by qinzc at 2018-9-14' >>$cron
echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>$cron
crontab -l
fi
}
function com_line_set(){
#7.终端全局设置
if [ `egrep "TMOUT|HISTSIZE|HISTFILESIZE" /etc/profile|wc -l` -ge 3 ]
then
echo 'export TMOUT=300' >>/etc/profile
echo 'export HISTSIZE=5' >>/etc/profile
echo 'export HISTFILESIZE=5' >>/etc/profile
. /etc/profile
fi
}
function open_file_set(){
#8.increase open file.
if [ `grep 65535 /etc/security/limits.conf|wc -l` -lt 1 ]
then
echo '* - nofile 65535 ' >>/etc/security/limits.conf
tail -1 /etc/security/limits.conf
fi
}
function set_kernel(){
#9.内核参数优化
if [ `grep kernel_flag /etc/sysctl.conf|wc -l` -lt 1 ]
then
cat >>/etc/sysctl.conf<<EOF
#kernel_flag
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
EOF
sysctl -p
fi
}
function init_ssh(){
#9.ssh参数优化
\cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +"%Y-%m-%d_%H-%M-%S"`
#sed -i 's%#Port 22%Port 52113%' /etc/ssh/sshd_config
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%' /etc/ssh/sshd_config
sed -i 's%#PermitEmptyPasswords no%PermitEmptyPasswords no%' /etc/ssh/sshd_config
sed -i 's%#UseDNS yes%UseDNS no%' /etc/ssh/sshd_config
/etc/init.d/sshd reload &>/dev/null
}
function update_linux(){
#10.安装lrzsz nmap tree dos2unix nc 软件.
if [ `rpm -qa lrzsz nmap tree dos2unix nc|wc -l` -le 3 ]
then
yum install lrzsz nmap tree dos2unix nc -y
#yum update -y
fi
}
main(){
mod_yum
close_selinux
close_iptables
least_service
adduser
charset
time_sync
com_line_set
open_file_set
set_kernel
init_ssh
update_linux
}
main
4.一键安装MySql脚本
cmake+mysql5.5.rar
#!/bin/bash
#安装依赖包
yum install ncurses-devel bison gcc gcc-c++ -y
#安装cmake
tar xf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
gmake
gmake install
cd ../
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
tar zxf mysql-5.5.32.tar.gz
cd mysql-5.5.32
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make && make install
ln -s /application/mysql-5.5.32/ /application/mysql
\cp support-files/my-small.cnf /etc/my.cnf
#配置环境变量
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
tail-l /etc/profile
source /etc/profile
echo $PATH
chown -R mysql.mysql /application/mysql/data/
chmod -R 1777 /tmp/
#初始化数据库(与5.1有路径区别)
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
#配置启动服务
\cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
5.批量管理执行命令脚本
#!/bin/sh
. /etc/init.d/functions
if [$# -ne 1]
then
echo "USAGE:/bin/sh $0 arg1 "
exit 1
fi
for n in 10 11 12 13 14 15
do
ssh -p22 qinzc@192.168.1.$n $1
if [ $? -eq 0 ]
then
action "============= 192.168.1.$n ok ================" /bin/true
else
action "============ 192.168.1.$n fail =============" /bin/false
fi
done
6.一键备份主库脚本(用于主从同步)
#!/bin/bash
MYUSER=root
MYPASS="123456"
MYSOCK=/data/3306/mysql.sock
MAIN_PATH=/data/backup
DATA_PATH=/data/backup
L0G_FILE=${DATA_PATH}/mysqllogs_`date +%F`.log
DATA_FILE=${DATA_PATH}/mysql_backup_`date +%F`.sql.gz
MYSQL_PATH=/application/mysql/bin
MYSQL_CMD="${MYSQL_PATH}/mysql -u$MYUSER -p$MYPASS -S $MYSOCK"
MYSQL_DUMP="${MYSQL_PATH}/mysqldump -u$MYUSER -p$MYPASS -S $MYSOCK -A -B --events --master-data=1 -x --flush-logs --single-transaction -e"
${MYSQL_CMD} -e "flush tables with read lock;"
echo " ------show master status result------" >>$L0G_FILE
${MYSQL_CMD} -e "show master status;" >>$L0G_FILE
${MYSQL_DUMP} | gzip > $DATA_FILE
${MYSQL_CMD} -e "unlock tables;"
cat $L0G_FILE
#mail -s "mysql slave log" 542129333@qq.com < $L0G_FILE
#创建专用同步帐号
#grant replication slave on *.* to 'rep'@'10.10.0.%' identified by '123456'; //创建
#flush privileges; //刷新权限
7.一键恢复与配置主从同步脚本(接上面脚本)
#!/bin/bash
MYUSER=root
MYPASS="123456"
MYSOCK=/data/3306/mysql.sock
MAIN_PATH=/data/backup
DATA_PATH=/data/backup
L0G_FILE=${DATA_PATH}/mysqllogs_`date +%F`.log
DATA_FILE=${DATA_PATH}/mysql_backup_`date +%F`.sql.gz
MYSQL_PATH=/application/mysql/bin
MYSQL_CMD="${MYSQL_PATH}/mysql -u$MYUSER -p$MYPASS -S $MYSOCK"
#恢复
cd ${DATA_PATH}
gzip -d mysql_backup_`date +%F`.sql.gz
echo "uzip ok"
${MYSQL_CMD} <mysql_backup_`date +%F`.sql
echo "drsql ok"
#配置从同步
cat |${MYSQL_CMD}<< EOF
CHANGE MASTER TO
MASTER_HOST='10.10.0.15',
MASTER_PORT=3307,
MASTER_USER='rep',
MASTER_PASSWORD='123456';
MASTER_LOG_FILE='mysql-bin.000003', #备份时如果指定了--master-data=1 ,此条不用写
MASTER_LOG_POS=107; #备份时如果指定了--master-data=1 ,此条不用写
EOF
${MYSQL_CMD} -e "start slave;"
${MYSQL_CMD} -e "show slave status\G"|egrep "IO_Running|SQL_Running">$L0G_FILE
cat $L0G_FILE
#mail -s "mysql slave log" 542129333@qq.com < $L0G_FILE
8.从库整库备份脚本
#!/bin/bash
MYUSER=root
MYPASS="123456"
MYSOCK=/data/3306/mysql.sock
DATA_PATH=/data/backup
MYSQL_PATH=/application/mysql/bin
MYSQL_CMD="${MYSQL_PATH}/mysql -u$MYUSER -p$MYPASS -S $MYSOCK"
MYSQL_DUMP="${MYSQL_PATH}/mysqldump -u$MYUSER -p$MYPASS -S $MYSOCK -A -B -F -e --single-transaction"
#如果当前周六,删除一星期前的数据,生成当天日志log,生成备份
if [ $(date +%w) -eq 6 ]
then
rm -f $DATA_PATH/mysql_backup_$(date --date="7 days ago" +%w_%Y%m%d*).sql.*
log=$DATA_PATH/mysql_backup_$(date +%w_%Y%m%d%H%M%S).sql.log
data=$DATA_PATH/mysql_backup_$(date +%w_%Y%m%d%H%M%S).sql.log.gz
else
log=$DATA_PATH/mysql_backup_$(date +%w).sql.log
data=$DATA_PATH/mysql_backup_$(date +%w).sql.log.gz
fi
#停止从同步,备份
echo "stop slave SQL_THREAD;" |${MYSQL_CMD}
echo "################################`date +%Y-%m-%d-%H-%M-%S-%w`#######################################" >$log
echo -e "master.info:" >>$log
cat /data/3306/master.info |sed -n '2,3p'>>$log
echo -e "show slave status:">>$log
echo "show slave status\G"|${MYSQL_CMD}|grep "Master_Log_File|Read_Master_Log_Pos"|sed -n '1,2p'|awk -F ": " '{print $2}'>> $log
echo -e "################################开始位置#######################################\n"
cd $MYSQL_PATH
${MYSQL_DUMP}|gzip >$data
echo "################################`date +%Y-%m-%d-%H-%M-%S-%w`#######################################" >$log
echo -e "master.info:" >>$log
sed -n '2,3p' /data/3306/master.info >>$log
echo -e "show slave status:">>$log
echo "show slave status\G"|${MYSQL_CMD}|egrep "Master_Log_File|Read_Master_Log_Pos"|sed -n '1,2p'|awk -F ": " '{print $2}'>> $log
echo -e "################################结束位置#######################################\n"
echo "start slave SQL_THREAD;"|${MYSQL_CMD}
#mail -s "bak log info" 542129333@qq.com <$log
#rsync all data to 22
#rsync -vzrtopg --progress /data/backup/ rsync_backup@10.10.0.16::back/3306/ --password-file=/etc/rsync.password
9.从库分表分库备份脚本
#!/bin/bash
MYUSER=root
MYPASS="123456"
MYSOCK=/data/3306/mysql.sock
DATA_PATH=/data/backup
MYSQL_PATH=/application/mysql/bin
MYSQL_CMD="${MYSQL_PATH}/mysql -u$MYUSER -p$MYPASS -S $MYSOCK"
MYSQL_DUMP="${MYSQL_PATH}/mysqldump -u$MYUSER -p$MYPASS -S $MYSOCK --lock-all-tables "
#如果当前周六,删除一星期前的数据,生成当天日志log,生成备份
if [ $(date +%w) -eq 6 ]
then
rm -f $DATA_PATH/mysql_backup_$(date --date="7 days ago" +%w_%Y%m%d*).sql.*
log=$DATA_PATH/mysql_backup_$(date +%w_%Y%m%d%H%M%S).sql.log
datadir=$DATA_PATH/$(date +%w_%Y%m%d%H%M%S)
else
log=$DATA_PATH/mysql_backup_$(date +%w).sql.log
datadir=$DATA_PATH/$(date +%w)
fi
#停止从同步,备份
echo "stop slave SQL_THREAD;" |${MYSQL_CMD}
echo "################################`date +%Y-%m-%d-%H-%M-%S-%w`#######################################" >$log
echo -e "master.info:" >>$log
cat /data/3306/master.info |sed -n '2,3p'>>$log
echo -e "show slave status:">>$log
echo "show slave status\G"|${MYSQL_CMD}|grep "Master_Log_File|Read_Master_Log_Pos"|sed -n '1,2p'|awk -F ": " '{print $2}'>> $log
echo -e "################################开始位置#####################################\n"
cd $MYSQL_PATH
#${MYSQL_DUMP}|gzip >$data
#for loop
for dbname in `$MYSQL_CMD -e "show databases;"|sed '1d'`
do
mkdir -p ${datadir}/${dbname}_$(date +%w)
cd ${datadir}/${dbname}_$(date +%w)
echo -e "-----------------------${dbname}----------------------------">>${datadir}/${dbname}_$(date +%w).log
for tablename in `${MYSQL_CMD} ${dbname} -e "show tables;"|sed '1d'`
do
cd ${MYSQL_PATH}
${MYSQL_DUMP} ${dbname} ${tablename} |gzip >${datadir}/${dbname}_$(date +%w)/${dbname}_${tablename}.sql.gz
done
echo -e "################################${dbname}--Stopp_Time:`date`#######################################"
echo >>${datadir}/fenbiao_$(date +%w).log;echo >>${datadir}/fenbiao_$(date +%w).log;
du -sh ${DATA_PATH}/$(date +%w)/${dbname}_$(date +%w)/ >>${datadir}/fenbiao_$(date +%w).log;
echo >>${datadir}/fenbiao_$(date +%w).log;echo >>${datadir}/fenbiao_$(date +%w).log;
done
echo "################################`date +%Y-%m-%d-%H-%M-%S-%w`#######################################" >$log
echo -e "master.info:" >>$log
sed -n '2,3p' /data/3306/master.info >>$log
echo -e "show slave status:">>$log
echo "show slave status\G"|${MYSQL_CMD}|egrep "Master_Log_File|Read_Master_Log_Pos"|sed -n '1,2p'|awk -F ": " '{print $2}'>> $log
echo -e "################################结束位置#######################################\n"
echo "start slave SQL_THREAD;"|${MYSQL_CMD}
#mail -s "bak log info" 542129333@qq.com <$log
#rsync all data to 22
#rsync -vzrtopg --progress /data/backup/ rsync_backup@10.10.0.16::back/3306/ --password-file=/etc/rsync.password
10.一键安装nagios监控
#!/bin/bash
#1安装依赖包
yum install gcc glibc glibc-common mysql* gd gd-devel httpd php php-gd -y
#2添加用户和组
/usr/sbin/useradd -m nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
#3解压并编译Nagios相关包
unzip oldboy_training_nagios_soft.zip
tar xzf nagios-3.5.1.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cd ../
#4配置WEB认证
htpasswd -cb /usr/local/nagios/etc/htpasswd.users qinzc 123456
#5安装插件
yum -y install perl-devel
tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make && make install
cd ../
ls /usr/local/nagios/libexec/|wc -l
#6安装NRPE
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
cd ..
#7启动服务,并检查
/etc/init.d/nagios start
/etc/init.d/httpd start
echo -----------
lsof -i tcp:80
echo ----------
ps -ef|grep nagios
echo "NAGIOS is successfully installed."
echo ok
11.一键安装nagios客户端
#!/bin/sh
#添加Nagios用户
/usr/sbin/useradd -m nagios -s /sbin/nologin
#安装插件必安装
yum -y install perl-devel gcc openssl-devel
#解压并编译Nagios相关包
unzip oldboy_training_nagios_soft.zip
tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --prefix=/usr/local/nagios --enable-perl-modules --enable-redhat-pthread-workaround
make && make install
cd ../
ls /usr/local/nagios/libexec/|wc -l
#安装nrpe
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
cd ..
#安装iostat插件
tar zxvf Params-Validate-0.91.tar.gz
cd Params-Validate-0.91
perl Makefile.PL
make
make install
cd ..
#----------------------------------------
tar zxvf Class-Accessor-0.31.tar.gz
cd Class-Accessor-0.31
perl Makefile.PL
make
make install
cd ..
#----------------------------------------
tar zxvf Config-Tiny-2.12.tar.gz
cd Config-Tiny-2.12
perl Makefile.PL
make
make install
cd ..
#----------------------------------------
tar zxvf Math-Calc-Units-1.07.tar.gz
cd Math-Calc-Units-1.07
perl Makefile.PL
make
make install
cd ..
#----------------------------------------
tar zxvf Regexp-Common-2010010201.tar.gz
cd Regexp-Common-2010010201
perl Makefile.PL
make
make install
cd ..
#----------------------------------------
tar zxvf Nagios-Plugin-0.34.tar.gz
cd Nagios-Plugin-0.34
perl Makefile.PL
make
make install
cd ..
#----------------------------------------
#系统性能命令工具
#for monitor iostat
yum install sysstat -y
cp ~/tools/check_memory.pl /usr/local/nagios/libexec
cp ~/tools/check_iostat /usr/local/nagios/libexec
chmod 755 /usr/local/nagios/libexec/check_memory.pl
chmod 755 /usr/local/nagios/libexec/check_iostat
dos2unix /usr/local/nagios/libexec/check_memory.pl
dos2unix /usr/local/nagios/libexec/check_iostat
#修改nrpe.cfg
\cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.bak
sed -i s#allowed_hosts=127.0.0.1#allowed_hosts=127.0.0.1,10.10.0.16#g /usr/local/nagios/etc/nrpe.cfg
sed -i '199,203d' /usr/local/nagios/etc/nrpe.cfg
echo "command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c 30,25,20">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p /">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10">>/usr/local/nagios/etc/nrpe.cfg
pkill nrpe
sleep 2
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "#nagios nrpe process cmd by qinzc 2018-9-7" >> /etc/rc.local
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d">>/etc/rc.local
netstat -lnt|grep 5666 && echo "nagios client is ok"
12.日志轮询备份脚本
#!/bin/sh
ip=$(ifconfig eth0|sed -n '2p'|awk -F "[ :]+" '{print $4}')
[ ! -d /backup/$ip ] && mkdir -p /backup/$ip
cd /backup/$ip &&\
tar -zcf bak_$(date +%F).tar.gz /var/www/html /app/logs/access_$(date +%F -d -1day).log /etc/rc.local/ /server/scripts /var/spool/cron && touch ${ip}_fl
ag_$(date +%F).txt
rsync -az /backup/ backupuser@192.168.1.11::backup/ --password-file=/etc/rsync.password
find /backup -type f -name "*.tar.gz" -mtime +7|xargs rm -f
13.
#!/bin/bash
14.
#!/bin/bash
停留在世界边缘,与之惜别