zabbix性能监控平台-监控服务自动化-nginx监控
zabbix性能监控平台-监控服务自动化-nginx监控部署jenkins的机器当做推送机对远程部署的机器进行免密,请参考以前的文章Linux下实现免密登录编写shell自动化搭建-nginx监控脚本,脚本内容如下nginx_create_remote_sync.sh#!/bin/bash#init paramsourcePath=$1remoteTargetPath=$2remoteip=$3z
·
zabbix性能监控平台-监控服务自动化-nginx监控
部署jenkins的机器当做推送机对远程部署的机器进行免密,请参考以前的文章
Linux下实现免密登录
编写shell自动化搭建-nginx监控脚本,脚本内容如下
nginx_create_remote_sync.sh
#!/bin/bash
#init param
sourcePath=$1
remoteTargetPath=$2
remoteip=$3
zabbix_server_ip=$4
shellFileName=nginx_zabbix_agent_auto_config.sh
shellPath=/root/tools/shell/nginx/remote/remote_create_and_zabbix_agent_config/$shellFileName
function remote_sync(){
#remote create targetPath
ssh root@$remoteip "rm -rf $remoteTargetPath && mkdir -p $remoteTargetPath"
#sync file to remote linux
scp $sourcePath/* root@$remoteip:$remoteTargetPath
#sync shell to remote linux for exec
scp $shellPath root@$remoteip:$remoteTargetPath
#exec remote shell
ssh 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/bash
localPath=$1
zabbix_server_ip=$2
function zabbin_agent_install(){
cd $localPath
rpm -ivh zabbix-agent-3.4.2-1.el7.x86_64.rpm
yum install -y zabbix-agent
}
function zabbin_agent_config(){
#get ip
localIp=$(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.conf
cp $localPath/zabbix_agentd.conf /etc/zabbix
sed -i 's/Server=127.0.0.1/Server='$zabbix_server_ip'/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive='$zabbix_server_ip'/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/Hostname=Zabbix server/Hostname='$localIp'/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1/g' /etc/zabbix/zabbix_agentd.conf
}
function zabbin_agent_start(){
pkill -9 zabbix
systemctl start zabbix-agent.service
}
zabbin_agent_install
zabbin_agent_config
zabbin_agent_start
将脚本放在指定目录/root/tools/shell/nginx/remote/remote_create_and_zabbix_agent_config下
将以下相关文件放在指定目录/root/tools/shell/nginx/monitor下
nginx.conf
nginx_status.sh
nginx_templates.xml #nginx模板 需要zabbix web平台导入模板
zabbix-agent-3.4.2-1.el7.x86_64.rpm
zabbix_agentd.conf
链接:https://pan.baidu.com/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平台导入模板
主机链接模板
最终效果
更多推荐
已为社区贡献2条内容
所有评论(0)