zabbix自动注册,实现自动添加机器,减少人工干预

1.zabbix_agent的安装配置:

vim install_zabbix_agent.sh 

#!/bin/bash
#author:chenjianwen

RealIP=`curl -s http://members.3322.org/dyndns/getip`
## 若zabbix服务端地址改变,修改此处即可
zabbix_server_ip=115.xx.xx.xx

yum_list_install(){
        yum install -y pcre pcre-devel
}
backup_agent_old(){
killall -9 zabbix_agentd mv /usr/local/zabbix /usr/local/zabbix-old } scp_agent(){ scp -r 115.xxx.xxx.xxx:/data/source/zabbix-3.4.5.tar.gz . tar xvf zabbix-3.4.5.tar.gz } install_agent(){ cd zabbix-3.4.5 ./configure --prefix=/usr/local/zabbix --enable-agent if [ $? == 0 ];then make -j 4 if [ $? == 0 ];then make install ##编辑配置文件 sed -i 's/Server\=127.0.0.1/Server\='${zabbix_server_ip}'/g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i 's/ServerActive\=127.0.0.1/ServerActive\='${zabbix_server_ip}'/g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i 's/Hostname\=Zabbix server/Hostname\='${RealIP}'/g' /usr/local/zabbix/etc/zabbix_agentd.conf echo "HostMetadata=dddjs" >> /usr/local/zabbix/etc/zabbix_agentd.conf  #指定元数据,用于自动注册标识,一般是项目英文名 echo "UserParameter=mysql.status[*],/usr/local/zabbix/share/script/mysql_check.sh \$1" >> /usr/local/zabbix/etc/zabbix_agentd.conf echo "UserParameter=tcp_port_listen,/usr/local/zabbix/share/script/get_game_port.py" >> /usr/local/zabbix/etc/zabbix_agentd.conf #echo "UserParameter=tcp_port_listen,/usr/local/zabbix/share/script/get_game_port_center.py" >> /usr/local/zabbix/etc/zabbix_agentd.conf echo "UserParameter=MongoDB.Status[*],/usr/local/zabbix/share/script/mongodb_status.sh \$1" >> /usr/local/zabbix/etc/zabbix_agentd.conf mkdir -p /usr/local/zabbix/share/script/ cp -r /root/dddjs_sysinit/zabbix_scripts/mysql_check.sh /usr/local/zabbix/share/script/ && chmod +x /usr/local/zabbix/share/script/mysql_check.sh cp -r /root/dddjs_sysinit/zabbix_scripts/mongodb_status.sh /usr/local/zabbix/share/script/ && chmod +x /usr/local/zabbix/share/script/mongodb_status.sh cp -r /root/dddjs_sysinit/zabbix_scripts/get_game_port.py /usr/local/zabbix/share/script/ && chmod +x /usr/local/zabbix/share/script/get_game_port.py #cp -r /root/dddjs_sysinit/zabbix_scripts/get_game_port_center.py /usr/local/zabbix/share/script/ && chmod +x /usr/local/zabbix/share/script/get_game_port_center.py else echo "编译失败" exit fi else echo "预编译失败" exit fi } start_agent(){ useradd -s /sbin/nologin zabbix /usr/local/zabbix/sbin/zabbix_agentd echo "/usr/local/zabbix/sbin/zabbix_agentd" >> /etc/rc.local } yum_list_install backup_agent_old scp_agent install_agent start_agent

2.zabbix界面操作:配置--》动作--》自动注册--》创建动作

 

 

 

posted @ 2019-12-03 17:28  chenjianwen  阅读(215)  评论(0编辑  收藏  举报