一共是两个脚本,分别是服务端和客户端。便捷化安装和配置
1、编写自动化执行脚本
①服务器(server)端
auto_zabbix_server.sh
++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/bash
IP=`ifconfig|sed -n 2p|awk '{print $2}'|cut -d ":" -f2`
#Env
yum -y install gcc gcc-c++ autoconf mysql-server mysql mysql-devel httpd php php-mysql php-gd php-bcmath php-xml php-pear php-xmlrpc php-mbstring php-bcmath php-snmp net-snmp-devel net-snmp net-snmp-utils OpenIPMI-devel curl-devel java-devel openldap-devel openldap wget unixODBC unixODBC-devel mysql-connector-odbc
#Install and config
wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.0/zabbix-2.4.0.tar.gz
if [ $? -eq 0 ];then
tar zxvf zabbix-2.4.0.tar.gz
fi
useradd zabbix
cd zabbix-2.4.0
/etc/init.d/mysqld start
mysql << EOF
create database zabbix character set utf8;
grant all on zabbix.* to zabbix@localhost identified by 'zabbixpwd';
quit
EOF
mysql -uzabbix -pzabbixpwd zabbix < ./database/mysql/schema.sql
mysql -uzabbix -pzabbixpwd zabbix < ./database/mysql/images.sql
mysql -uzabbix -pzabbixpwd zabbix < ./database/mysql/data.sql
#Compiled
sed -i 's#%6li:%.4d%.2d%.2d:%.2d%.2d%.2d.%03ld#%.4d-%.2d-%.2d:%.2d%.2d%.2d.%03ld#g' /root/zabbix-2.4.0/src/libs/zbxlog/log.c
./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-openipmi --with-unixodbc --with-ldap --enable-java && \
make && \
make install
#Service Configuration
cat >> /etc/services << "EOF"
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper
EOF
#Install the startup script
\cp misc/init.d/fedora/core/zabbix* /etc/init.d/
chmod 755 /etc/init.d/zabbix*
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_server
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_agentd
sed -i 's#DBUser=root#DBUser=zabbix#g' /etc/zabbix/zabbix_server.conf
sed -i '102a\DBPassword=zabbixpwd' /etc/zabbix/zabbix_server.conf
sed -i "s/Server\=127.0.0.1/Server\=127.0.0.1,"$IP"/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/ServerActive\=127.0.0.1/ServerActive\="$IP":10051/g" /etc/zabbix/zabbix_agentd.conf
#Start Zabbix Server
/etc/init.d/zabbix_server start
# Start Zabbix Agentd
/etc/init.d/zabbix_agentd start
#Configuration WEB
\cp -r frontends/php/* /var/www/html/
/etc/init.d/httpd start
#modify php.ini
sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#g' /etc/php.ini
sed -i 's#max_execution_time = 30#max_execution_time = 300#g' /etc/php.ini
sed -i 's#post_max_size = 8M#post_max_size = 32M#g' /etc/php.ini
sed -i 's#max_input_time = 60#max_input_time = 300#g' /etc/php.ini
sed -i 's#memory_limit = 128M#memory_limit = 512M#g' /etc/php.ini
sed -i 's#;mbstring.func_overload = 0#ambstring.func_overload = 2#g' /etc/php.ini
/etc/init.d/httpd restart
touch /var/www/html/conf/zabbix.conf.php
cat > /var/www/html/conf/zabbix.conf.php << "EOF"
<?php
// Zabbix GUI configuration file
global $DB;
$DB["TYPE"] = 'MYSQL';
$DB["SERVER"] = 'localhost';
$DB["PORT"] = '0';
$DB["DATABASE"] = 'zabbix';
$DB["USER"] = 'zabbix';
$DB["PASSWORD"] = 'zabbixpwd';
// SCHEMA is relevant only for IBM_DB2 database
$DB["SCHEMA"] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
?>
EOF
chkconfig --add zabbix_server && chkconfig --add zabbix_agentd && chkconfig zabbix_server on && chkconfig zabbix_agentd on
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
②客户(agentd)端
auto_zabbix_agentd.sh
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/bash
yum -y install gcc
wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.0/zabbix-2.4.0.tar.gz
tar zxvf /root/zabbix-2.4.0.tar.gz
useradd zabbix
cd /root/zabbix-2.4.0
./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix --enable-agent && \
make && \
make install
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
chmod 755 /etc/init.d/zabbix_agentd
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_agentd
cat >> /etc/services << "EOF"
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
EOF
sed -i 's/Server\=127.0.0.1/Server\=127.0.0.1,10.32.119.172/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/ServerActive\=127.0.0.1/ServerActive\=10.32.119.172:10051/g' /etc/zabbix/zabbix_agentd.conf
sed -i '#UnsafeUserParameters=0#aUnsafeUserParameters=1\n' /etc/zabbix/zabbix_agentd.conf
echo "UserParameter=custom.tcp.conn[*],netstat -n | awk '/^tcp/ {++S[\$NF]} END {for(a in S) print a, S[a]}' | grep \$1 | awk '{print \$\$2}'" >>/etc/zabbix/zabbix_agentd.conf
/etc/init.d/zabbix_agentd restart && chkconfig zabbix_agentd on
+++++++++++++++++++++++++++++++++++++++++++++++++
本文出自 “PETER-疏狂少年” 博客,谢绝转载!