目录
一、服务端安装
1.1 安装zabbix5.0存储库(二进制安装方式)
rpm-Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
1.2 安装zabbix软件包
yum install zabbix-server-mysql zabbix-agent -y
可选配置:如果官方仓库无法连接,可将仓库地址改为清华大学,下边是清华大学仓库地址
vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch baseurl=https://mirrors.tuna.tsinghua.edu.cn/ zabbix/zabbix/5.0/rhel/7/$basearch/
enabled=1 gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-
ZABBIX-A14FE591
[zabbix-frontend]
name=Zabbix Official Repository frontend -
$basearch baseurl=https://mirrors.tuna.tsinghua.edu.cn/ zabbix/zabbix/5.0/rhel/7/$basearch/frontend enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-
ZABBIX-A14FE591
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo -
$basearch baseurl=https://mirrors.tuna.tsinghua.edu.cn/ zabbix/zabbix/5.0/rhel/7/$basearch/debuginfo/ enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-
ZABBIX-A14FE591
gpgcheck=0
[zabbix-non-supported]
name=Zabbix Official Repository non-supported
- $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/ enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY- ZABBIX
gpgcheck=0
启用zabbix-frontend存储库
vim /etc/yum.repos.d/zabbix.repo
...
[zabbix-frontend]
name=Zabbix Official Repository frontend -
$basearch baseurl=https://mirrors.tuna.tsinghua.edu.cn/ zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1 #启用仓库
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY- ZABBIX-A14FE591
1.3 安装Zabbix前端软件包
zabbix-web-mysql-scl 用于连接数据库
zabbix-apache-conf-scl 用于连接apache
yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
1.4 安装数据库软件
yum install -y mariadb-server
systemctl start mariadb
systemctl enable mariadb
1.5 数据库配置
#进入数据库
mysql
创建存储数据的库,并支持中文(库名:zabbix)
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
#授权连接数据库的用户,并设置密码(用户名:zabbix)
MariaDB [(none)]> create user zabbix@localhost identified by '123456';
#数据库授权
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
#查看所有库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.01 sec)
#进入zabbix库
MariaDB [(none)]> use zabbix;
Database changed
#查看当前库下表
MariaDB [zabbix]> show tables;
Empty set (0.00 sec) #空
#在Zabbix服务器主机上,导入初始架构和数据。系统将提示您输
入新创建的密码
zcat /usr/share/doc/zabbix-server- mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: password #输入zabbix用户密码
#Zabbix服务器配置数据库
vim /etc/zabbix/zabbix_server.conf
100 DBName=zabbix #存储监控数据的库名
116 DBUser=zabbix #连接数据库的用户
124 DBPassword=123456 #设置zabbix用户密码
#为Zabbix配置正确的时区
vim /etc/opt/rh/rh- php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai #亚洲/上海
1.6 启动并查看
#启动所有服务
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
#设置服务随机自启
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
#查看zabbix服务占用端口信息
netstat -anptul | grep zabbix
tcp LISTEN 0 128 *:10051
#zabbix-server端口
tcp LISTEN 0 128 *:10050
#zabbix-agent端口
1.7 zabbix服务端一件安装脚本
#!/bin/bash
#Zabbix-Server 5.0
#安装zabbix源、aliyun YUM源
cd /etc/yum.repos.d/
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i.bak 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#' zabbix.repo
sed -i 's#enabled=0#enabled=1#' zabbix.repo
#安装zabbix
yum -y install zabbix-server-mysql zabbix-agent
yum -y install centos-release-scl
yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
#安装启动 mariadb数据库
yum -y install mariadb mariadb-server httpd
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";'
mysql -e 'flush privileges;'
#导入数据
zcat /usr/share/doc/zabbix-server-mysql-5.0.3/create.sql.gz|mysql -uzabbix -pzabbix -Dzabbix
#配置zabbixserver连接mysql
sed -i.bak '/^# DBPassword=*/i DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
#添加时区
sed -i.bak '/^; php_value[date.timezone]*/i php_value[date.timezone] = Asia/Shanghai' /etc/opt/rh/rh-php72/php-fpm.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 restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
#开机自启动
systemctl enable mariadb.service
systemctl enable httpd
systemctl enable zabbix-server
#输出信息
echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"
二、Zabbix服务参数介绍
zabbix server服务名:zabbix-server 端口:10051
zabbix agent服务名:zabbix-agent端口:10050
zabbix server主配置文件:/etc/zabbix/zabbix_server.conf
zabbix agent主配置文件:/etc/zabbix/zabbix_agentd.conf
zabbix企业微信报警脚本路径:/usr/lib/zabbix/alertscripts
zabbix自定义监控项路径:/etc/zabbix/zabbix_agentd.d zabbix
日志文件路径:/var/log/zabbix/
三、部署被监控主机
3.1 修改源
rpm-ivh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.24-1.el7.x86_64.rpm
3.2 下载客户端agent包 并查看
yum install -y zabbix-agent
rpm -ql zabbix-agent
/etc/logrotate.d/zabbix-agent
/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.d
/usr/lib/systemd/system/zabbix-agent.service
/usr/lib/tmpfiles.d/zabbix-agent.conf
/usr/sbin/zabbix_agentd
/usr/share/doc/zabbix-agent-5.0.24
/usr/share/doc/zabbix-agent-5.0.24/AUTHORS
/usr/share/doc/zabbix-agent-5.0.24/COPYING
/usr/share/doc/zabbix-agent-5.0.24/ChangeLog
/usr/share/doc/zabbix-agent-5.0.24/NEWS
/usr/share/doc/zabbix-agent-5.0.24/README
/usr/share/doc/zabbix-agent-5.0.24/userparameter_mysql.conf
/usr/share/man/man8/zabbix_agentd.8.gz
/var/log/zabbix
/var/run/zabbix
3.3 修改agent配置文件
vim /etc/zabbix/zabbix_agentd.conf
117 Server=192.168.0.110 #指定zabbix server地 址
#启动服务并设置服务随机自启
systemctl start zabbix-agent
systemctl enable zabbix-agent
3.4 安装nginx的web服务
#创建nginx仓库文件
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$rel easever/$basearch/
gpgcheck=1 enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.k ey
module_hotfixes=true
#测试仓库
yum repolist
#安装nginx
yum -y install nginx
vim /etc/nginx/conf.d/default.conf
#开启nginx的状态页面
location = /status {
stub_status;
}
#启动服务&设置服务随机自启
systemctl restart nginx
systemctl enable nginx
#访问测试
http://192.168.223.10/
http://192.168.223.10/status #访问状态页面
#状态页面含义解释:
active #当前活动用户的连接数量
accepts #接受的客户端连接总数量
handled #处理的连接总数量 requests #客户端请求的总数量
reading #nginx正在读取请求标头的当前连接数
writing #nginx 将响应写回客户端的当前连接数
waiting #当前客户端正在等待服务器的响应数量
3.5 zabbix客户端一键安装脚本
#!/bin/bash
#Zabbix-Agent 5.0
Zabbix_Service=192.168.10.13
#安装zabbix源、aliyun YUM源
cd /etc/yum.repos.d/
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i.bak 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#' zabbix.repo
sed -i 's#enabled=0#enabled=1#' zabbix.repo
#安装zabbix
yum -y install zabbix-agent
#修改配置文件
sed -i.bak "s/^Server=127.0.0.1/Server=$Zabbix_Service/" /etc/zabbix/zabbix_agentd.conf
sed -i "s/^ServerActive=127.0.0.1/ServerActive=$Zabbix_Service/" /etc/zabbix/zabbix_agentd.conf
sed -i "/^Hostname=/c Hostname=$(echo `hostname`)" /etc/zabbix/zabbix_agentd.conf
#开启zabbix-agent服务 10050 端口
systemctl start zabbix-agent
#设置开机自启
systemctl enable zabbix-agent
#输出提示
echo -e "Now you can use \033[32mnetstat -tnlp\033[0m check \033[33mport:10050\033[0m"