|
#!/bin/bash
Server_IP= #Zabbix-server的IP地址
download()
{
echo "install zbbbix-2.4.2"
mkdir -p /home/zbx_src && cd /home/
wget http://www.zabbix.com/downloads/ ... nux2_6.amd64.tar.gz
tar zxvf zabbix_agents_2.4.1.linux2_6.amd64.tar.gz -C /home/zbx_src >/dev/null
if [ $? = 0 ];then
echo -e "\033[42;30m download complete \033[0m"
fi
}
config_file(){
echo "create zabbix configure file"
cd /usr/local/etc/
rm -fr /usr/local/etc/zabbix_agent.conf >/dev/null
cp -f /home/zbx_src/sbin/* /usr/local/sbin/
cp -f /home/zbx_src/bin/* /usr/local/bin/
cat > /usr/local/etc/zabbix_agentd.conf << EOF
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
ServerActive=$Server_IP
Server=$Server_IP
EnableRemoteCommands=1
UnsafeUserParameters=1
UserParameter=net.tcp.conn,netstat -n | grep -c $1
UserParameter=gs.status,ps aux | grep -v grep | grep -c /GameServer/tomcat/
UserParameter=gs.cpu,top -b -n 1 |grep mt_a | grep -v grep | awk '{print$9}'
UserParameter=mysqld.cpu,top -b -n 1 |grep '\\bmysqld\\b' | grep -v grep | awk '{print$9}'
EOF
if [ $? = 0 ];then
echo -e "\033[42;30m configure file complete! \033[0m"
fi
}
create_user(){
echo "create zabbix users"
groupadd zabbix
useradd zabbix -s /sbin/nologin -g zabbix
mkdir /var/log/zabbix
mkdir /var/run/zabbix
chown -R zabbix.root /var/run/zabbix/
chown -R zabbix.root /var/log/zabbix/
if [ $? = 0 ];then
echo -e "\033[42;30m create user complete! \033[0m"
fi
}
create_start_file(){
echo "create start file..."
cat > /etc/init.d/zabbix_agentd <<EOF
# /etc/rc.d/init.d/zabbix_agentd
#
# Starts the zabbix_agentd daemon
#
# chkconfig: - 95 5
# description: Zabbix Monitoring Agent
# processname: zabbix_agentd
# pidfile: /tmp/zabbix_agentd.pid
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
# Source function library.
#!/bin/bash
. /etc/init.d/functions
RETVAL=0
prog="Zabbix Agent"
ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"
if [ ! -x \${ZABBIX_BIN} ] ; then
echo -n "\${ZABBIX_BIN} not installed! "
# Tell the user this has skipped
exit 5
fi
start() {
echo -n \$"Starting \$prog: "
daemon \$ZABBIX_BIN
RETVAL=\$?
[ \$RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agentd
echo
}
stop() {
echo -n \$"Stopping \$prog: "
killproc \$ZABBIX_BIN
RETVAL=\$?
[ \$RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_agentd
echo
}
case "\$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
stop
sleep 10
start
RETVAL=\$?
;;
condrestart)
if [ -f /var/lock/subsys/zabbix_agentd ]; then
stop
start
fi
;;
status)
status \$ZABBIX_BIN
RETVAL=\$?
;;
*)
echo \$"Usage: \$0 {condrestart|start|stop|restart|reload|status}"
exit 1
esac
exit \$RETVAL
EOF
if [ $? = 0 ];then
echo -e "\033[42;30m create_start_file complete! \033[0m"
fi
}
configure_Permissions_start(){
chmod a+x /etc/init.d/zabbix_agentd
chkconfig --add zabbix_agentd
chkconfig zabbix_agentd on
/etc/init.d/zabbix_agentd start
}
echo -e "\033[42;30m ============================START======================== \033[0m"
download
config_file
create_user
create_start_file
configure_Permissions_start
echo -e "\033[42;30m ============================END========================== \033[0m"
|
|
|