环境准备
主机 | 外网ip | 内网ip |
---|---|---|
server | 10.0.0.101 | |
proxy | 10.0.0.102 | 172.16.1.102 |
agent01 | 172.16.1.103 | |
agent02 | 172.16.1.104 | |
win | 192.168.45.171 |
server
#如下步骤可以写进sh脚本中,直接运行
#使用服务端快速部署脚本
#!/bin/bash
# 2021/8/11
#设置解析 注意:网络条件较好时,可以不用自建yum源
# echo '10.0.0.1 mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com' >> /etc/hosts
#安装zabbix源、aliyun YUM源
#curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
#安装zabbix
yum install -y zabbix-server-mysql zabbix-web-mysql
#安装启动 mariadb数据库
yum install -y mariadb-server
systemctl start mariadb.service
#创建数据库
mysql -e 'create database zabbix character set utf8 collate utf8_bin;'
mysql -e 'grant all privileges on zabbix.* to zabbix@localhost identified by "zabbix";'
#导入数据
zcat /usr/share/doc/zabbix-server-mysql-3.4.15/create.sql.gz|mysql -uzabbix -pzabbix zabbix
#配置zabbixserver连接mysql
sed -i.ori '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
#添加时区
sed -i.ori '18a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
#解决中文乱码
yum -y install wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
#启动服务
systemctl start zabbix-server
systemctl start httpd
#写入开机自启动
systemctl enable mariadb.service
systemctl enable httpd
systemctl enable zabbix-server
#输出信息
echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"
grep ^[a-Z] /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
proxy
#安装proxy 推荐使用yum 因为可以解决依赖包的问题
yum localinstall -y https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-proxy-mysql-3.4.15-1.el7.x86_64.rpm
#配置MySQL5.6的yum源
vim /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=0
#安装MySQL
sudo yum install mysql-community-server
#启动MySQL并加入开机自启
sysytemctl start mysqld
sysytemctl enable mysqld
#检查MySQL状态
sysytemctl status mysqld
#创建数据库
mysql
#创建数据库
create database zabbix_proxy charset utf8;
#创建用户
grant all privileges on zabbix_proxy.* to zabbix@'localhost' identified by 'zabbix';
quit
#导入数据
#查看相关文件
rpm -ql zabbix-proxy-mysql
/usr/share/doc/zabbix-proxy-mysql-3.4.15/schema.sql.gz
#导入
zcat /usr/share/doc/zabbix-proxy-mysql-3.4.15/schema.sql.gz |mysql -uzabbix -pzabbix zabbix_proxy
#查看数据库
mysql -uzabbix -pzabbix
show databases;
use zabbix_proxy;
show tables;
quit
#配置proxy文件
grep ^[a-Z] /etc/zabbix/zabbix_proxy.conf
Server=10.0.0.101
Hostname=zabbix-proxy
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=zabbix
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
#启动proxy并加入开机自启
systemctl start zabbix-proxy
systemctl enable zabbix-proxy
netstat -lntp
agent
#2台agent都是同样的配方
#安装agent
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.15-1.el7.x86_64.rpm
#配置agent
grep ^[a-Z] /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.16.1.102
ServerActive=172.16.1.102
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#启动agnet并加入开机自启
systemctl start zabbix-agent
systemctl enable zabbix-agent
netstat -lntp
添加agent代理程序
手动添加主机
# 因为agent发生的数据到proxy再到server 会有点慢
我们可以直接重启服务
systemctl restart zabbix-agent
systemctl restart zabbix-proxy
web页面--监测中--最新数据
自定义监控项
监控系统登录状态,若登录xshell用户超过2个用户,则触发报警
uptime |awk '{print $4}'
vim /etc/zabbix/zabbix_agentd.conf
UserParameter=login.number,uptime |awk '{print $4}'
systemctl restart zabbix-agent.service
#检查是否生效
zabbix_agentd -p
login.number [t|1]
## proxy安装zabbix-get
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-get-3.4.15-1.el7.x86_64.rpm
## 检查是否可以识别该监控项目
zabbix_get -s 172.16.1.103 -k login.number
web页面--监测中--最新数据
我们在agent01上打开多个xshell,会监测到值,同事仪表板上回报警
win-agent
https://cdn.zabbix.com/zabbix/binaries/stable/3.4/3.4.6/zabbix_agent-3.4.6-windows-i386.zip
#解压到C盘下 zabbix文件夹里
修改 conf文件
1、LogFile=C:\zabbix\zabbix_agentd.log
2、Server=192.168.45.171,10.0.0.102
#本机名,也可以在cmd下使用hostname命令获得
3、Hostname=daizeyu
4、ServerActive=10.0.0.102
修改完成后cmd进入到解压目录,
#切换目录进入
>cd C:\zabbix\bin\win32
#安装
>zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -i
#启动agent
>zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -s
#检查zabbix-agent是否正常启动
>netstat -an | findstr "10050"
-c:指定配置文件位置
-i:安装agent
-s:启动
-x:停止agent
-d:卸载agent
#3、更改防火墙
开始——控制面板——系统和安全——windows防火墙——高级设置——入站规则——新建规则——端口——特定本地端口——端口号xxx——
#web页面添加主机 关联模板
标签:zabbix3,3.4,agent,server,zabbix,proxy,mysql
From: https://www.cnblogs.com/ycmyay/p/17383833.html