Zabbix 配置笔记
Zabbix Server
安装参考 https://www.cnblogs.com/clsn/p/7885990.html 安装脚本
#!/bin/bash
#clsn
#设置解析 注意:网络条件较好时,可以不用自建yum源
# echo '10.0.0.1 mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com' >> /etc/hosts
#安装zabbix源、aliyun YUM源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
#安装zabbix
yum install -y zabbix-server-mysql zabbix-web-mysql
#安装启动 mariadb数据库
yum install -y mariadb-server
systemctl start mariadb.service
#创建数据库
mysql -e 'create database zabbix character set utf8 collate utf8_bin;'
mysql -e 'grant all privileges on zabbix.* to zabbix@localhost identified by "zabbix";'
#导入数据
zcat /usr/share/doc/zabbix-server-mysql-3.0.13/create.sql.gz|mysql -uzabbix -pzabbix zabbix
#配置zabbixserver连接mysql
sed -i.ori '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
#添加时区
sed -i.ori '18a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
#解决中文乱码
yum -y install wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
#启动服务
systemctl start zabbix-server
systemctl start httpd
#写入开机自启动
chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local<<EOF
systemctl start mariadb.service
systemctl start httpd
systemctl start zabbix-server
EOF
#输出信息
echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"
Zabbix Agent
Zabbix Agent是客户端, 运行在需要监控的主机上, 开放10050端口, 等待服务端的查询
客户端安装脚本
#!/bin/bash
#clsn
#设置解析
echo '10.0.0.1 mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com' >> /etc/hosts
#安装zabbix源、aliyu nYUM源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
#安装zabbix客户端
yum install zabbix-agent -y
sed -i.ori 's#Server=127.0.0.1#Server=172.16.1.61#' /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent.service
#写入开机自启动
chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local<<EOF
systemctl start zabbix-agent.service
EOF
进程
/usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
配置文件
# more /etc/zabbix/zabbix_agentd.conf|grep -v '#'|grep -v '^$'
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=118.123.123.123
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
UserParameter=pm2_status,/var/shell/check_pm2.sh
子配置文件
more /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf |grep -v '#'|grep -v '^$'
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -N | awk '{print $$2}'
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/var/lib/zabbix mysql -N'
UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V
子配置文件
more /var/shell/check_pm2.sh
#!/bin/bash
source /etc/profile.d/some_env.sh
ret_ok=1
ret_critical=0
b=online
a=`sudo pm2 list |grep "3"|awk -F"│" '{print $10}'|awk '{print $1}'|sed -n 1p`
if [ $a = $b ];then
echo ${ret_ok}
else
echo ${ret_critical}
fi
配置Agent主动模式
参考 https://blog.csdn.net/chengrowe/article/details/96484986
Agent端的调整
LogFile=/tmp/zabbix_agentd.log
StartAgents=0 #客户端的anent的模式. 0表示关闭被动模式, zabbix-agentd不监控本地端口, 就没有zabbix_agentd进程。
Server=14.18.xxx.xxx #如果设置纯被动模式,应该注释掉这行
ServerActive=14.18.xxx.xx #主动模式的serverip地址
Hostname=119.146.xxx.xx #客户端的hostname,不配置则使用主机名
RefreshActiveChecks=120 #被监控端到服务器获取监控项的周期,默认120S
BufferSize=10000 #被监控端存储监控信息的空间大小
MaxLinesPerSecond=200
Timeout=30 #超时时间
Agentd在主动模式下, 不是由Server来收集数据, 而是主动将数据报送给Server, 可以减轻Server压力. 比较重要的参数是ServerActive和Hostname,ServerActive是指定Agentd收集的数据往哪里发送,Hostname是必须要和Server端添加主机时的主机名对应,这样Server端接收到数据才能找到对应关系,如果要兼容被动模式,StartAgents就不用设为0,如果一开始就是使用主动模式的话建议把StartAgents设为0,关闭被动模式.
Server端的调整:
StartPollers=100
首先把这个主动收集数据进程减少
StartTrappers=200
然后把这个负责处理Agentd推送过来的数据的进程开大一些
调整模板, 克隆一个Template OS Linux 模板来改,需要调整的地方就是把所有的item的类型由原来的zabbix代理
改成zabbix端点代理程序(主动式)