Zabbix是一款分布式监控系统,基于C/S模式,需在服务器安装zabbix_server,在客户端安装zabbix_agent,通过shell脚本可以更快快速地实现该需求。
shell 脚本实现Zabbix服务端和客户端自动安装:
Zabbix 软件的版本源码安装、路径、--enable-server、--enable-agent;
cpzabbix_agentd启动进程至/etc/init.d/zabbix_agentd,执行X权限;
配置zabbix_agentd.conf文件,指定serverIP变量;
指定客户端的Hostname,可以写成客户端IP地址;
启动zabbix_agentd服务,创建Zabbixuser。
shell 脚本实现Zabbix服务端和客户端自动安装:
#!/bin/bash
#Auto install zabbixserver and client
#By author tang.com2018
#Define Path variables
ZABBIX_SOFT="zabbix-3.2.6.tar.gz"
INSTALL_DIR="/usr/local/zabbix/"
SERVER_IP="192.168.9.99"
IP=`ifconfig |grep"broadcast" |tail -1 |awk '{print $2}'`
SERVER_INSTALL(){
yum -y install curlcurl-devel net-snmp net-snmp-devel perl-DBI
groupadd zabbix;useradd-g zabbix -s /sbin/nologin zabbix -M
tar -xzf$ZABBIX_SOFT;cd `echo $ZABBIX_SOFT|sed 's/.tar.*//g'`
./configure--prefix=/usr/local/zabbix --enable-server --enable-agent --with-msyql--enable-ipv6 --with-net-snmp --with-libcurl && make install
if [ $? -eq 0 ];then
ln-s /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/
fi
cd - ;cd zabbix-3.2.6
cpmisc/inti.d/tru64/{zabbix_agentd,zabbix_server} /etc/init.d/ ;chmod o+x/etc/init.d/zabbix_*
mkdir -p/var/www/html/zabbix/; cp -a frontends/php/* /var/www/html/zabbix/
#config zabbix server
cat >$INSTALL_DIR/etc/zabbix_server.conf <<EOF
LogFile=/tmp/zabbix_server.log
DBHost=locahost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
EOF
#config zabbix agentd
cat>$INISTALL_DIR/etc/zabbix_agentd.conf<<EOF
LogFile=/tmp/zabbix_agentd.log
Server=$SERVER_IP
ServerActive=$SERVER_IP
Hostname=$IP
EOF
#start zabbix agentd
/etc/init.d/zabbix_serverrestart
/etc/init.d/zabbix_agentdrestart
/etc/init.d/iptablesstop
setenforce 0
}
AGENT_INSTALL(){
yum -y install curlcurl-devel net-snmp net-snmp-devel perl-DBI
groupadd zabbix;useradd-g zabbix -s /sbin/nologin zabbix -M
tar -xzf$ZABBIX_SOFT;cd `echo $ZABBIX_SOFT|sed 's/.tar.*//g'`
./configure--prefix=/usr/local/zabbix --enable-agent && make install
if [ $? -eq 0 ];then
ln -s /usr/local/zabbix/sbin/zabbix_*/usr/local/sbin/
fi
cd - ;cd zabbix-3.2.6
cpmisc/inti.d/tru64/zabbix_agentd /etc/init.d/zabbix_agentd ;chmod o+x/etc/init.d/zabbix_agentd
mkdir -p/var/www/html/zabbix/; cp -a frontends/php/* /var/www/html/zabbix/
#config zabbix agentd
cat >$INSTALL_DIR/etc/zabbix_agentd.conf <<EOF
LogFile=/tmp/zabbix_agentd.log
Server=$SERVER_IP
ServerActive=$SERVER_IP
Hostname=$IP
EOF
#start zabbix agentd
/etc/init.d/zabbix_agentdrestart
/etc/init.d/iptablesstop
setenforce 0
}
read -p "Pleaseconfirm whether to install Zabbix Server,yes or no ?" INPUT
if [ $INPUT =="y" -o $INPUT == "yes" ];then
SERVER_INSTALL
else
AGENT_INSTALL
fi