zabbix性能监控平台-监控服务自动化-nginx监控
部署jenkins的机器当做推送机对远程部署的机器进行免密,请参考以前的文章
Linux下实现免密登录
编写shell自动化搭建-nginx监控脚本,脚本内容如下
nginx_create_remote_sync.sh
#!/bin/bash#init paramsourcePath=$1remoteTargetPath=$2remoteip=$3zabbix_server_ip=$4shellFileName=nginx_zabbix_agent_auto_config.shshellPath=/root/tools/shell/nginx/remote/remote_create_and_zabbix_agent_config/$shellFileNamefunction remote_sync(){#remote create targetPathssh root@$remoteip "rm -rf $remoteTargetPath && mkdir -p $remoteTargetPath"#sync file to remote linuxscp $sourcePath/* root@$remoteip:$remoteTargetPath#sync shell to remote linux for execscp $shellPath root@$remoteip:$remoteTargetPath#exec remote shellssh root@$remoteip "chmod 755 $remoteTargetPath/$shellFileName"ssh root@$remoteip "sh $remoteTargetPath/$shellFileName $remoteTargetPath $zabbix_server_ip"}remote_sync
nginx_zabbix_agent_auto_config.sh
#!/bin/bashlocalPath=$1zabbix_server_ip=$2function zabbin_agent_install(){cd $localPathrpm -ivh zabbix-agent-3.4.2-1.el7.x86_64.rpmyum install -y zabbix-agent}function zabbin_agent_config(){#get iplocalIp=$(ifconfig -a | grep inet | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}' | awk 'NR==1')cp $localPath/nginx.conf nginx_status.sh /etc/zabbix/zabbix_agentd.d/rm -rf /etc/zabbix/zabbix_agentd.confcp $localPath/zabbix_agentd.conf /etc/zabbixsed -i 's/Server=127.0.0.1/Server='$zabbix_server_ip'/g' /etc/zabbix/zabbix_agentd.confsed -i 's/ServerActive=127.0.0.1/ServerActive='$zabbix_server_ip'/g' /etc/zabbix/zabbix_agentd.confsed -i 's/Hostname=Zabbix server/Hostname='$localIp'/g' /etc/zabbix/zabbix_agentd.confsed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1/g' /etc/zabbix/zabbix_agentd.conf}function zabbin_agent_start(){pkill -9 zabbixsystemctl start zabbix-agent.service}zabbin_agent_installzabbin_agent_configzabbin_agent_start
将脚本放在指定目录/root/tools/shell/nginx/remote/remote_create_and_zabbix_agent_config下
将以下相关文件放在指定目录/root/tools/shell/nginx/monitor下
nginx.confnginx_status.shnginx_templates.xml #nginx模板 需要zabbix web平台导入模板zabbix-agent-3.4.2-1.el7.x86_64.rpmzabbix_agentd.conf
相关文件下载地址
链接:/s/1HMjz7OEAI4GV7wc5J7sZHw
提取码:694p
jenkins的任务创建和之前的文章一样,这里就不多说了直接上图
time sh /root/tools/shell/nginx/remote/remote_create_and_zabbix_agent_config/nginx_create_remote_sync.sh $sourcePath $remoteTargetPath $remoteip $zabbix_server_ip
zabbix平台导入模板
主机链接模板
最终效果