一、服务端
1.准备工作
2.运行 server-install.sh 一键安装zabbix服务端
#!/bin/sh
zabbix_version=3.0.18
zabbixdir=`pwd`
ip=`ip addr |grep inet |egrep -v "inet6|127.0.0.1" |awk '{print $2}' |awk -F "/" '{print $1}'`
release=`cat /etc/redhat-release | awk -F "release" '{print $2}' |awk -F "." '{print $1}' |sed 's/ //g'`
cat $zabbixdir/README.md
#sleep 10
echo "当前目录为:$zabbixdir"
echo "本机ip为:$ip"
echo "安装mysql、apache、php等相关组件"
sleep 3
if [ $release = 7 ];then
rpm -Uvh http://mirrors.isu.net.sa/pub/fedora/fedora-epel/7/x86_64/e/epel-release-7-6.noarch.rpm
yum -y install patch php-xml unixODBC unixODBC-devel php-xmlrpc php-mbstring php-mhash patch java-devel wget unzip libxml2 libxml2-devel httpd mariadb mariadb-devel mariadb-server php php-mysql php-common php-mbstring php-gd php-odbc php-pear curl curl-devel net-snmp net-snmp-devel perl-DBI php-xml ntpdate php-bcmath zlib-devel glibc-devel curl-devel gcc automake libidn-devel openssl-devel net-snmp-devel rpm-devel OpenIPMI-devel
systemctl start mariadb.service
elif [ $release = 6 ];then
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64 -y
rpm -Uvh http://mirrors.isu.net.sa/pub/fedora/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum install unixODBC patch unixODBC-devel patch java-devel wget unzip libxml2 libxml2-devel httpd mysql mysql-server curl curl-devel net-snmp net-snmp-devel perl-DBI ntpdate zlib-devel mysql-devel glibc-devel gcc-c++ gcc automake mysql libidn-devel openssl-devel net-snmp-devel rpm-devel OpenIPMI-devel php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-bcmath php56w-xml -y
service mysqld start
fi
echo "同步服务器时间"
ntpdate asia.pool.ntp.org
echo "创建zabbix用户"
groupadd zabbix
useradd -g zabbix zabbix
sleep 5
echo "设置数据库root密码,默认为123321"
sleep 3
mysqladmin -uroot password "123321"
echo "创建zabbix数据库,和用户名密码"
echo "create database IF NOT EXISTS zabbix default charset utf8 COLLATE utf8_general_ci;" | mysql -uroot -p123321
echo "grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';" | mysql -uroot -p123321
echo "flush privileges;" | mysql -uroot -p123321
echo "安装zabbix-${zabbix_version}"
sleep 3
if [ ! -f zabbix-${zabbix_version}.tar.gz ];then
wget http://netix.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/${zabbix_version}/zabbix-${zabbix_version}.tar.gz
fi
tar zxvf $zabbixdir/zabbix-${zabbix_version}.tar.gz
cd $zabbixdir/zabbix-${zabbix_version}
echo `pwd`
./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
sleep 3
CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
mkdir /var/www/html/zabbix
cp -r $zabbixdir/zabbix-${zabbix_version}/frontends/php/* /var/www/html/zabbix
cp $zabbixdir/simkai.ttf /var/www/html/zabbix/fonts
sed -i "s/DejaVuSans/simkai/g" /var/www/html/zabbix/include/defines.inc.php
cp graphtree3.0.4.patch /var/www/html/zabbix/
cd /var/www/html/zabbix
#wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/graphtree3-0-1.patch
patch -Np0 /var/www/html/zabbix/conf/zabbix.conf.php <
END
echo "导入zabbix数据库"
sleep 3
cd $zabbixdir/zabbix-${zabbix_version}
mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/schema.sql
mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/images.sql
mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/data.sql
echo "创建启动init"
sleep 3
cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
cp misc/init.d/tru64/zabbix_server /etc/init.d/
chmod +x /etc/init.d/zabbix_*
sed -i 's:DAEMON=/usr/local/sbin/zabbix_server:DAEMON=/usr/local/zabbix/sbin/zabbix_server:g' /etc/init.d/zabbix_server
sed -i 's:DAEMON=/usr/local/sbin/zabbix_agentd:DAEMON=/usr/local/zabbix/sbin/zabbix_agentd:g' /etc/init.d/zabbix_agentd
sed -i 's:DBUser=root:DBUser=zabbix:g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i '/# DBPassword=/a\DBPassword=zabbix' /usr/local/zabbix/etc/zabbix_server.conf
echo "设置php.ini相关参数"
sleep 3
cp /etc/php.ini /etc/php.ini.zabbixbak
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
sed -i '/max_input_time =/s/60/300/' /etc/php.ini
sed -i '/mbstring.func_overload = 0/a\mbstring.func_overload = 1' /etc/php.ini
sed -i '/post_max_size =/s/8M/32M/' /etc/php.ini
sed -i '/;always_populate_raw_post_data = -1/a\always_populate_raw_post_data = -1' /etc/php.ini
sed -i '/;date.timezone =/a\date.timezone = Asia\/Shanghai' /etc/php.ini
echo "设置apache"
sleep 3
sed -i '/#ServerName www.example.com:80/a\ServerName zabbix' /etc/httpd/conf/httpd.conf
if [ $release = 7 ];then
systemctl start httpd.service
systemctl enable httpd.service
systemctl enable mariadb
elif [ $release = 6 ];then
chkconfig httpd on
chkconfig mysqld on
service httpd start
fi
echo "设置开机启动"
echo "/etc/init.d/zabbix_server restart" >> /etc/rc.local
echo "/etc/init.d/zabbix_agentd restart" >> /etc/rc.local
echo "/usr/local/zabbix/sbin/zabbix_java/startup.sh" >> /etc/rc.local
echo "启动zabbix"
/etc/init.d/zabbix_server restart
/etc/init.d/zabbix_agentd restart
/usr/local/zabbix/sbin/zabbix_java/startup.sh
echo "数据库默认root密码zabbix123321;zabbix-Database name:zabbix/User:zabbix/Password:zabbix"
cp $zabbixdir/zabbix-${zabbix_version}.tar.gz /var/www/html/zabbix
echo "打开http://$ip/zabbix,进行下一步安装"
由于zabbix3需要php5.6以上,因此脚本会删除原有php环境重新安装
- mysql默认root密码123321
zabbix数据库名称zabbix
zabbix数据库用户名zabbix
zabbix数据库密码zabbix
二、客户端
1.常规监控, 终端运行 agent-install.sh 安装
#!/bin/sh
sleep 10
zabbixdir=`pwd`
zabbix_version=3.0.18
ip=`ip addr |grep inet |egrep -v "inet6|127.0.0.1" |awk '{print $2}' |awk -F "/" '{print $1}'`
echo "当前目录为:$zabbixdir"
echo "本机ip为:$ip"
cat $zabbixdir/Readme
read -p "what's zabbix-server-IP ?:" ServerIP
echo "zabbix服务器ip为:$ServerIP"
read -p "zabbix-server-IP is $ServerIP yes or no:" isY
if [ "${isY}" != "y" ] && [ "${isY}" != "Y" ] && [ "${isY}" != "yes" ] && [ "${isY}" != "YES" ];then
exit 1
fi
echo "安装相关组件"
yum install -y ntpdate gcc gcc-c++ wget unixODBC unixODBC-devel
echo "同步服务器时间"
ntpdate asia.pool.ntp.org
echo "创建zabbix用户"
groupadd zabbix
useradd -g zabbix zabbix
echo "安装zabbix-agent"
sleep 3
#wget http://netix.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$zabbix_version/zabbix-${zabbix_version}.tar.gz
wget http://$ServerIP/zabbix/zabbix-${zabbix_version}.tar.gz
tar zxvf $zabbixdir/zabbix-${zabbix_version}.tar.gz
cd $zabbixdir/zabbix-${zabbix_version}
echo `pwd`
./configure --prefix=/usr/local/zabbix/ --enable-agent
sleep 3
make
make install
echo "配置zabbix server ip为 $ServerIP"
sed -i "s/Server=127.0.0.1/Server=$ServerIP/g" /usr/local/zabbix/etc/zabbix_agentd.conf
echo "创建启动init"
cp $zabbixdir/zabbix-${zabbix_version}/misc/init.d/tru64/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
sed -i "s:DAEMON=/usr/local/sbin/zabbix_agentd:DAEMON=/usr/local/zabbix/sbin/zabbix_agentd:g" /etc/init.d/zabbix_agentd
echo "启动zabbix_agentd"
/etc/init.d/zabbix_agentd restart
2.开启 jvm, 参照
/opt/tomcat/bin/catalina.sh
增加 CATALINA_OPTS (172.18.5.61 为本机ip)
CATALINA_OPTS=”-Djava.rmi.server.hostname=172.18.5.61 -Djavax.management.builder.initial= -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false”
三、命令和问题
#服务端重启
/etc/init.d/zabbix_server restart
#服务端java-gateway 模块重启
/etc/init.d/zabbix-java-gateway restart
#客户端重启
/etc/init.d/zabbix_agentd restart
图形比例尺显示异常, 参照
ttf语言文件下载, simkai.ttf
四、邮件报警 参照
送信脚本 ( 使用本机送信, 第三方发信有数量限制 )
#!/bin/sh
#设置语言防止乱码
export LANG=zh_CN.UTF-8
#替换换行符
body=`echo $3|tr ‘\r’ ‘\n’`
echo “$body”|mail -s “$2” $1
信件参数配置
「故障」服务器:{HOSTNAME1}: {TRIGGER.NAME}
告警主机IP地址:{HOST.CONN}
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
「恢复」服务器:{HOSTNAME1}: {TRIGGER.NAME}
告警主机IP地址:{HOST.CONN}
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
本文链接地址: zabbix3.0搭建&tomcat监控