ZABBIX通过客户端自动向服务器注册的简单实现

由客户端代理发起的注册

一、首先得在服务器端创建一条自动注册的规则

 

添加触发条件和自动发生的操作

 

 

二、安装客户端

客户端的安装方式和我前面的文章写的自动化安装脚本差不多,就是在zabbix_agentd.conf增加了HostMetadataItem=system.uname的配置

[root@v73 tmp]# cat inall.sh 
#!/bin/bash
cat pwd.txt | while read line
do
hostip=`echo $line | cut -d" " -f1`
uname=`echo $line | cut -d" " -f2`
pwd=`echo $line | cut -d" " -f3`

/usr/bin/expect <<-EOF
set timeout 600
spawn scp -r /tmp/zabbix-4.0.16.tar.gz $uname@$hostip:/tmp/
expect {
 "*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$pwd\r" }
}
spawn scp -r /tmp/3.sh $uname@$hostip:/tmp/
 expect {
 "*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$pwd\r" }
}
spawn ssh $uname@$hostip
 expect {
 "*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$pwd\r" }
}
expect "*]#"
send "chmod +x /tmp/3.sh\r"
expect "*]#"
send "sh /tmp/3.sh\r"
expect "*]#"
send "exit\r"
interact
expect eof
EOF

done

 

[root@v73 tmp]# cat 3.sh
#!/bin/bash
yum -y install pcre*
egrep "^zabbix" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd zabbix
fi
egrep "^zabbix" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    useradd -g zabbix zabbix -s /sbin/nologin
fi
cd /tmp/
tar -zxvf /tmp/zabbix-4.0.16.tar.gz
cd /tmp/zabbix-4.0.16/
./configure --prefix=/usr/local/zabbix-agent --enable-agent
make
make install
cd /tmp/zabbix-4.0.16/misc
cp init.d/tru64/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
cp -r /etc/init.d/zabbix_agentd /tmp/zabbix_agentd.bak
sed -i 's/DAEMON=\/usr\/local\/sbin\/zabbix_agentd/DAEMON=\/usr\/local\/zabbix-agent\/sbin\/zabbix_agentd/g' /etc/init.d/zabbix_agentd
sed -i '/#!\/bin\/sh/a\#chkconfig: 345 95 95' /etc/init.d/zabbix_agentd
sed -i '/#chkconfig: 345 95 95/a\#description: Zabbix_Server' /etc/init.d/zabbix_agentd
chkconfig zabbix_agentd on
sed -i 's/Server=127.0.0.1/Server=192.168.156.73/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive=192.168.156.73/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
HOSTNAME=`hostname`
sed -i 's/Hostname=Zabbix server/Hostname='$HOSTNAME'/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
sed -i 's/LogFile=\/tmp\/zabbix_agentd.log/LogFile=\/var\/log\/zabbix\/zabbix_agentd.log/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
sed -i '/# HostMetadataItem=/a\HostMetadataItem=system.uname' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
mkdir -p /var/log/zabbix
chown -R zabbix.zabbix /var/log/zabbix/
chown -R zabbix.zabbix /usr/local/zabbix-agent/

/etc/init.d/zabbix_agentd start

 

 

 

三、执行安装

安装完成服务启动后,自动注册

在服务器WEB管理控制台已经可以看到主机了

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页