标签:tmp net sim aliyun hat form display $nf mic
环境
zabbixserver 10.0.0.12
zabbixproxy 10.0.0.13
#!/bin/bash
# install zabbix-proxy
# version 1.0
# author wangzhen
# date 20190506
OsVersion=`cat /etc/redhat-release|awk -F "." ‘{print $1}‘|grep -o [0-9]`
DbPswd=zabbix
ZabbixServerIp=10.0.0.12
ProxyConfFile=/etc/zabbix/zabbix_proxy.conf
ZabbixRepoUrl6=https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/6/x86_64/zabbix-release-3.4-1.el6.noarch.rpm
ZabbixRepoUrl7=https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
LogFile=$0.log
ConfFile() {
echo "ProxyMode=1
Server=$ZabbixServerIp
Hostname=zabbix_proxy
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=1
PidFile=/var/run/zabbix/zabbix_proxy.pid
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=$DbPswd
ConfigFrequency=600
DataSenderFrequency=1
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000" >$ProxyConfFile
}
CheckInstall() {
##检查端口占用
[ `lsof -i:10051|wc -l` -ne 0 ] && echo ‘prot 10051 already in use .‘ && exit 1
##检查是否已安装
[`rpm -qa |grep zabbix-server|wc -l` -gt 1 ] && echo ‘zabbix server already installed‘ && exit 1
}
ZabbixProxyInstall() {
ZabbixRepoRpm=`echo $ZabbixRepoUrl | awk -F ‘/‘ ‘{print $NF}‘`
#安装zabbix源、aliyun YUM源、zabbix-server、mariadb
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-${OsVersion}.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-${OsVersion}.repo
wget $ZabbixRepoUrl
yum localinstall -y $ZabbixRepoRpm
yum cleal all
yum makecache
yum install -y zabbix-proxy-mysql mariadb-server zabbix-get
}
MysqlConfigure() {
systemctl start mariadb.service
mysql <<EOF
create database zabbix_proxy character set utf8 collate utf8_bin;
grant all privileges on zabbix_proxy.* to zabbix@localhost identified by "$DbPswd";
flush privileges;
EOF
#导入zabbix数据库
ZabbixVersion=`rpm -qa|grep zabbix-proxy|awk -F ‘-‘ ‘{print $4}‘`
zcat /usr/share/doc/zabbix-proxy-mysql-${ZabbixVersion}/schema.sql.gz|mysql -uzabbix -p"$DbPswd" zabbix_proxy
}
ZabbixConfgure() {
cp $ProxyConfFile{,.bak}
##配置文件修改
ConfFile
}
Start() {
systemctl start zabbix-proxy
systemctl enable mariadb
systemctl enable zabbix-proxy
}
Check() {
ls -l
}
main() {
case "$OsVersion" in
6)
ZabbixRepoUrl=$ZabbixRepoUrl6
ZabbixProxyInstall
MysqlConfigure
ZabbixConfgure
Start
Check
;;
7)
ZabbixRepoUrl=$ZabbixRepoUrl7
ZabbixProxyInstall
MysqlConfigure
ZabbixConfgure
Start
Check
;;
*)
echo ‘OsVersion must be 6 or 7‘ >>$log
exit 1
esac
}
main
curl -O https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum localinstall -y zabbix-release-3.4-2.el7.noarch.rpm
yum install -y zabbix-proxy-mysql zabbix-get
yum -y install mariadb-server
systemctl start mariadb.service
## 创建用户
create database zabbix_proxy character set utf8 collate utf8_bin;
grant all privileges on zabbix_proxy.* to zabbix@‘localhost‘ identified by ‘zabbix‘;
## 导入zabbix信息
zcat /usr/share/doc/zabbix-proxy-mysql-3.4.15/schema.sql.gz |mysql -uzabbix -pzabbix zabbix_proxy
[root@zabbix_proxy server]# egrep -v ‘^$|^#‘ /etc/zabbix/zabbix_proxy.conf
ProxyMode=1
Server=10.0.0.12
Hostname=zabbix_proxy_aws
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=1
PidFile=/var/run/zabbix/zabbix_proxy.pid
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=distsh
ConfigFrequency=600
DataSenderFrequency=1
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
# Hostname 作为后面添加的代理程序名称,要保持一致
Server=服务端ip #真正的服务端
ServerPort=18103 #根据个人需要修改,一般可以不改,默认端口是10051,要实现转发的话使用这个选项
Hostname=153Zabbix proxy #proxy的hostname,在web端网页配置时需要用到
DBHost=localhost #数据库,使用本地,也可以使用ip,我喜欢使用localhost,因为我授权就是本地,也因为配置ip失败踩过坑
DBName=zabbix_proxy #数据库名称,创建zabbix-proxy的mysql的数据库名称
DBUser=zabbix #用户
DBPassword=zabbix #密码
#DBPort=3306 #当DBHost填写localhost时,默认是使用socket通信的,这里配置一下也无碍
#HeartbeatFrequency=60 #心跳线(具体作用网了,看配置文件吧,这个默认就是60)
ConfigFrequency=600 #这个好像是同步配置文件的时间
DataSenderFrequency=1 #这个是proxy端向server端发送数据的时间,单位是秒,几乎等于实时同步
ProxyMode=1 # 0 代表 Proxy 处于主动模式,即:Proxy 主动去请求 Zabbix Server 获取监控项;1 代表被动模式
Server=10.0.0.12 # Zabbix Server 地址,当 Proxy 处于被动模式时,不需要设置该项 ( 想想也能明白 )
ServerPort=10051 # Zabbix Server 监听端口,同上只在 Proxy 为主动模式时生效
LogFile=/tmp/zabbix_proxy.log # Proxy 日志文件位置
ConfigFrequency=60 # Proxy 向 Zabbix Server 请求监控项间隔,单位为 秒
DataSenderFrequency=60 # Proxy 向 Zabbix Server 发送监控数据间隔,单位为 秒
#启动
systemctl restart zabbix-proxy.service
修改客户端信息
vim /etc/zabbix/zabbix_agentd.conf
Server=10.0.0.13 ##Server=proxy的ip
ServerActive=10.0.0.13 ##ServerActive=proxy的ip
[root@cache01 ~]# systemctl restart zabbix-agent.service
#检查端口
[root@zabbix_proxy ~]# netstat -lntup |grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 105762/zabbix_agent
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 85273/zabbix_proxy
tcp6 0 0 :::10050 :::* LISTEN 105762/zabbix_agent
tcp6 0 0 :::10051 :::* LISTEN 85273/zabbix_proxy
[root@zabbix_proxy ~]# zabbix_get -s 10.0.0.13 -k system.uname
Linux centos7.5 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64
标签:tmp net sim aliyun hat form display $nf mic
原文地址:https://www.cnblogs.com/wzstudy/p/10821095.html