Linux under Zabbix agentd client plug-in Shell one-click Automatic installation Script

Source: Internet
Author: User
Tags chmod mkdir

The production environment on the line of more than one Linux server, the need to all into the Zabbix monitoring category, a Taiwan to install Zabbix Agentd plug-ins that is too hard, fortunately Zabbix client plug-in is to support the green installation, wrote a simple one-click installation script, and then cooperate with Multi-Window interactive commands for Secure CRT can be done at once.

Normal boot Zabbix Client service actually requires only 2 files: Zabbix_agentd and zabbix_agentd.conf, it needs to be specifically stated: Zabbix_agentd is best compiled with Zabbix_server, The path to the warranty version and configuration file is consistent, or you may not be able to use the service startup mode of the Linux system.

First, preparatory work
Zabbix host must set up a Web service, so just can put the required to the Web directory, easy to download.

The client plug-in Zabbix_agentd is located in the Sbin directory under the Zabbix installation directory, such as:/usr/local/zabbix/sbin/zabbix_agentd

The Service control script Zabbix_agentd is located in the Zabbix source compilation directory Misc/init.d/fedora/core/zabbix_agentd

All we have to do is copy these files to the Web directory, such as/var/www/html/zabbix_agent/, and depending on the system version, we can prepare the 64 and 32-bit ZABBIX_AGENTD for subsequent installations under different systems.

After copying, manually verify that the file is available for download:

Client Plug-ins: Http://192.168.1.40/zabbix_agent/64/zabbix_agentd

Service Control script: Http://192.168.1.40/zabbix_agent/init.d/zabbix_agentd

Second, write a script

①, save the following code as zabbix_agentd.sh and upload to the Zabbix_agent directory in the first step.

#!/bin/bash
#Desc: Install Zabbix Agent in Onekey.
#Date: 2015-04-02
#Author: Zhangge

#设置zabbix服务器地址
If [-Z $]
Then
Server= "192.168.1.40"
Else
Server=$1
Fi

#检测相关
function Check () {
NETSTAT-NTLP | grep zabbix_agentd >/dev/null && echo "Exit for ZABBIX_AGENTD has been already." && exit
Test-f zabbix_agent.sh && rm-f zabbix_agent.sh
Test-f/usr/local/zabbix/sbin/zabbix_agentd && Rm-rf/usr/local/zabbix/sbin/zabbix_agentd
Test-f/etc/init.d/zabbix_agentd && rm-f/etc/init.d/zabbix_agentd
}

#配置相关
function Config () {
Server=$1

#获取IP
ip= "' Ifconfig | grep 192.168 | grep "inet Addr:" | Awk-f "Bcast:" ' {print $} ' | Awk-f "inet addr:" ' {print $} '

Mkdir/usr/local/zabbix/sbin/-P
mkdir/usr/local/zabbix/etc/-P
cd/usr/local/zabbix/sbin/

#写入配置文件
Cat >/usr/local/zabbix/etc/zabbix_agentd.conf <<eof
Server=${server}
HOSTNAME=${IP}
buffersize=1024
debuglevel=2
logfilesize=1024
Enableremotecommands=1
#Include =/etc/zabbix/zabbix_command.conf
Eof
}

function Install () {
Config $

#下载服务控制脚本
Wget-p/etc/init.d/http://192.168.1.40/zabbix_agent/init.d/zabbix_agentd

#判断系统位数, download different versions
if [["$ (uname-m)" = "x86_64"]]
Then
wget Http://192.168.1.40/zabbix_agent/64/zabbix_agentd
Else
wget Http://192.168.1.40/zabbix_agent/32/zabbix_agentd
Fi
chmod +x/etc/init.d/zabbix_agentd
chmod +x/usr/local/zabbix/sbin/zabbix_agentd

#新增用户和用户组
Groupadd Zabbix
Useradd-s/sbin/nologin-m-G Zabbix Zabbix

#启动服务并加入开启启动
Service Zabbix_agentd start && chkconfig zabbix_agentd on
echo---------------------result---------------------------------

#检查安装结果
NETSTAT-NTLP | grep zabbix_agentd && echo-e "\033[33minstall succeed.\033[0m" | | echo-e "\033[31minstall failed.\033[0m"
}

#main
Check
Install $Server

②, Service Control scripts

For convenience of friends who do not find Zabbix Agent service Control scripts, provide additional service control code. Save the code as ZABBIX_AGENTD and upload to the first step of the zabbixz_agent/init.d/directory for backup.


#!/bin/sh
#chkconfig: 345 95 95
#description: Zabbix Agent
# Zabbix
# Copyright (C) 2001-2013 Zabbix SIA
#
# this are free software; You can redistribute it and/or modify
# It under the terms of the GNU general public License as published by
# the free Software Foundation; Either version 2 of the License, or
# (at your option) any later version.
#
# This are distributed in the hope that it'll be useful,
# but without any WARRANTY; Without even the implied warranty of
# merchantability or FITNESS for A particular purpose. The
# GNU general public License for more details.
#
# You should have received a copy of the GNU general public License
# along with this program; If not, write to the free Software
# Foundation, Inc., Wuyi Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Start/stop the Zabbix Agent daemon.
# Place a startup script in/sbin/init.d, and link to it FROM/SBIN/RC[023].D
Service= "Zabbix Agent"
Daemon=/usr/local/zabbix/sbin/zabbix_agentd
Pidfile=/tmp/zabbix_agentd.pid
Basedir=/usr/local/zabbix
zabbix_agentd= $BASEDIR/sbin/zabbix_agentd
Case is in
' Start ')
If [-X ${daemon}]
Then
$DAEMON
# Error checking here would to be good ...
echo "${service} started."
Else
echo "Can ' t find file ${daemon}."
echo "${service} not started."
Fi
;;
' Stop ')
If [-s ${pidfile}]
Then
If kill ' cat ${pidfile} ' >/dev/null 2>&1
Then
echo "${service} stoped."
Rm-f ${pidfile}
Fi
Fi
;;
' Restart ')
$ stop
Sleep 10
$ start
;;
*)
echo "Usage: $ start|stop|restart"
;;
Esac

Iii. Methods of Use

Log on to the client system, and run the following command to install one click:

①, using the default Zabbix_server IP address:

wget http://192.168.1.40/zabbix_agent/zabbix_agent.sh && chmod +x zabbix_agent.sh &&/zabbix_ agent.sh

②, followed by an IP parameter can be specified to another zabbix_server or zabbix_proxy:


wget http://192.168.1.40/zabbix_agent/zabbix_agent.sh && chmod +x zabbix_agent.sh &&/zabbix_ Agent.sh 192.168.1.41
Secure CRT Multi-session interactive execution:

Other Description: The ZABBIX_AGENTD compilation path (prefix) in this script is/usr/local/zabbix, if this is not the path to compile, you need to modify the relevant path in the script according to the actual situation, otherwise the registered Zabbix_ The AGENTD service will not start, it can only be started through the command line!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.