标签:自动化安装zabbix 自动化脚本 监控系统 zabbix
自动化安装zabbix脚本(3.0/3.2)
一、zabbix简介
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
二、zabbix特点
1.企业级的、开源的、分布式
2.灵活的告警机制、存储数据提供杰出的报告及图形
3.通过内置的绘图方法实现监控数据实时绘图
4.允许灵活地自定义问题阀值
5.支持主动与被动方式(agent、snmp、ipmi、自定义脚本)
三、自动化安装zabbix(3.0/3.2)脚本
#!/bin/bash
#Date 2017/1/20
#mail xuel@51idc.com
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
which ntpdate
if [ $? -eq 0 ];then
/usr/sbin/ntpdate time1.aliyun.com
echo "*/5 * * * * /usr/sbin/ntpdate -s time1.aliyun.com">>/var/spool/cron/root
else
yum install ntpdate -y
/usr/sbin/ntpdate time1.aliyun.com
echo "*/5 * * * * /usr/sbin/ntpdate -s time1.aliyun.com">>/var/spool/cron/root
fi
clear
echo "##########################################"
echo "# Auto Install zabbix. ##"
echo "# Press Ctrl + C to cancel ##"
echo "# Any key to continue ##"
echo "##########################################"
echo "(1) Install zabbix3.0"
echo "(2) Install zabbix3.2"
echo "(3) EXIT"
read -p "Please input your choice:" NUM
case $NUM in
1)
URL="http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm"
VER=zabbix-3.0
;;
2)
URL="http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm"
VER=zabbix-3.2
;;
3)
echo -e "\033[41;37m You choice channel! \033[0m" && exit 0
;;
*)
echo -e "\033[41;37m Input Error! Place input{1|2|3} \033[0m" && exit 1
;;
esac
clear
echo -e "\033[32m You choice install $VER.Install\033[0m"
echo -e "\033[5m Press any key to start install $VER... \033[0m"
read -n 1
TDIR=/tools
IP=`ifconfig eth0 | grep "inet addr" | awk -F"[: ]+" ‘{print $4}‘`
yum remove php* -y
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
ls /etc/yum.repos.d/webtatic.repo
if [ $? -eq 0 ];then
yum -y install `yum list|grep php55w|awk ‘{printf ("%s ",$1)}‘` --skip-broken
fi
if [ $? -eq 0 ];then
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini
sed -i "s#`grep max_execution_time /etc/php.ini`#max_execution_time = 300#g" /etc/php.ini
#max_execution_time = 30
sed -i "s#`grep post_max_size /etc/php.ini`#post_max_size = 32M#g" /etc/php.ini
sed -i "s#`grep max_input_time\ = /etc/php.ini`#max_input_time = 300#g" /etc/php.ini
sed -i "s#`grep memory_limit /etc/php.ini`#memory_limit = 128M#g" /etc/php.ini
fi
service php-fpm start /tmp/php-install.log 2>&1
STAT=`echo $?`
PORT=`netstat -lntup|grep php-fpm|wc -l`
if [ $STAT -eq 0 ] && [ $PORT -eq 1 ];then
echo -e "\033[32m PHP is install success! \033[0m"
else
echo -e "\033[32m PHP install file.please check /tmp/php-install.log \033[0m"
fi
yum install -y ntpdate mailx dos2unix vim zcat wget net-snmp-utils gcc gcc-c++ autoconf httpd libxml* mysql mysql-server httpd-manual mod_ssl mod_perl mod_auth_mysql mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel unixODBC-devel OpenIPMI-devel java-devel fping
clear
service mysqld start
groupadd zabbix -g 201
useradd -g zabbix -u 201 -m -s /sbin/nologin zabbix
rpm -ivh $URL
ls /etc/yum.repos.d/zabbix.repo
ZAB=`echo $?`
if [ ! -d $TDIR ];then
/bin/mkdir $TDIR && cd $TDIR
fi
if [ $? -eq 0 ];then
yum install -y zabbix-agent.x86_64 zabbix-get.x86_64 zabbix-server-mysql.x86_64 zabbix-web.noarch zabbix-web-mysql.noarch
fi
if [ "$VER" == "zabbix-3.0" ];then
yum install -y zabbix-agent.x86_64 zabbix-get.x86_64 zabbix-server-mysql.x86_64 zabbix-web.noarch zabbix-web-mysql.noarch
elif [ "$VER" == "zabbix-3.2" ];then
if [ -d $TDIR ];then
cd $TDIR
else
/bin/mkdir $TDIR && cd $TDIR
fi
if [ $? -eq 0 ];then
for PAG in zabbix-server-mysql-3.2.3-1.el6.x86_64.rpm zabbix-web-3.2.3-1.el6.noarch.rpm zabbix-web-mysql-3.2.3-1.el6.noarch.rpm zabbix-agent-3.2.3-1.el6.x86_64.rpm
do
wget -c http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/deprecated/$PAG
done
yum install -y zabbix-server-mysql* zabbix-web-mysql* zabbix-agent zabbix-web*
fi
else
echo "error zabbixi version"
fi
if [ $? -eq 0 ];then
mysql -uroot -e "create database zabbix character set utf8;"
mysql -uroot -e "grant all privileges on zabbix.* to zabbix@localhost identified by ‘zabbix‘;"
mysql -uroot -e "flush privileges;"
fi
cd /usr/share/doc
MYSQLDIR=`ls -l /usr/share/doc/ | grep zabbix-server-mysql* | awk ‘{print $9}‘`
cd $MYSQLDIR
zcat create.sql.gz | mysql -uroot zabbix
mysqladmin -uroot password "mysqladmin"
cd /usr/share/
cp -r ./zabbix/ /var/www/html/zabbix
echo "DBPassword=zabbix" >> /etc/zabbix/zabbix_server.conf
service httpd start
service zabbix-server start
service zabbix-agent start
chkconfig httpd on
chkconfig mysqld on
chkconfig php-fpm on
chkconfig zabbix-server on
chkconfig zabbix-agent on
/etc/init.d/iptables status >/dev/null 2>&1
if [ $? -eq 0 ];then
iptables -I INPUT -p tcp --dport 443 -j ACCEPT &&
iptables -I INPUT -p tcp --dport 10051 -j ACCEPT &&
iptables -I INPUT -p tcp --dport 10050 -j ACCEPT &&
iptables -I INPUT -p tcp --dport 3000 -j ACCEPT &&
#iptables -I INPUT -p tcp --dport 3306 -j ACCEPT &&
service iptables save >/dev/null 2>&1
/etc/init.d/iptables restart
else
echo -e "\033[32m iptables is stopd\033[0m"
fi
clear
STAT=`/bin/ps -ef|grep zabbix_server|grep -v grep|wc -l`
PORT=`/bin/netstat -lntup|grep zabbix_server|wc -l`
if [ $STAT -ne 0 ] && [ $PORT -ne 0 ];then
echo -e "\033[42;37m Zabbix$VER is Install Success,Username:Admin Password:zabbix \033[0m"
echo -e "\033[42;37m MySql Username:root Password:mysqladmin \033[0m"
echo -e "\033[42;37m rul:https://$IP/zabbix \033[0m"
fi
四、脚本说明
1.执行脚本如下:(选择喜欢的版本安装,目前最新的3.4官方有说明,但还未发现软件包)
2.按任继健回车开始安装
3.安装完成如下图
4.通过浏览器打开脚本执行完的url进行安装即可。
本文出自 “KaliArch” 博客,请务必保留此出处http://kaliarch.blog.51cto.com/8966921/1896968
标签:自动化安装zabbix 自动化脚本 监控系统 zabbix
原文地址:http://kaliarch.blog.51cto.com/8966921/1896968